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

Subversion Repositories yac

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

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

Rev 3 Rev 4
Line 58... Line 58...
#include <math.h>
#include <math.h>
#include "mex.h"
#include "mex.h"
 
 
/* enable debug output */
/* enable debug output */
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
#define PRINT_DEBUG        0
#define PRINT_DEBUG        0
=======
=======
#define PRINT_DEBUG  0
#define PRINT_DEBUG  0
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
#define PRINT_DEBUG        0
 
>>>>>>> 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
 
 
Line 83... Line 87...
#define PRINT  mexPrintf
#define PRINT  mexPrintf
 
 
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
=======
=======
 
 
long long int ov_check( long long int * value, long long int length )
long long int ov_check( long long int * value, long long int length )
{
{
   long long int mask = (1<<length)-1;
   long long int mask = (1<<length)-1;
Line 100... Line 105...
}
}
 
 
 
 
 
 
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
>>>>>>> Updated C and RTL model as well as the documentation
void cordic_int( long long int   x_i,
void cordic_int( long long int   x_i,
                 long long int   y_i,
                 long long int   y_i,
                 long long int   a_i,
                 long long int   a_i,
                 long long int * x_o,
                 long long int * x_o,
                 long long int * y_o,
                 long long int * y_o,
Line 123... Line 130...
int            cordic_int_init   ( long long int *x,
int            cordic_int_init   ( long long int *x,
                                   long long int *y,
                                   long long int *y,
                                   long long int *a,
                                   long long int *a,
                                   int           mode,
                                   int           mode,
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
                                   int           A_WIDTH,
                                   int           A_WIDTH,
                                   int           XY_WIDTH );
                                   int           XY_WIDTH );
=======
=======
                                   int           A_WIDTH );
                                   int           A_WIDTH );
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
                                   int           A_WIDTH,
 
                                   int           XY_WIDTH );
 
>>>>>>> Updated C and RTL model as well as the documentation
void           cordic_int_rm_gain( long long int *x,
void           cordic_int_rm_gain( long long int *x,
                                   long long int *y,
                                   long long int *y,
                                   int           mode,
                                   int           mode,
                                   int           rm_gain );
                                   int           rm_gain );
int            cordic_int_rotate(  long long int * x,
int            cordic_int_rotate(  long long int * x,
Line 257... Line 269...
   long long int y;
   long long int y;
   long long int a;
   long long int a;
   long long int s;
   long long int s;
   int ov;
   int ov;
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
   int it = 0;
   int it = 0;
=======
=======
   int it;
   int it;
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
   int it = 0;
 
>>>>>>> Updated C and RTL model as well as the documentation
 
 
 
 
 
 
 
 
   /* total with, including guard bits */
   /* total with, including guard bits */
   int XY_WIDTH_G = XY_WIDTH + GUARD_BITS;
   int XY_WIDTH_G = XY_WIDTH + GUARD_BITS;
 
 
   cordic_int_dbg( x_i, y_i, a_i, mode, 0, "input" );
   cordic_int_dbg( x_i, y_i, a_i, mode, 0, "input" );
 
 
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
   if( !cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH, XY_WIDTH ) )
   if( !cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH, XY_WIDTH ) )
   {
   {
 
 
      it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
      it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
 
 
Line 282... Line 299...
   }
   }
=======
=======
   cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH );
   cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH );
 
 
   it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
   it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
 
=======
 
   if( !cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH, XY_WIDTH ) )
 
   {
 
>>>>>>> Updated C and RTL model as well as the documentation
 
 
   cordic_int_rm_gain( &x_i, &y_i, mode, RM_GAIN );
      it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
 
 
 
<<<<<<< HEAD
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
      cordic_int_rm_gain( &x_i, &y_i, mode, RM_GAIN );
 
   }
 
>>>>>>> Updated C and RTL model as well as the documentation
 
 
   *x_o  = x_i;
   *x_o  = x_i;
   *y_o  = y_i;
   *y_o  = y_i;
   *a_o  = a_i;
   *a_o  = a_i;
   *it_o = it;
   *it_o = it;
Line 305... Line 331...
int cordic_int_init( long long int *x,
int cordic_int_init( long long int *x,
                     long long int *y,
                     long long int *y,
                     long long int *a,
                     long long int *a,
                     int           mode,
                     int           mode,
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
                     int           A_WIDTH,
                     int           A_WIDTH,
                     int           XY_WIDTH )
                     int           XY_WIDTH )
=======
=======
                     int           A_WIDTH )
                     int           A_WIDTH )
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
                     int           A_WIDTH,
 
                     int           XY_WIDTH )
 
>>>>>>> Updated C and RTL model as well as the documentation
{
{
   int already_done = 0;
   int already_done = 0;
 
 
 
 
   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
 
 
   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 328... Line 360...
=======
=======
 
 
 
 
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
 
 
   long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
 
 
 
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
 
 
 
 
 
>>>>>>> Updated C and RTL model as well as the documentation
   /* Circular rotation mode */
   /* Circular rotation mode */
   if( 0          == ( mode &  C_FLAG_VEC_ROT )    &&
   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
Line 363... Line 403...
   /* circular vector mode */
   /* circular vector mode */
   else 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     )  )
   {
   {
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
 
=======
 
>>>>>>> Updated C and RTL model as well as the documentation
 
 
      if( *x == 0 && *y == 0 )
      if( *x == 0 && *y == 0 )
      {
      {
         already_done = 1;
         already_done = 1;
         *a = 0;
         *a = 0;
Line 432... Line 475...
         #if PRINT_DEBUG > 0
         #if PRINT_DEBUG > 0
         PRINT( "Fixed value of -pi/2, skipping rotations" );
         PRINT( "Fixed value of -pi/2, skipping rotations" );
         #endif
         #endif
      }
      }
      else if( *x < 0  && *y >= 0 )
      else if( *x < 0  && *y >= 0 )
 
<<<<<<< HEAD
=======
=======
      if( *x < 0 && *y > 0 )
      if( *x < 0 && *y > 0 )
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
>>>>>>> Updated C and RTL model as well as the documentation
      {
      {
         *x = -*x;
         *x = -*x;
         *y = -*y;
         *y = -*y;
         *a =  PI;
         *a =  PI;
          #if PRINT_DEBUG > 0
          #if PRINT_DEBUG > 0
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
          PRINT("pre-rotation from second to the fourth quadrant\n" );
          PRINT("pre-rotation from second to the fourth quadrant\n" );
          #endif
          #endif
      }
      }
      else if( *x < 0 && *y <  0 )
      else if( *x < 0 && *y <  0 )
=======
=======
          PRINT("align from second quadrand\n" );
          PRINT("align from second quadrand\n" );
          #endif
          #endif
      }
      }
      else if( *x < 0 && *y < 0 )
      else if( *x < 0 && *y < 0 )
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
          PRINT("pre-rotation from second to the fourth quadrant\n" );
 
          #endif
 
      }
 
      else if( *x < 0 && *y <  0 )
 
>>>>>>> Updated C and RTL model as well as the documentation
      {
      {
         *x = -*x;
         *x = -*x;
         *y = -*y;
         *y = -*y;
         *a = -PI;
         *a = -PI;
          #if PRINT_DEBUG > 0
          #if PRINT_DEBUG > 0
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
          PRINT("pre-rotation from third to first quadrand\n" );
          PRINT("pre-rotation from third to first quadrand\n" );
          #endif
          #endif
      }
      }
=======
=======
          PRINT("align from third quadrand\n" );
          PRINT("align from third quadrand\n" );
Line 470... Line 524...
      {
      {
         *a           = PI;
         *a           = PI;
         already_done = 1;
         already_done = 1;
      }
      }
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
          PRINT("pre-rotation from third to first quadrand\n" );
 
          #endif
 
      }
 
>>>>>>> Updated C and RTL model as well as the documentation
      else
      else
         *a = 0;
         *a = 0;
   }
   }
   /* linear vector mode */
   /* linear vector mode */
   else if ( 0          != ( mode &  C_FLAG_VEC_ROT )    &&
   else if ( 0          != ( mode &  C_FLAG_VEC_ROT )    &&
Line 487... Line 546...
      *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
   return already_done;
   return already_done;
=======
=======
 
 
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
   return already_done;
 
>>>>>>> Updated C and RTL model as well as the documentation
}
}
 
 
 
 
 
 
int cordic_int_dbg(  long long int x,
int cordic_int_dbg(  long long int x,
Line 608... Line 671...
      cordic_int_dbg( *x, *y, *a, mode, it, "after rotation" );
      cordic_int_dbg( *x, *y, *a, mode, it, "after rotation" );
 
 
      /* abort condition */
      /* abort condition */
      if( ( mode & C_FLAG_VEC_ROT  ) == 0 &&
      if( ( mode & C_FLAG_VEC_ROT  ) == 0 &&
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
          ( *a == 0 /* || *a == -1 */ ) )
          ( *a == 0 /* || *a == -1 */ ) )
=======
=======
          ( *a == 0 || *a == -1 ) )
          ( *a == 0 || *a == -1 ) )
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
          ( *a == 0 /* || *a == -1 */ ) )
 
>>>>>>> Updated C and RTL model as well as the documentation
          break;
          break;
      if( ( mode & C_FLAG_VEC_ROT  ) == 0 &&
      if( ( mode & C_FLAG_VEC_ROT  ) == 0 &&
          ( *a == alst ) )
          ( *a == alst ) )
          break;
          break;
 
 
      if( ( mode & C_FLAG_VEC_ROT  ) != 0 &&
      if( ( mode & C_FLAG_VEC_ROT  ) != 0 &&
<<<<<<< HEAD
<<<<<<< HEAD
 
<<<<<<< HEAD
          ( *y == 0 /*|| *y == -1 */ ) )
          ( *y == 0 /*|| *y == -1 */ ) )
=======
=======
          ( *y == 0 || *y == -1 ) )
          ( *y == 0 || *y == -1 ) )
>>>>>>> initial commit
>>>>>>> initial commit
 
=======
 
          ( *y == 0 /*|| *y == -1 */ ) )
 
>>>>>>> Updated C and RTL model as well as the documentation
          break;
          break;
      if( ( mode & C_FLAG_VEC_ROT  ) != 0 &&
      if( ( mode & C_FLAG_VEC_ROT  ) != 0 &&
          ( *y == ylst ) )
          ( *y == ylst ) )
          break;
          break;
 
 

powered by: WebSVN 2.1.0

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