OpenCores
URL https://opencores.org/ocsvn/yac/yac/trunk

Subversion Repositories yac

[/] [yac/] [trunk/] [c_octave/] [cordic_iterative.c] - Diff between revs 4 and 7

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 4 Rev 7
Line 54... Line 54...
 
 
 
 
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <math.h>
#include <math.h>
 
 
 
#ifndef OR32_TARGET
#include "mex.h"
#include "mex.h"
 
#endif 
 
 
/* enable debug output */
/* enable debug output */
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
#define PRINT_DEBUG        0
#define PRINT_DEBUG        0
Line 67... Line 70...
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
#define PRINT_DEBUG        0
#define PRINT_DEBUG        0
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
 
 
/* #define CORDIC_ROUNDING    0.5 */
/* #define CORDIC_ROUNDING    0.5 */
#define CORDIC_ROUNDING    0.0
#define CORDIC_ROUNDING    0.0
 
 
 
 
/* the supported modes */
/* the supported modes */
Line 81... Line 83...
#define C_MODE_CIR         0x00
#define C_MODE_CIR         0x00
#define C_MODE_LIN         0x01
#define C_MODE_LIN         0x01
#define C_MODE_HYP         0x02
#define C_MODE_HYP         0x02
 
 
 
 
 
#ifndef OR32_TARGET
#define PRINT  mexPrintf
#define PRINT  mexPrintf
 
#endif
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
Line 155... Line 157...
                                   int             it,
                                   int             it,
                                   int             A_WIDTH );
                                   int             A_WIDTH );
 
 
 
 
 
 
 
#ifndef OR32_TARGET
 
 
 
 
void mexFunction(int nlhs, mxArray *plhs[],
void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
                 int nrhs, const mxArray *prhs[])
{
{
Line 245... Line 247...
 
 
 
 
   }
   }
}
}
 
 
 
#endif
 
 
 
 
 
 
 
 
void cordic_int( long long int   x_i,
void cordic_int( long long int   x_i,
Line 349... Line 351...
 
 
   long long int PI   = ( long long int )( M_PI * pow( 2, A_WIDTH-1 ) + 0.5 );
   long long int PI   = ( long long int )( M_PI * pow( 2, A_WIDTH-1 ) + 0.5 );
   long long int PI_H = (long long int)(  M_PI * pow( 2, A_WIDTH-2 ) + 0.5  );
   long long int PI_H = (long long int)(  M_PI * pow( 2, A_WIDTH-2 ) + 0.5  );
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
 
 
   long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
   long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
 
 
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
 
 
Line 362... Line 365...
 
 
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
 
 
 
=======
 
 
 
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
   long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
   long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
 
 
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
 
 
 
 
 
<<<<<<< HEAD
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
=======
 
   if( 0 != ( mode &  C_FLAG_VEC_ROT ) && *y == 0 )
 
   {
 
       already_done = 1;
 
       *a = 0;
 
       #if PRINT_DEBUG > 0
 
       PRINT( "Zero input, skipping rotations \n" );
 
       #endif
 
   }
 
   else if( 0 == ( mode &  C_FLAG_VEC_ROT )  && *a == 0 )
 
   {
 
       #if PRINT_DEBUG > 0
 
       PRINT("zero angular input\n" );
 
       #endif
 
       already_done = 1;
 
   }
 
 
 
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
   /* Circular rotation mode */
   /* Circular rotation mode */
   if( 0          == ( mode &  C_FLAG_VEC_ROT )    &&
   else if( 0          == ( mode &  C_FLAG_VEC_ROT )    &&
       C_MODE_CIR == ( mode &  C_MODE_MSK     )  )
       C_MODE_CIR == ( mode &  C_MODE_MSK     )  )
   {
   {
 
 
 
 
      /* move from third quadrant to first
      /* move from third quadrant to first
         quadrant if necessary */
         quadrant if necessary */
      if( *a <  - PI_H )
      if( *a <  - PI_H )
      {
      {
          if( ! (mode & C_FLAG_ATAN_3) )
          if( ! (mode & C_FLAG_ATAN_3) )
Line 407... Line 434...
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
      if( *x == 0 && *y == 0 )
      if( *x == XY_MAX && *y == XY_MAX )
      {
 
         already_done = 1;
 
         *a = 0;
 
         #if PRINT_DEBUG > 0
 
         PRINT( "Zero input, skipping rotations \n" );
 
         #endif
 
      }
 
      else if( *x == XY_MAX && *y == XY_MAX )
 
      {
      {
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "All max, skipping rotations 1\n" );
         PRINT( "All max, skipping rotations 1\n" );
         #endif
         #endif
 
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5;
 
         *y = 0;
         *a = cordic_int_lut( mode, 0, A_WIDTH );
         *a = cordic_int_lut( mode, 0, A_WIDTH );
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
 
         already_done = 1;
         already_done = 1;
      }
      }
      else if( *x == -XY_MAX && *y == -XY_MAX )
      else if( *x == -XY_MAX && *y == -XY_MAX )
      {
      {
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "All max, skipping rotations 2\n" );
         PRINT( "All max, skipping rotations 2\n" );
         #endif
         #endif
 
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5;
 
         *y = 0;
         *a = cordic_int_lut( mode, 0, A_WIDTH ) - PI;
         *a = cordic_int_lut( mode, 0, A_WIDTH ) - PI;
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
 
         already_done = 1;
         already_done = 1;
      }
      }
      else if( *x ==  XY_MAX && *y == -XY_MAX )
      else if( *x ==  XY_MAX && *y == -XY_MAX )
      {
      {
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "All max, skipping rotations 3\n" );
         PRINT( "All max, skipping rotations 3\n" );
         #endif
         #endif
 
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5;
 
         *y = 0;
         *a = -cordic_int_lut( mode, 0, A_WIDTH );
         *a = -cordic_int_lut( mode, 0, A_WIDTH );
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
 
         already_done = 1;
         already_done = 1;
      }
      }
      else if( *x == -XY_MAX && *y ==  XY_MAX )
      else if( *x == -XY_MAX && *y ==  XY_MAX )
      {
      {
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "All max, skipping rotations 4\n" );
         PRINT( "All max, skipping rotations 4\n" );
         #endif
         #endif
 
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5;
 
         *y = 0;
         *a = PI - cordic_int_lut( mode, 0, A_WIDTH );
         *a = PI - cordic_int_lut( mode, 0, A_WIDTH );
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
 
         already_done = 1;
         already_done = 1;
      }
      }
 
 
 
 
 
 
Line 460... Line 483...
      {
      {
         *a = PI_H;
         *a = PI_H;
         *x = *y;
         *x = *y;
         already_done = 1;
         already_done = 1;
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "Fixed value of pi/2, skipping rotations" );
         PRINT( "Fixed value of pi/2, skipping rotations\n" );
         #endif
         #endif
         *y = 0;
         *y = 0;
      }
      }
      else if( *x == 0 && *y < 0 )
      else if( *x == 0 && *y < 0 )
      {
      {
         *a = -PI_H;
         *a = -PI_H;
         *x = -*y;
         *x = -*y;
         *y = 0;
         *y = 0;
         already_done = 1;
         already_done = 1;
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "Fixed value of -pi/2, skipping rotations" );
         PRINT( "Fixed value of -pi/2, skipping rotations\n" );
         #endif
         #endif
      }
      }
      else if( *x < 0  && *y >= 0 )
      else if( *x < 0  && *y >= 0 )
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
Line 543... Line 566...
         *x = -*x;
         *x = -*x;
         *y = -*y;
         *y = -*y;
      }
      }
      *a = 0;
      *a = 0;
   }
   }
 
 
   cordic_int_dbg( *x, *y, *a, mode, 0, "after init" );
   cordic_int_dbg( *x, *y, *a, mode, 0, "after init" );
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
   return already_done;
   return already_done;
=======
=======
Line 701... Line 723...
          ( *y == ylst ) )
          ( *y == ylst ) )
          break;
          break;
 
 
      else if( it > 40 )
      else if( it > 40 )
      {
      {
 
#if PRINT_DEBUG
         PRINT( "ERROR: abort %lld %lld %lld %lld - %d - %d!\n", *a, alst, *y, ylst, mode, *y == ylst );
         PRINT( "ERROR: abort %lld %lld %lld %lld - %d - %d!\n", *a, alst, *y, ylst, mode, *y == ylst );
 
#endif
         it = -1;
         it = -1;
          break;
          break;
      }
      }
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.