URL
https://opencores.org/ocsvn/yac/yac/trunk
Subversion Repositories yac
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 6 to Rev 7
- ↔ Reverse comparison
Rev 6 → Rev 7
/yac/trunk/rtl/vhdl/cordic_iterative_tb.vhd
80,10 → 80,10
signal rst : std_logic; |
signal nrst : std_logic; |
|
constant XY_WIDTH : natural := 25; |
constant A_WIDTH : natural := 25; |
constant GUARD_BITS : natural := 2; |
constant RM_GAIN : natural := 5; |
constant XY_WIDTH : natural := 8; |
constant A_WIDTH : natural := 8; |
constant GUARD_BITS : natural := 2; |
constant RM_GAIN : natural := 3; |
component cordic_iterative_int is |
generic( |
XY_WIDTH : natural := 12; |
117,7 → 117,6
signal a_o : std_logic_vector( A_WIDTH+2-1 downto 0 ); |
|
|
|
begin |
|
|
139,10 → 138,10
rst <= '0'; |
wait; |
end process; |
|
|
|
|
|
dut : cordic_iterative_int |
generic map ( |
XY_WIDTH => XY_WIDTH , |
188,7 → 187,7
variable err_cnt : integer := 0; |
variable stim_cnt : integer := 0; |
begin |
|
|
err_cnt := 0; |
|
-- |
217,7 → 216,6
|
while ( not endfile( test_pattern_file ) )loop |
|
|
wait until en='1'; |
wait for clk_T; |
|
254,14 → 252,15
<<<<<<< HEAD |
<<<<<<< HEAD |
integer'image( stim_cnt ) & ": Serial Cordic Failed: expected x result:" |
& integer'image( tmp_value(5) ) & ", but got:" |
& integer'image( to_integer( signed( x_ex ) ) ); |
& integer'image( tmp_value(3) ) & ", but got:" |
& integer'image( to_integer( signed( x_o ) ) ); |
assert y_ex = y_o report |
integer'image( stim_cnt ) & ": Serial Cordic Failed: expected y result:" |
& integer'image( tmp_value(6) ) & ", but got:" |
& integer'image( to_integer( signed( y_ex ) ) ); |
& integer'image( tmp_value(4) ) & ", but got:" |
& integer'image( to_integer( signed( y_o ) ) ); |
assert a_ex = a_o report |
integer'image( stim_cnt ) & ": Serial Cordic Failed: expected a result:" |
<<<<<<< HEAD |
======= |
" Serial Cordic Failed: expected x result:" |
======= |
282,11 → 281,15
>>>>>>> Updated C and RTL model as well as the documentation |
& integer'image( tmp_value(7) ) & ", but got:" |
& integer'image( to_integer( signed( a_ex ) ) ); |
======= |
& integer'image( tmp_value(5) ) & ", but got:" |
& integer'image( to_integer( signed( a_o ) ) ); |
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper |
err_cnt := err_cnt + 1; |
writeline( error_pattern_file, input_line_bak ); |
|
end if; |
|
|
wait for CLK_T * 5; |
|
end loop; |
303,7 → 306,7
wait for clk_T * 10; |
en <= '1'; |
wait for clk_T * 1000; |
|
|
end process; |
|
|
/yac/trunk/rtl/vhdl/cordic_iterative_wb.vhd
299,7 → 299,7
b3_trans <= WB_NO_BURST; |
ack_r <= '0'; |
else |
|
|
cti_r <= cti_i; |
bte_r <= bte_i; |
|
318,7 → 318,7
|
-- start of burst |
b3_trans <= WB_BURST; |
|
|
elsif burst_end = '1' then |
|
-- end of burst |
325,7 → 325,7
b3_trans <= WB_NO_BURST; |
|
elsif b3_trans = WB_BURST then |
|
|
-- during burst |
|
end if; |
386,7 → 386,7
wr_p : process( clk_i, rst_i ) |
variable MEM_START : integer; |
begin |
|
|
if clk_i'event and clk_i='1' then |
if rst_i = '1' then |
MEM <= ( others => ( others => '0' ) ); |
437,20 → 437,20
state.st <= ST_WAIT; |
end if; |
|
|
|
-- single cordic calculation is done: |
-- save the result and start the next one or |
-- go back to idle |
if state.st = ST_WAIT and cordic_done = '1' then |
MEM_START := to_integer( state.cnt & "00" ); -- state.cnt * 4 |
MEM( MEM_START+0 ) <= ( others => '0' ); |
MEM( MEM_START+1 ) <= ( others => '0' ); |
MEM( MEM_START+2 ) <= ( others => '0' ); |
MEM( MEM_START+0 ) <= ( others => cordic_x_o( cordic_x_o'high )); |
MEM( MEM_START+1 ) <= ( others => cordic_y_o( cordic_y_o'high ) ); |
MEM( MEM_START+2 ) <= ( others => cordic_a_o( cordic_a_o'high ) ); |
MEM( MEM_START+0 )( cordic_x_o'range ) <= cordic_x_o; |
MEM( MEM_START+1 )( cordic_y_o'range ) <= cordic_y_o; |
MEM( MEM_START+2 )( cordic_a_o'range ) <= cordic_a_o; |
|
|
|
if state.cnt = 0 then |
|
-- go back to IDLE |
465,7 → 465,7
state.st <= ST_START; |
state.cnt <= state.cnt-1; |
end if; |
|
|
end if; |
|
end if; |
/yac/trunk/rtl/vhdl/cordic_iterative_int.vhd
84,7 → 84,7
|
|
architecture BEHAVIORAL of cordic_iterative_int is |
|
|
-- log2( max-iteration ) |
constant L2_MAX_I : natural := 8; |
|
94,15 → 94,19
constant A_WIDTH_I : natural := A_WIDTH+2; |
<<<<<<< HEAD |
<<<<<<< HEAD |
<<<<<<< HEAD |
======= |
>>>>>>> Updated C and RTL model as well as the documentation |
|
======= |
|
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper |
|
constant SQRT2_REAL : real := 1.4142135623730951454746218587388284504413604; |
constant PI_REAL : real := 3.1415926535897931159979634685441851615905762; |
constant PI : integer := natural( PI_REAL * real( 2**( A_WIDTH-1 ) ) + 0.5 ); |
constant PI_H : integer := natural( PI_REAL * real( 2**( A_WIDTH-2 ) ) + 0.5 ); |
constant SQRT2 : integer := natural( SQRT2_REAL * real( 2**( XY_WIDTH-1 ) ) + 0.5 ); |
constant PI : integer := natural( round( PI_REAL * real( 2**( A_WIDTH-1 ) ) ) ); |
constant PI_H : integer := natural( round( PI_REAL * real( 2**( A_WIDTH-2 ) ) ) ); |
constant SQRT2 : integer := natural( round( SQRT2_REAL * real( 2**( XY_WIDTH-1 ) ) ) ); |
constant XY_MAX : integer := natural( 2**( XY_WIDTH-1)-1); |
|
<<<<<<< HEAD |
135,12 → 139,12
alst : signed( A_WIDTH_I -1 downto 0 ); |
i : signed( L2_MAX_I -1 downto 0 ); |
do_shift : std_logic; |
done : std_logic; |
repeate : std_logic; |
end record state_t; |
signal state : state_t; |
|
|
|
--------------------------------------- |
-- Auto-generated function |
-- by matlab (see c_octave/cordic_iterative_code.m) |
222,13 → 226,12
alst => ( others => '0' ), |
mode => ( others => '0' ), |
i => ( others => '0' ), |
done => '0', |
do_shift => '0', |
repeate => '0' |
); |
|
|
elsif en = '1' then |
|
|
if state.st = ST_IDLE and start = '1' then |
state.st <= ST_INIT; |
state.mode <= mode_i; |
236,6 → 239,7
state.y <= resize( signed( y_i ), state.y'length ); |
state.a <= resize( signed( a_i ), state.a'length ); |
state.i <= ( others => '0' ); |
<<<<<<< HEAD |
|
<<<<<<< HEAD |
<<<<<<< HEAD |
255,6 → 259,10
elsif state.st = ST_INIT then |
>>>>>>> initial commit |
======= |
======= |
state.alst <= ( others => '0' ); |
state.ylst <= ( others => '0' ); |
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper |
elsif state.st = ST_INIT then |
-- |
-- initialization state |
269,6 → 277,7
|
<<<<<<< HEAD |
<<<<<<< HEAD |
<<<<<<< HEAD |
if state.mode( 1 downto 0 ) = VAL_MODE_HYP then |
-- if we do a hyperbolic rotation, we start with 1 |
======= |
288,6 → 297,29
<<<<<<< HEAD |
<<<<<<< HEAD |
if state.mode( I_FLAG_VEC_ROT ) = '0' |
======= |
if state.mode( 1 downto 0 ) = VAL_MODE_HYP then |
-- if we do a hyperbolic rotation, we start with 1 |
state.i(0) <= '1'; |
end if; |
|
|
|
if state.mode( I_FLAG_VEC_ROT ) = '1' and state.y = 0 then |
-- zero-input |
state.x_sum <= state.x; |
state.y_sum <= state.y; |
state.a <= ( others => '0' ); |
state.st <= ST_DONE; |
|
elsif state.mode( I_FLAG_VEC_ROT ) = '0' and state.a = 0 then |
-- nothing to do, a is zero |
state.x_sum <= state.x; |
state.y_sum <= state.y; |
state.st <= ST_DONE; |
|
elsif state.mode( I_FLAG_VEC_ROT ) = '0' |
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper |
and state.mode( 1 downto 0 ) = VAL_MODE_CIR then |
-- circular vector mode |
|
403,49 → 435,50
and state.mode( 1 downto 0 ) = VAL_MODE_CIR then |
-- circular rotation mode |
|
if state.x = 0 and state.y = 0 then |
if state.y = 0 then |
-- zero-input |
state.a <= ( others => '0' ); |
state.y <= ( others => '0' ); |
state.st <= ST_DONE; |
state.x_sum <= state.x; |
state.y_sum <= state.y; |
state.a <= ( others => '0' ); |
state.st <= ST_DONE; |
|
elsif state.x = XY_MAX and state.y = XY_MAX then |
-- all-max 1 |
state.a <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ); |
state.x <= to_signed( SQRT2, state.x'length ); |
state.y <= (others => '0' ); |
state.st <= ST_DONE; |
state.x_sum <= to_signed( SQRT2, state.x'length ); |
state.y_sum <= (others => '0' ); |
state.a <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ); |
state.st <= ST_DONE; |
elsif state.x = -XY_MAX and state.y = -XY_MAX then |
-- all-max 2 |
state.a <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI; |
state.x <= to_signed( SQRT2, state.x'length ); |
state.y <= (others => '0' ); |
state.st <= ST_DONE; |
state.x_sum <= to_signed( SQRT2, state.x'length ); |
state.y_sum <= (others => '0' ); |
state.a <= resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ) - PI; |
state.st <= ST_DONE; |
elsif state.x = XY_MAX and state.y = -XY_MAX then |
-- all-max 3 |
state.a <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ); |
state.x <= to_signed( SQRT2, state.x'length ); |
state.y <= (others => '0' ); |
state.st <= ST_DONE; |
state.x_sum <= to_signed( SQRT2, state.x'length ); |
state.y_sum <= (others => '0' ); |
state.a <= resize( -angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ); |
state.st <= ST_DONE; |
elsif state.x = -XY_MAX and state.y = XY_MAX then |
-- all-max 4 |
state.a <= PI- resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ); |
state.x <= to_signed( SQRT2, state.x'length ); |
state.y <= (others => '0' ); |
state.st <= ST_DONE; |
state.x_sum <= to_signed( SQRT2, state.x'length ); |
state.y_sum <= (others => '0' ); |
state.a <= PI- resize( angular_lut( 0, state.mode( 1 downto 0 ), A_WIDTH ), A_WIDTH_I ); |
state.st <= ST_DONE; |
|
elsif state.x = 0 and state.y > 0 then |
-- fixed rotation of pi/2 |
state.a <= to_signed( PI_H, state.a'length ); |
state.x <= state.y; |
state.y <= ( others => '0' ); |
state.st<= ST_DONE; |
state.x_sum <= state.y; |
state.y_sum <= ( others => '0' ); |
state.a <= to_signed( PI_H, state.a'length ); |
state.st <= ST_DONE; |
elsif state.x = 0 and state.y < 0 then |
-- fixed rotation of -pi/2 |
state.a <= to_signed( -PI_H, state.a'length ); |
state.x <= -state.y; |
state.y <= ( others => '0' ); |
state.st<= ST_DONE; |
state.x_sum <= -state.y; |
state.y_sum <= ( others => '0' ); |
state.a <= to_signed( -PI_H, state.a'length ); |
state.st <= ST_DONE; |
|
elsif state.x < 0 and state.y >= 0 then |
-- move from second quadrant to fourth |
472,6 → 505,7
>>>>>>> initial commit |
======= |
-- linear rotation mode |
|
if state.x < 0 then |
state.x <= - state.x; |
state.y <= - state.y; |
523,8 → 557,10
|
|
if state.do_shift = '1' then |
-- get the angle, do the shifting and set the right angle |
state.do_shift <= '0'; |
|
-- get the angle, do the shifting and set the correct angle |
|
if sign = '1' then |
|
-- circular case |
572,7 → 608,6
state.x_sh <= - SHIFT_RIGHT( state.x, to_integer( state.i ) ); |
|
end if; |
state.do_shift <= '0'; |
|
-- abort condition |
<<<<<<< HEAD |
638,9 → 673,9
end if; |
|
|
|
|
|
|
-- |
-- removal of the cordic gain |
-- |
649,7 → 684,6
-- calculate the RM_GAIN steps |
if state.i = (RM_GAIN) then |
state.st <= ST_DONE; |
state.done <= '1'; |
state.i <= ( others => '0' ); |
else |
state.i <= state.i + 1; |
662,8 → 696,6
mult_0_21( state.x, state.x_sh, state.x_sum, to_integer( state.i ), RM_GAIN ); |
mult_0_21( state.y, state.y_sh, state.y_sum, to_integer( state.i ), RM_GAIN ); |
else |
-- TODO merge ST_DONE and state.done |
state.done <= '1'; |
state.st <= ST_DONE; |
state.x_sum <= state.x; |
state.y_sum <= state.y; |
672,7 → 704,6
|
elsif state.st = ST_DONE then |
state.st <= ST_IDLE; |
state.done <= '0'; |
end if; |
-- end states |
|
686,7 → 717,7
-- end clk |
|
end process; |
done <= state.done ; |
done <= '1' when state.st = ST_DONE else '0'; |
x_o <= std_logic_vector( state.x_sum ); |
y_o <= std_logic_vector( state.y_sum ); |
a_o <= std_logic_vector( state.a ); |
/yac/trunk/c_octave/cordic_iterative.c
56,8 → 56,11
#include <stdio.h> |
#include <stdlib.h> |
#include <math.h> |
#include "mex.h" |
|
#ifndef OR32_TARGET |
#include "mex.h" |
#endif |
|
/* enable debug output */ |
<<<<<<< HEAD |
<<<<<<< HEAD |
69,7 → 72,6
#define PRINT_DEBUG 0 |
>>>>>>> Updated C and RTL model as well as the documentation |
|
|
/* #define CORDIC_ROUNDING 0.5 */ |
#define CORDIC_ROUNDING 0.0 |
|
83,11 → 85,11
#define C_MODE_HYP 0x02 |
|
|
#ifndef OR32_TARGET |
#define PRINT mexPrintf |
#endif |
|
#define PRINT mexPrintf |
|
|
|
<<<<<<< HEAD |
<<<<<<< HEAD |
======= |
157,9 → 159,9
|
|
|
#ifndef OR32_TARGET |
|
|
|
void mexFunction(int nlhs, mxArray *plhs[], |
int nrhs, const mxArray *prhs[]) |
{ |
177,16 → 179,16
mexErrMsgTxt("8 input arguments required"); |
if(nlhs!=4) |
mexErrMsgTxt("4 output arguments required"); |
|
|
if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0])) |
mexErrMsgTxt("Input x must be double and non-complex"); |
|
|
if (!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1])) |
mexErrMsgTxt("Input y must be double and non-complex"); |
|
|
if (!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2])) |
mexErrMsgTxt("Input a must be double and non-complex"); |
|
|
mrowsx = mxGetM(prhs[0]); |
ncolsx = mxGetN(prhs[0]); |
mrowsy = mxGetM(prhs[1]); |
193,23 → 195,23
ncolsy = mxGetN(prhs[1]); |
mrowsz = mxGetM(prhs[2]); |
ncolsz = mxGetN(prhs[2]); |
|
|
|
|
|
if (mrowsx > 1 || mrowsy >1 || mrowsz > 1) |
mexErrMsgTxt("Input vector must have the size Nx1."); |
|
/* printf("%d %d %d\n", ncolsx, ncolsy, ncolsa); */ |
|
|
if (ncolsx!=ncolsy || ncolsx!=ncolsz || ncolsy!=ncolsz) |
mexErrMsgTxt("Input vectors don't have the same length!"); |
|
|
|
|
plhs[0] = mxCreateDoubleMatrix(mrowsx,ncolsx,mxREAL); |
plhs[1] = mxCreateDoubleMatrix(mrowsy,ncolsy,mxREAL); |
plhs[2] = mxCreateDoubleMatrix(mrowsz,ncolsz,mxREAL); |
plhs[3] = mxCreateDoubleMatrix(mrowsz,ncolsz,mxREAL); |
|
|
inx = mxGetPr(prhs[0]); |
iny = mxGetPr(prhs[1]); |
inz = mxGetPr(prhs[2]); |
242,16 → 244,16
outy[i] = outy_i; |
outz[i] = outz_i; |
outi[i] = it; |
|
|
|
} |
} |
|
#endif |
|
|
|
|
|
void cordic_int( long long int x_i, |
long long int y_i, |
long long int a_i, |
281,11 → 283,11
>>>>>>> Updated C and RTL model as well as the documentation |
|
|
|
|
|
/* total with, including guard bits */ |
int XY_WIDTH_G = XY_WIDTH + GUARD_BITS; |
|
|
cordic_int_dbg( x_i, y_i, a_i, mode, 0, "input" ); |
|
<<<<<<< HEAD |
351,6 → 353,7
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; |
|
364,16 → 367,40
>>>>>>> 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; |
|
|
cordic_int_dbg( *x, *y, *a, mode, 0, "before init" ); |
|
|
<<<<<<< HEAD |
>>>>>>> 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 */ |
if( 0 == ( mode & C_FLAG_VEC_ROT ) && |
else if( 0 == ( mode & C_FLAG_VEC_ROT ) && |
C_MODE_CIR == ( mode & C_MODE_MSK ) ) |
{ |
|
|
/* move from third quadrant to first |
quadrant if necessary */ |
if( *a < - PI_H ) |
409,21 → 436,14
======= |
>>>>>>> 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 |
PRINT( "All max, skipping rotations 1\n" ); |
#endif |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5; |
*y = 0; |
*a = cordic_int_lut( mode, 0, A_WIDTH ); |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ); |
already_done = 1; |
} |
else if( *x == -XY_MAX && *y == -XY_MAX ) |
431,8 → 451,9
#if PRINT_DEBUG > 0 |
PRINT( "All max, skipping rotations 2\n" ); |
#endif |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5; |
*y = 0; |
*a = cordic_int_lut( mode, 0, A_WIDTH ) - PI; |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ); |
already_done = 1; |
} |
else if( *x == XY_MAX && *y == -XY_MAX ) |
440,8 → 461,9
#if PRINT_DEBUG > 0 |
PRINT( "All max, skipping rotations 3\n" ); |
#endif |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5; |
*y = 0; |
*a = -cordic_int_lut( mode, 0, A_WIDTH ); |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ); |
already_done = 1; |
} |
else if( *x == -XY_MAX && *y == XY_MAX ) |
449,8 → 471,9
#if PRINT_DEBUG > 0 |
PRINT( "All max, skipping rotations 4\n" ); |
#endif |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ) + 0.5; |
*y = 0; |
*a = PI - cordic_int_lut( mode, 0, A_WIDTH ); |
*x = sqrt( 2 ) * pow( 2, XY_WIDTH-1 ); |
already_done = 1; |
} |
|
462,7 → 485,7
*x = *y; |
already_done = 1; |
#if PRINT_DEBUG > 0 |
PRINT( "Fixed value of pi/2, skipping rotations" ); |
PRINT( "Fixed value of pi/2, skipping rotations\n" ); |
#endif |
*y = 0; |
} |
473,7 → 496,7
*y = 0; |
already_done = 1; |
#if PRINT_DEBUG > 0 |
PRINT( "Fixed value of -pi/2, skipping rotations" ); |
PRINT( "Fixed value of -pi/2, skipping rotations\n" ); |
#endif |
} |
else if( *x < 0 && *y >= 0 ) |
545,7 → 568,6
} |
*a = 0; |
} |
|
cordic_int_dbg( *x, *y, *a, mode, 0, "after init" ); |
<<<<<<< HEAD |
<<<<<<< HEAD |
576,11 → 598,11
int cordic_int_repeat( iteration, mode ) |
{ |
int i = 4; |
|
|
if( C_MODE_HYP != ( mode & C_MODE_MSK ) ) |
return 0; |
|
|
|
|
while( 1 ) |
{ |
if( i == iteration ) |
669,7 → 691,7
} |
} |
cordic_int_dbg( *x, *y, *a, mode, it, "after rotation" ); |
|
|
/* abort condition */ |
if( ( mode & C_FLAG_VEC_ROT ) == 0 && |
<<<<<<< HEAD |
685,7 → 707,7
if( ( mode & C_FLAG_VEC_ROT ) == 0 && |
( *a == alst ) ) |
break; |
|
|
if( ( mode & C_FLAG_VEC_ROT ) != 0 && |
<<<<<<< HEAD |
<<<<<<< HEAD |
703,7 → 725,9
|
else if( it > 40 ) |
{ |
#if PRINT_DEBUG |
PRINT( "ERROR: abort %lld %lld %lld %lld - %d - %d!\n", *a, alst, *y, ylst, mode, *y == ylst ); |
#endif |
it = -1; |
break; |
} |
/yac/trunk/c_octave/cordic_iterative_test.m
99,30 → 99,15
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN |
|
|
% |
% flags: they are also define in cordic_iterative.c and |
% cordic_iterative_pkg.vhd |
C_FLAG_VEC_ROT = 2^3; |
C_FLAG_ATAN_3 = 2^2; |
C_MODE_CIRC = 0; |
C_MODE_LIN = 1; |
C_MODE_HYP = 2; |
cordic_iterative_setup |
|
% initialize the random-generator's seed |
rand('seed', 1633); |
% open output file |
tb_fid = fopen( TB_FILE, 'w' ); |
|
|
% cordic setup: |
% this must fit to the testbench |
XY_WIDTH = 25; |
ANGLEWIDTH = 25; |
GUARDBITS = 2; |
RM_GAIN = 5; |
|
|
% Number of tests, which are run |
N_TESTS = 10000; |
|
<<<<<<< HEAD |
% open test file |
tb_fid = fopen( './tb_data.txt', 'w' ); |
<<<<<<< HEAD |
211,6 → 196,8
|
|
|
======= |
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper |
|
% |
% run test, which uses random values |
291,7 → 278,7
-1 -1 -1 -1 -1 -1 -1 -1 -1 ]; |
|
data_d = data_a * pi; |
|
|
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ]; |
data_b_div = [ 1 ,1, 1, 1, -1, -1 ]; |
|
302,8 → 289,8
data_c, tb_fid ); |
[ ~, div_err, it_4 ] = cdiv( data_a_div, data_b_div, tb_fid ); |
[ ~, mul_err, it_5 ] = cmul( data_a, data_b, tb_fid ); |
|
print_result_info( ... |
|
print_result( ... |
atan_err, it_1, ... |
abs_err, it_1, ... |
sin_err, it_2, ... |
379,6 → 366,8
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' ); |
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' ); |
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' ); |
|
|
end |
|
|
441,25 → 430,47
[ ~, ~, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid ); |
[ ~, ~, sinh_err, cosh_err, it_7 ] = csinhcosh( data_a, tb_fid ); |
|
print_result_info( atan_err, it_1, ... |
abs_err, it_1, ... |
sin_err, it_2, ... |
cos_err, it_2, ... |
x_err, it_3, ... |
y_err, it_3, ... |
div_err, it_4, ... |
mul_err, it_5, ... |
atanh_err, it_6, ... |
sqrt_err, it_6, ... |
sinh_err, it_7, ... |
cosh_err, it_7, ... |
'Random Value Test' ); |
|
|
print_result_header( 'Random Test Result' ); |
print_result2( 'atan', it_1, atan_err, data_a, data_b ); |
print_result2( 'abs ', it_1, abs_err, data_a, data_b ); |
print_result2( 'sin ', it_2, sin_err, data_a, data_b ); |
print_result2( 'cos ', it_2, cos_err, data_a, data_b ); |
|
|
|
print_result( atan_err, it_1, ... |
abs_err, it_1, ... |
sin_err, it_2, ... |
cos_err, it_2, ... |
x_err, it_3, ... |
y_err, it_3, ... |
div_err, it_4, ... |
mul_err, it_5, ... |
atanh_err, it_6, ... |
sqrt_err, it_6, ... |
sinh_err, it_7, ... |
cosh_err, it_7, ... |
'Random Value Test' ); |
|
|
end |
|
function print_result_header( title ) |
printf( ' ___________________________________________________________________\n' ); |
fprintf( ' %s\n', title); |
fprintf( ' -----+-------------------+--------------------+-------------------\n' ); |
end |
|
function print_result_info( ... |
function print_result2( msg, it, err, a, b ) |
|
[ verr, ierr ] = max( err ); |
fprintf( '%s | %.14f | (%.14f %.14f) | %.14f | %.5f \n', msg, verr, a( ierr ), b( ierr ), mean( err ), max( it ) ) |
|
end |
|
|
function print_result( ... |
atan_err, atan_it, ... |
abs_err, abs_it, ... |
sin_err, sin_it, ... |
492,7 → 503,6
fprintf( ' sinh | % .14f | % .14f | %.5f \n', max( sinh_err ), mean( sinh_err ), max( sinh_it ) ); |
fprintf( ' cosh | % .14f | % .14f | %.5f \n', max( cosh_err ), mean( cosh_err ), max( cosh_it ) ); |
|
end |
|
======= |
[ ~, ~, sin_err, cos_err, it_2 ] = cpol2cart( data_a, data_b, tb_fid ); |
524,6 → 534,7
>>>>>>> initial commit |
|
|
end |
|
|
|
550,9 → 561,9
ANGLEWIDTH, ... |
GUARDBITS, ... |
RM_GAIN ); |
|
|
|
|
|
|
cosh_res = rcosh ./ ( 2^(XY_WIDTH-1)-1 ); |
sinh_res = rsinh ./ ( 2^(XY_WIDTH-1)-1 ); |
cosh_m = cosh( th ); |
560,7 → 571,7
sinh_err = abs(sinh_res - sinh_m ); |
cosh_err = abs(cosh_res - cosh_m ); |
|
|
|
% write TB data |
write_tb( fid, xi, yi, ai, rcosh, rsinh, ra, mode ); |
|
604,7 → 615,7
abs_res = rx ./ ( 2^(XY_WIDTH-1) -1 ); |
atan_err = abs( m_th - atan_res ); |
abs_err = abs( m_r - abs_res ); |
|
|
% write TB data |
write_tb( fid, xi, yi, ai, rx, ry, ra, mode ); |
|
638,8 → 649,8
ANGLEWIDTH, ... |
GUARDBITS, ... |
RM_GAIN ); |
|
|
|
|
mul_res = rmul ./ (2^(ANGLEWIDTH-1)-1); |
mul_err = abs( y.*x - mul_res ); |
|
676,8 → 687,8
ANGLEWIDTH, ... |
GUARDBITS, ... |
RM_GAIN ); |
|
|
|
|
div_res = rdiv ./ (2^(ANGLEWIDTH-1)-1); |
div_err = abs( y./x - div_res ); |
|
715,9 → 726,9
ANGLEWIDTH, ... |
GUARDBITS, ... |
RM_GAIN ); |
|
|
tmp = ( x + 1i * y ) .* exp( i * th ); |
|
|
x_res = rx ./ ( 2^(XY_WIDTH-1)-1 ); |
y_res = ry ./ ( 2^(XY_WIDTH-1)-1 ); |
|
777,9 → 788,9
ANGLEWIDTH, ... |
GUARDBITS, ... |
RM_GAIN ); |
|
|
|
|
|
|
cos_res = rcos ./ ( 2^(XY_WIDTH-1)-1 ); |
sin_res = rsin ./ ( 2^(XY_WIDTH-1)-1 ); |
[ cos_m, sin_m ] = pol2cart( th, r ); |
815,7 → 826,6
xi = round( x * (2^(XY_WIDTH-1)-1) ); |
yi = round( y * (2^(XY_WIDTH-1)-1) ); |
|
|
mode = C_FLAG_VEC_ROT + C_MODE_CIRC; |
|
|
869,13 → 879,3
|
|
|
function write_tb( fid, x_i, y_i, a_i, x_o, y_o, a_o, mode ) |
|
if fid > 0 |
for x = 1 : length( x_i ) |
fprintf( fid, '%ld ', fix( [ x_i(x), y_i(x), a_i(x), x_o(x), y_o(x), a_o(x), mode ] ) ); |
fprintf( fid, '\n' ); |
end |
end |
|
end |
/yac/trunk/c_octave/cordic_iterative_setup.m
0,0 → 1,37
|
% |
% flags: they are also define in cordic_iterative.c and |
% cordic_iterative_pkg.vhd |
C_FLAG_VEC_ROT = 2^3; |
C_FLAG_ATAN_3 = 2^2; |
C_MODE_CIRC = 0; |
C_MODE_LIN = 1; |
C_MODE_HYP = 2; |
|
% initialize the random-generator's seed |
rand('seed', 1633); |
|
|
% cordic setup: |
% this must fit to the testbench |
XY_WIDTH = 8; |
ANGLEWIDTH = 8; |
GUARDBITS = 2; |
RM_GAIN = 3; |
|
TB_FILE = './tb_data.txt' |
% open test file |
%tb_fid = 0; |
|
|
function write_tb( fid, x_i, y_i, a_i, x_o, y_o, a_o, mode ) |
|
if fid > 0 |
for x = 1 : length( x_i ) |
fprintf( fid, '%ld ', fix( [ x_i(x), y_i(x), a_i(x), x_o(x), y_o(x), a_o(x), mode ] ) ); |
fprintf( fid, '\n' ); |
end |
end |
|
end |
|