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

Subversion Repositories yac

[/] [yac/] [trunk/] [c_octave/] [cordic_iterative.c] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feddischso
/***************************************************************************
2
*                                                                          *
3
*  File           : cordic_iterative.c                                     *
4
*  Project        : YAC (Yet Another CORDIC Core)                          *
5
*  Creation       : Feb. 2014                                              *
6
*  Limitations    :                                                        *
7
*  Platform       : Linux, Mac, Windows                                    *
8
*  Target         : Octave, Matlab, Standalone-Application                 *
9
*                                                                          *
10
*  Author(s):     : Christian Haettich                                     *
11
*  Email          : feddischson@opencores.org                              *
12
*                                                                          *
13
*                                                                          *
14
**                                                                        **
15
*                                                                          *
16
*  Description                                                             *
17
*     C-implementation of an interative cordic.                            *
18
*     General information about the CORDIC algorithm can be found          *
19
*     here: - http://en.wikipedia.org/wiki/CORDIC                          *
20
*           - http://en.wikibooks.org/wiki/Digital_Circuits/CORDIC         *
21
*                                                                          *
22
*                                                                          *
23
**                                                                        **
24
*                                                                          *
25
*  TODO                                                                    *
26
*        Some documentation and function description                       *
27
*                                                                          *
28
*                                                                          *
29
*                                                                          *
30
*                                                                          *
31
****************************************************************************
32
*                                                                          *
33
*                     Copyright Notice                                     *
34
*                                                                          *
35
*    This file is part of YAC - Yet Another CORDIC Core                    *
36
*    Copyright (c) 2014, Author(s), All rights reserved.                   *
37
*                                                                          *
38
*    YAC is free software; you can redistribute it and/or                  *
39
*    modify it under the terms of the GNU Lesser General Public            *
40
*    License as published by the Free Software Foundation; either          *
41
*    version 3.0 of the License, or (at your option) any later version.    *
42
*                                                                          *
43
*    YAC is distributed in the hope that it will be useful,                *
44
*    but WITHOUT ANY WARRANTY; without even the implied warranty of        *
45
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
46
*    Lesser General Public License for more details.                       *
47
*                                                                          *
48
*    You should have received a copy of the GNU Lesser General Public      *
49
*    License along with this library. If not, download it from             *
50
*    http://www.gnu.org/licenses/lgpl                                      *
51
*                                                                          *
52
***************************************************************************/
53
 
54
 
55
 
56
#include <stdio.h>
57
#include <stdlib.h>
58
#include <math.h>
59
#include "mex.h"
60
 
61
/* enable debug output */
62
#define PRINT_DEBUG        0
63
 
64
 
65
/* #define CORDIC_ROUNDING    0.5 */
66
#define CORDIC_ROUNDING    0.0
67
 
68
 
69
/* the supported modes */
70
#define C_FLAG_VEC_ROT     0x08
71
#define C_FLAG_ATAN_3      0x04
72
#define C_MODE_MSK         0x03
73
#define C_MODE_CIR         0x00
74
#define C_MODE_LIN         0x01
75
#define C_MODE_HYP         0x02
76
 
77
 
78
 
79
#define PRINT  mexPrintf
80
 
81
 
82
 
83
void cordic_int( long long int   x_i,
84
                 long long int   y_i,
85
                 long long int   a_i,
86
                 long long int * x_o,
87
                 long long int * y_o,
88
                 long long int * a_o,
89
                 int           * it_o,
90
                 int        mode,
91
                 int        XY_WIDTH,
92
                 int        A_WIDTH,
93
                 int        GUARD_BITS,
94
                 int        RM_GAIN );
95
int            cordic_int_dbg    ( long long int x,
96
                                   long long int y,
97
                                   long long int a,
98
                                   int           mode,
99
                                   int           it,
100
                                   char*         msg );
101
int            cordic_int_init   ( long long int *x,
102
                                   long long int *y,
103
                                   long long int *a,
104
                                   int           mode,
105
                                   int           A_WIDTH,
106
                                   int           XY_WIDTH );
107
void           cordic_int_rm_gain( long long int *x,
108
                                   long long int *y,
109
                                   int           mode,
110
                                   int           rm_gain );
111
int            cordic_int_rotate(  long long int * x,
112
                                   long long int * y,
113
                                   long long int * a,
114
                                   int             mode,
115
                                   int             A_WIDTH );
116
long long int  cordic_int_lut    ( int             mode,
117
                                   int             it,
118
                                   int             A_WIDTH );
119
 
120
 
121
 
122
 
123
 
124
 
125
void mexFunction(int nlhs, mxArray *plhs[],
126
                 int nrhs, const mxArray *prhs[])
127
{
128
   double *inx,*iny,*inz,*outx,*outy,*outz,*outi;
129
   double mode;
130
   double xy_width;
131
   double a_width;
132
   double guard_bits;
133
   double rm_gain;
134
 
135
   int mrowsx,ncolsx,mrowsy,ncolsy,mrowsz,ncolsz;
136
   int i;
137
   int it;
138
   if(nrhs!=8 )
139
      mexErrMsgTxt("8 input arguments required");
140
   if(nlhs!=4)
141
      mexErrMsgTxt("4 output arguments required");
142
 
143
   if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]))
144
      mexErrMsgTxt("Input x must be double and non-complex");
145
 
146
   if (!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]))
147
      mexErrMsgTxt("Input y must be double and non-complex");
148
 
149
   if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]))
150
      mexErrMsgTxt("Input a must be double and non-complex");
151
 
152
   mrowsx = mxGetM(prhs[0]);
153
   ncolsx = mxGetN(prhs[0]);
154
   mrowsy = mxGetM(prhs[1]);
155
   ncolsy = mxGetN(prhs[1]);
156
   mrowsz = mxGetM(prhs[2]);
157
   ncolsz = mxGetN(prhs[2]);
158
 
159
 
160
 
161
   if (mrowsx > 1 || mrowsy >1 || mrowsz > 1)
162
       mexErrMsgTxt("Input vector must have the size Nx1.");
163
 
164
   /* printf("%d %d %d\n", ncolsx, ncolsy, ncolsa); */
165
 
166
   if (ncolsx!=ncolsy || ncolsx!=ncolsz || ncolsy!=ncolsz)
167
       mexErrMsgTxt("Input vectors don't have the same length!");
168
 
169
 
170
   plhs[0] = mxCreateDoubleMatrix(mrowsx,ncolsx,mxREAL);
171
   plhs[1] = mxCreateDoubleMatrix(mrowsy,ncolsy,mxREAL);
172
   plhs[2] = mxCreateDoubleMatrix(mrowsz,ncolsz,mxREAL);
173
   plhs[3] = mxCreateDoubleMatrix(mrowsz,ncolsz,mxREAL);
174
 
175
   inx         = mxGetPr(prhs[0]);
176
   iny         = mxGetPr(prhs[1]);
177
   inz         = mxGetPr(prhs[2]);
178
   mode        = mxGetScalar(prhs[3]);
179
   xy_width    = mxGetScalar(prhs[4]);
180
   a_width     = mxGetScalar(prhs[5]);
181
   guard_bits  = mxGetScalar(prhs[6]);
182
   rm_gain     = mxGetScalar(prhs[7]);
183
 
184
   outx= mxGetPr(plhs[0]);
185
   outy= mxGetPr(plhs[1]);
186
   outz= mxGetPr(plhs[2]);
187
   outi= mxGetPr(plhs[3]);
188
 
189
   for( i = 0; i < ncolsx; i++ )
190
   {
191
        long long int inx_i = inx[ i ];
192
        long long int iny_i = iny[ i ];
193
        long long int inz_i = inz[ i ];
194
        long long int outx_i = 0;
195
        long long int outy_i = 0;
196
        long long int outz_i = 0;
197
/*        PRINT("x: %lld, y: %lld, a: %lld\n", inx_i, iny_i, inz_i ); */
198
 
199
        cordic_int(   inx_i,    iny_i,   inz_i,
200
                        &outx_i, &outy_i, &outz_i,
201
                         &it, mode,
202
                         xy_width, a_width, guard_bits, rm_gain );
203
        outx[i] = outx_i;
204
        outy[i] = outy_i;
205
        outz[i] = outz_i;
206
        outi[i] = it;
207
 
208
 
209
   }
210
}
211
 
212
 
213
 
214
 
215
 
216
 
217
void cordic_int( long long int   x_i,
218
                 long long int   y_i,
219
                 long long int   a_i,
220
                 long long int * x_o,
221
                 long long int * y_o,
222
                 long long int * a_o,
223
                 int           * it_o,
224
                 int        mode,
225
                 int        XY_WIDTH,
226
                 int        A_WIDTH,
227
                 int        GUARD_BITS,
228
                 int        RM_GAIN )
229
{
230
   long long int x;
231
   long long int y;
232
   long long int a;
233
   long long int s;
234
   int ov;
235
   int it = 0;
236
 
237
 
238
 
239
 
240
   /* total with, including guard bits */
241
   int XY_WIDTH_G = XY_WIDTH + GUARD_BITS;
242
 
243
   cordic_int_dbg( x_i, y_i, a_i, mode, 0, "input" );
244
 
245
   if( !cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH, XY_WIDTH ) )
246
   {
247
 
248
      it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
249
 
250
      cordic_int_rm_gain( &x_i, &y_i, mode, RM_GAIN );
251
   }
252
 
253
   *x_o  = x_i;
254
   *y_o  = y_i;
255
   *a_o  = a_i;
256
   *it_o = it;
257
 
258
}
259
 
260
 
261
 
262
 
263
 
264
 
265
 
266
int cordic_int_init( long long int *x,
267
                     long long int *y,
268
                     long long int *a,
269
                     int           mode,
270
                     int           A_WIDTH,
271
                     int           XY_WIDTH )
272
{
273
   int already_done = 0;
274
 
275
 
276
   long long int PI   = ( long long int )( M_PI * pow( 2, A_WIDTH-1 ) + 0.5 );
277
   long long int PI_H = (long long int)(  M_PI * pow( 2, A_WIDTH-2 ) + 0.5  );
278
 
279
   long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
280
 
281
   cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
282
 
283
 
284
   /* Circular rotation mode */
285
   if( 0          == ( mode &  C_FLAG_VEC_ROT )    &&
286
       C_MODE_CIR == ( mode &  C_MODE_MSK     )  )
287
   {
288
      /* move from third quadrant to first
289
         quadrant if necessary */
290
      if( *a <  - PI_H )
291
      {
292
          if( ! (mode & C_FLAG_ATAN_3) )
293
             *a += PI;
294
          *x  = -*x;
295
          *y  = -*y;
296
          #if PRINT_DEBUG > 0
297
          PRINT("move from third quadrand");
298
          #endif
299
      }
300
      /* move from second quadrant to fourth
301
         quadrant if necessary */
302
      else if( *a > PI_H )
303
      {
304
          if( ! (mode & C_FLAG_ATAN_3) )
305
             *a -= PI;
306
          *x  = -*x;
307
          *y  = -*y;
308
          #if PRINT_DEBUG > 0
309
          PRINT("move from second quadrand\n" );
310
          #endif
311
      }
312
   }
313
 
314
   /* circular vector mode */
315
   else if ( 0          != ( mode &  C_FLAG_VEC_ROT )    &&
316
             C_MODE_CIR == ( mode &  C_MODE_MSK     )  )
317
   {
318
 
319
      if( *x == 0 && *y == 0 )
320
      {
321
         already_done = 1;
322
         *a = 0;
323
         #if PRINT_DEBUG > 0
324
         PRINT( "Zero input, skipping rotations \n" );
325
         #endif
326
      }
327
      else if( *x == XY_MAX && *y == XY_MAX )
328
      {
329
         #if PRINT_DEBUG > 0
330
         PRINT( "All max, skipping rotations 1\n" );
331
         #endif
332
         *a = cordic_int_lut( mode, 0, A_WIDTH );
333
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
334
         already_done = 1;
335
      }
336
      else if( *x == -XY_MAX && *y == -XY_MAX )
337
      {
338
         #if PRINT_DEBUG > 0
339
         PRINT( "All max, skipping rotations 2\n" );
340
         #endif
341
         *a = cordic_int_lut( mode, 0, A_WIDTH ) - PI;
342
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
343
         already_done = 1;
344
      }
345
      else if( *x ==  XY_MAX && *y == -XY_MAX )
346
      {
347
         #if PRINT_DEBUG > 0
348
         PRINT( "All max, skipping rotations 3\n" );
349
         #endif
350
         *a = -cordic_int_lut( mode, 0, A_WIDTH );
351
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
352
         already_done = 1;
353
      }
354
      else if( *x == -XY_MAX && *y ==  XY_MAX )
355
      {
356
         #if PRINT_DEBUG > 0
357
         PRINT( "All max, skipping rotations 4\n" );
358
         #endif
359
         *a = PI - cordic_int_lut( mode, 0, A_WIDTH );
360
         *x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 );
361
         already_done = 1;
362
      }
363
 
364
 
365
 
366
      else if( *x == 0 && *y > 0 )
367
      {
368
         *a = PI_H;
369
         *x = *y;
370
         already_done = 1;
371
         #if PRINT_DEBUG > 0
372
         PRINT( "Fixed value of pi/2, skipping rotations" );
373
         #endif
374
         *y = 0;
375
      }
376
      else if( *x == 0 && *y < 0 )
377
      {
378
         *a = -PI_H;
379
         *x = -*y;
380
         *y = 0;
381
         already_done = 1;
382
         #if PRINT_DEBUG > 0
383
         PRINT( "Fixed value of -pi/2, skipping rotations" );
384
         #endif
385
      }
386
      else if( *x < 0  && *y >= 0 )
387
      {
388
         *x = -*x;
389
         *y = -*y;
390
         *a =  PI;
391
          #if PRINT_DEBUG > 0
392
          PRINT("pre-rotation from second to the fourth quadrant\n" );
393
          #endif
394
      }
395
      else if( *x < 0 && *y <  0 )
396
      {
397
         *x = -*x;
398
         *y = -*y;
399
         *a = -PI;
400
          #if PRINT_DEBUG > 0
401
          PRINT("pre-rotation from third to first quadrand\n" );
402
          #endif
403
      }
404
      else
405
         *a = 0;
406
   }
407
   /* linear vector mode */
408
   else if ( 0          != ( mode &  C_FLAG_VEC_ROT )    &&
409
             C_MODE_LIN == ( mode &  C_MODE_MSK     )  )
410
   {
411
      if( *x < 0 )
412
      {
413
         *x = -*x;
414
         *y = -*y;
415
      }
416
      *a = 0;
417
   }
418
 
419
   cordic_int_dbg( *x, *y, *a, mode, 0, "after init" );
420
   return already_done;
421
}
422
 
423
 
424
 
425
int cordic_int_dbg(  long long int x,
426
                     long long int y,
427
                     long long int a,
428
                     int           mode,
429
                     int           it,
430
                     char*         msg )
431
{
432
   #if PRINT_DEBUG > 0
433
   PRINT( "%20s: mode = %d, iteration %d, x = % 10.lld, y = %10.lld, a = %10.lld \n",
434
           msg,mode,it,x,y,a );
435
   #endif
436
}
437
 
438
int cordic_int_repeat( iteration, mode )
439
{
440
   int i = 4;
441
 
442
   if( C_MODE_HYP != ( mode & C_MODE_MSK ) )
443
      return 0;
444
 
445
 
446
   while( 1 )
447
   {
448
      if( i == iteration )
449
          return 1;
450
      else if( i > iteration )
451
          return 0;
452
      i = i * 3 + 1;
453
   }
454
}
455
 
456
 
457
 
458
 
459
int cordic_int_rotate( long long int * x,
460
                       long long int * y,
461
                       long long int * a,
462
                       int             mode,
463
                       int             A_WIDTH )
464
{
465
   int it = 0;
466
   long long int xsh, ysh;
467
   long long int ylst, alst;
468
   int sign;
469
   int repeat = 0;
470
 
471
   while( 1 )
472
   {
473
      /* get the sign */
474
      if( 0 == ( mode & C_FLAG_VEC_ROT ) )
475
          sign =  ( *a >= 0 );
476
      else
477
          sign = !( *y >= 0 );
478
 
479
      /* shift operation: hyperbolic case*/
480
      if( C_MODE_HYP == ( mode & C_MODE_MSK ) )
481
      {
482
         xsh = *x >> (it+1);
483
         ysh = *y >> (it+1);
484
      }
485
      /* shift operation: circular and linear case*/
486
      else
487
      {
488
         xsh = *x >> it;
489
         ysh = *y >> it;
490
      }
491
 
492
      if( sign == 1 )
493
      {
494
         *a -= cordic_int_lut( mode, it, A_WIDTH );
495
 
496
         if( C_MODE_CIR == ( mode & C_MODE_MSK ) )
497
         {
498
            *x = *x - ysh;
499
            *y = *y + xsh;
500
         }
501
         else
502
         if( C_MODE_LIN == ( mode & C_MODE_MSK ) )
503
         {
504
            *x = *x;
505
            *y = *y + xsh;
506
         }
507
         else
508
         {
509
            *x = *x + ysh;
510
            *y = *y + xsh;
511
         }
512
      }
513
      else
514
      {
515
         *a += cordic_int_lut( mode, it, A_WIDTH );
516
         if( C_MODE_CIR == ( mode & C_MODE_MSK ) )
517
         {
518
            *x = *x + ysh;
519
            *y = *y - xsh;
520
         }
521
         else
522
         if( C_MODE_LIN == ( mode & C_MODE_MSK ) )
523
         {
524
            *x = *x;
525
            *y = *y - xsh;
526
         }
527
         else
528
         {
529
            *x = *x - ysh;
530
            *y = *y - xsh;
531
         }
532
      }
533
      cordic_int_dbg( *x, *y, *a, mode, it, "after rotation" );
534
 
535
      /* abort condition */
536
      if( ( mode & C_FLAG_VEC_ROT  ) == 0 &&
537
          ( *a == 0 /* || *a == -1 */ ) )
538
          break;
539
      if( ( mode & C_FLAG_VEC_ROT  ) == 0 &&
540
          ( *a == alst ) )
541
          break;
542
 
543
      if( ( mode & C_FLAG_VEC_ROT  ) != 0 &&
544
          ( *y == 0 /*|| *y == -1 */ ) )
545
          break;
546
      if( ( mode & C_FLAG_VEC_ROT  ) != 0 &&
547
          ( *y == ylst ) )
548
          break;
549
 
550
      else if( it > 40 )
551
      {
552
         PRINT( "ERROR: abort %lld %lld %lld %lld - %d - %d!\n", *a, alst, *y, ylst, mode, *y == ylst );
553
         it = -1;
554
          break;
555
      }
556
 
557
 
558
      ylst = *y;
559
      alst = *a;
560
      if( repeat == 0 && cordic_int_repeat( it, mode ) )
561
      {
562
         repeat = 1;
563
         #if PRINT_DEBUG
564
         mexPrintf( "repeat it %d\n" , it );
565
         #endif
566
      }
567
      else
568
      {
569
         repeat = 0;
570
         it++;
571
      }
572
   }
573
   return it;
574
}
575
 
576
 
577
 
578
#define SCALE_VAL( _W_ )(  (double)( (long long int) 1 << (long long int)( _W_ -1 ) ) ) 
579
 
580
long long int cordic_int_lut( int mode, int it, int A_WIDTH )
581
{
582
   long long int lut_val;
583
   if( C_MODE_CIR == ( mode & C_MODE_MSK ) )
584
   {
585
      if( it <= 10 )
586
         lut_val = (long long int)(   atan(  pow( 2, -it ) ) * pow( 2, A_WIDTH-1 ) );
587
      else
588
         lut_val = pow( 2, A_WIDTH-1-it ); /* (long long int)( SCALE_VAL( A_WIDTH-it ) ); */
589
   }
590
   else
591
   if( C_MODE_LIN == ( mode & C_MODE_MSK ) )
592
   {
593
      lut_val =  (long long int)( 1.0 / (double)( ( long long int )1 << (long long int)it )
594
                                *  SCALE_VAL( A_WIDTH ) -1 );
595
   }
596
   else
597
   {
598
      lut_val = (long long int)( atanh( 1.0 / (double)( (long long int)1 << ( long long int )(it+1)  ) )
599
                                *  SCALE_VAL( A_WIDTH ) );
600
   }
601
   return lut_val;
602
}
603
 
604
 
605
 
606
 
607
/**
608
 *
609
 * Cordic gain:
610
 *
611
 *
612
 *
613
 */
614
void cordic_int_rm_gain( long long int *x,
615
                         long long int *y,
616
                         int mode,
617
                         int rm_gain )
618
{
619
   /* for the non-linear case: remove cordic gain if RM_GAIN > 0 */
620
   if( C_MODE_CIR == ( mode & C_MODE_MSK ) )
621
   {
622
 
623
 
624
      switch( rm_gain )
625
      {
626
         case 1: *x = + ( *x >> 1 ) ; break; /* error: 0.1072529350 */
627
         case 2: *x = + ( *x >> 1 ) - ( *x >> 4 ) ; break; /* error: 0.1697529350 */
628
         case 3: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 5 ) ; break; /* error: 0.0135029350 */
629
         case 4: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 8 ) ; break; /* error: 0.0017841850 */
630
         case 5: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 12 ) ; break; /* error: 0.0000752006 */
631
         case 6: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) ; break; /* error: 0.0000141655 */
632
         case 7: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) - ( *x >> 17 ) ; break; /* error: 0.0000217949 */
633
         case 8: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) + ( *x >> 16 ) - ( *x >> 19 ) ; break; /* error: 0.0000008140 */
634
         case 9: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) + ( *x >> 16 ) - ( *x >> 20 ) - ( *x >> 22 ) ; break; /* error: 0.0000000988 */
635
         case 10: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) + ( *x >> 16 ) - ( *x >> 20 ) - ( *x >> 23 ) - ( *x >> 25 ) ; break; /* error: 0.0000000094 */
636
         case 11: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) + ( *x >> 16 ) - ( *x >> 20 ) - ( *x >> 23 ) - ( *x >> 26 ) - ( *x >> 27 ) ; break; /* error: 0.0000000019 */
637
         case 12: *x = + ( *x >> 1 ) + ( *x >> 3 ) - ( *x >> 6 ) - ( *x >> 9 ) - ( *x >> 13 ) - ( *x >> 14 ) + ( *x >> 16 ) - ( *x >> 20 ) - ( *x >> 23 ) - ( *x >> 26 ) - ( *x >> 28 ) - ( *x >> 29 ) ; break; /* error: 0.0000000001 */
638
         default: *x = *x; break;
639
      }
640
      switch( rm_gain )
641
      {
642
         case 1: *y = + ( *y >> 1 ) ; break; /* error: 0.1072529350 */
643
         case 2: *y = + ( *y >> 1 ) - ( *y >> 4 ) ; break; /* error: 0.1697529350 */
644
         case 3: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 5 ) ; break; /* error: 0.0135029350 */
645
         case 4: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 8 ) ; break; /* error: 0.0017841850 */
646
         case 5: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 12 ) ; break; /* error: 0.0000752006 */
647
         case 6: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) ; break; /* error: 0.0000141655 */
648
         case 7: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) - ( *y >> 17 ) ; break; /* error: 0.0000217949 */
649
         case 8: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) + ( *y >> 16 ) - ( *y >> 19 ) ; break; /* error: 0.0000008140 */
650
         case 9: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) + ( *y >> 16 ) - ( *y >> 20 ) - ( *y >> 22 ) ; break; /* error: 0.0000000988 */
651
         case 10: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) + ( *y >> 16 ) - ( *y >> 20 ) - ( *y >> 23 ) - ( *y >> 25 ) ; break; /* error: 0.0000000094 */
652
         case 11: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) + ( *y >> 16 ) - ( *y >> 20 ) - ( *y >> 23 ) - ( *y >> 26 ) - ( *y >> 27 ) ; break; /* error: 0.0000000019 */
653
         case 12: *y = + ( *y >> 1 ) + ( *y >> 3 ) - ( *y >> 6 ) - ( *y >> 9 ) - ( *y >> 13 ) - ( *y >> 14 ) + ( *y >> 16 ) - ( *y >> 20 ) - ( *y >> 23 ) - ( *y >> 26 ) - ( *y >> 28 ) - ( *y >> 29 ) ; break; /* error: 0.0000000001 */
654
         default: *x = *y; break;
655
      }
656
 
657
   }
658
   else
659
   if( C_MODE_HYP == ( mode & C_MODE_MSK ) )
660
   {
661
      switch( rm_gain )
662
      {
663
         case 1: *x = *x - ( *x >> 3 ) ; break; /* error: 0.3324970678 */
664
         case 2: *x = *x + ( *x >> 2 ) - ( *x >> 4 ) ; break; /* error: 0.0199970678 */
665
         case 3: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 6 ) ; break; /* error: 0.0043720678 */
666
         case 4: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) ; break; /* error: 0.0004658178 */
667
         case 5: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) - ( *x >> 12 ) ; break; /* error: 0.0007099584 */
668
         case 6: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 15 ) ; break; /* error: 0.0000080541 */
669
         case 7: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 16 ) - ( *x >> 17 ) ; break; /* error: 0.0000004247 */
670
         case 8: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 16 ) - ( *x >> 17 ) - ( *x >> 22 ) ; break; /* error: 0.0000006631 */
671
         case 9: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 16 ) - ( *x >> 17 ) + ( *x >> 21 ) - ( *x >> 24 ) ; break; /* error: 0.0000000075 */
672
         case 10: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 16 ) - ( *x >> 17 ) + ( *x >> 21 ) - ( *x >> 24 ) + ( *x >> 27 ) ; break; /* error: 0.0000000000 */
673
         case 11: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 16 ) - ( *x >> 17 ) + ( *x >> 21 ) - ( *x >> 24 ) + ( *x >> 27 ) - ( *x >> 37 ) ; break; /* error: 0.0000000000 */
674
         case 12: *x = *x + ( *x >> 2 ) - ( *x >> 5 ) - ( *x >> 7 ) - ( *x >> 8 ) + ( *x >> 11 ) - ( *x >> 16 ) - ( *x >> 17 ) + ( *x >> 21 ) - ( *x >> 24 ) + ( *x >> 27 ) + ( *x >> 36 ) - ( *x >> 39 ) ; break; /* error: 0.0000000000 */
675
      }
676
      switch( rm_gain )
677
      {
678
         case 1: *y = *y - ( *y >> 3 ) ; break; /* error: 0.3324970678 */
679
         case 2: *y = *y + ( *y >> 2 ) - ( *y >> 4 ) ; break; /* error: 0.0199970678 */
680
         case 3: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 6 ) ; break; /* error: 0.0043720678 */
681
         case 4: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) ; break; /* error: 0.0004658178 */
682
         case 5: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) - ( *y >> 12 ) ; break; /* error: 0.0007099584 */
683
         case 6: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 15 ) ; break; /* error: 0.0000080541 */
684
         case 7: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 16 ) - ( *y >> 17 ) ; break; /* error: 0.0000004247 */
685
         case 8: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 16 ) - ( *y >> 17 ) - ( *y >> 22 ) ; break; /* error: 0.0000006631 */
686
         case 9: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 16 ) - ( *y >> 17 ) + ( *y >> 21 ) - ( *y >> 24 ) ; break; /* error: 0.0000000075 */
687
         case 10: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 16 ) - ( *y >> 17 ) + ( *y >> 21 ) - ( *y >> 24 ) + ( *y >> 27 ) ; break; /* error: 0.0000000000 */
688
         case 11: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 16 ) - ( *y >> 17 ) + ( *y >> 21 ) - ( *y >> 24 ) + ( *y >> 27 ) - ( *y >> 37 ) ; break; /* error: 0.0000000000 */
689
         case 12: *y = *y + ( *y >> 2 ) - ( *y >> 5 ) - ( *y >> 7 ) - ( *y >> 8 ) + ( *y >> 11 ) - ( *y >> 16 ) - ( *y >> 17 ) + ( *y >> 21 ) - ( *y >> 24 ) + ( *y >> 27 ) + ( *y >> 36 ) - ( *y >> 39 ) ; break; /* error: 0.0000000000 */
690
      }
691
   }
692
}
693
 

powered by: WebSVN 2.1.0

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