4 * Created on: 2014/01/19
8 #include "fx_vector_test.h"
12 #define SATP(x) (((x)>2147483647LL)?(2147483647LL):x)
13 #define SAT(x) (((x)>=-2147483648LL)?(SATP(x)):-2147483648LL)
15 #define mult_fr1x32x32(x,y) SAT(((long long )(x)*(long long)(y)+0x40000000)>>31)
16 #define neg_mult_fr1x32x32(x,y) SAT((-(long long )(x)*(long long)(y)+0x40000000)>>31)
19 void clearBuffer ( fract32 buf[], int count)
22 for ( i= 0; i<count; i++ )
27 * Basic test to see vector + vector addition.
29 #define NUMSAMPLE_01 4
31 fract32 buf_a_01[NUMSAMPLE_01]=
39 fract32 buf_b_01[NUMSAMPLE_01] =
47 fract32 desired_01[NUMSAMPLE_01] =
49 0x09000000, // Simple addition
50 0x7FFFFFFF, // Saturated
52 0x00000000, // 0 for count test
55 void test_01_fr32_vector_add()
57 fract32 output[NUMSAMPLE_01];
61 // clear output buffer
62 clearBuffer( output, NUMSAMPLE_01);
63 // test addition. Sample is less than NUMSAMPLE_01 to test the count parameter
64 fr32_vector_add( buf_a_01, buf_b_01, output, NUMSAMPLE_01-1);
66 for ( i=0; i<NUMSAMPLE_01; i++)
68 if ( output[i] != desired_01[i] )
70 printf( "test_01 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_01[i] );
74 printf ("test_01 OK\n");
81 * Basic test to see scalar + vector addition.
83 #define NUMSAMPLE_02 4
85 fract32 buf_a_02[NUMSAMPLE_02]=
94 fract32 desired_02[NUMSAMPLE_02] =
96 0x09000000, // Simple addition
97 0x7FFFFFFF, // Saturated
99 0x00000000, // 0 for count test
102 void test_02_fr32_vector_add_svv()
104 fract32 output[NUMSAMPLE_02];
108 // clear output buffer
109 clearBuffer( output, NUMSAMPLE_02);
110 // test addition. Sample is less than NUMSAMPLE_02 to test the count parameter
111 fr32_vector_add_svv( 0x01000000, buf_a_02, output, NUMSAMPLE_02-1);
113 for ( i=0; i<NUMSAMPLE_02; i++)
115 if ( output[i] != desired_02[i] )
117 printf( "test_02 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_02[i] );
121 printf ("test_02 OK\n");
128 * Basic test to see vector + vector addition.
130 #define NUMSAMPLE_03 4
132 fract32 buf_a_03[NUMSAMPLE_03]=
140 fract32 buf_b_03[NUMSAMPLE_03] =
148 fract32 desired_03[NUMSAMPLE_03] =
150 0x08000000, // Simple addition
151 0x80000000, // Saturated
153 0x00000000, // 0 for count test
156 void test_03_fr32_vector_sub()
158 fract32 output[NUMSAMPLE_03];
162 // clear output buffer
163 clearBuffer( output, NUMSAMPLE_03);
164 // test subtraction. Sample is less than NUMSAMPLE_03 to test the count parameter
165 fr32_vector_sub( buf_a_03, buf_b_03, output, NUMSAMPLE_03-1);
167 for ( i=0; i<NUMSAMPLE_03; i++)
169 if ( output[i] != desired_03[i] )
171 printf( "test_03 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_03[i] );
175 printf ("test_03 OK\n");
182 * Basic test to see scalar + vector addition.
184 #define NUMSAMPLE_04 4
186 fract32 buf_a_04[NUMSAMPLE_04]=
195 fract32 desired_04[NUMSAMPLE_04] =
197 0x08000000, // Simple addition
198 0x7fffffff, // Saturated
200 0x00000000, // 0 for count test
203 void test_04_fr32_vector_sub_svv()
205 fract32 output[NUMSAMPLE_04];
209 // clear output buffer
210 clearBuffer( output, NUMSAMPLE_04);
211 // test subtraction. Sample is less than NUMSAMPLE_04 to test the count parameter
212 fr32_vector_sub_svv( 0x09000000, buf_a_04, output, NUMSAMPLE_04-1);
214 for ( i=0; i<NUMSAMPLE_04; i++)
216 if ( output[i] != desired_04[i] )
218 printf( "test_04 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_04[i] );
222 printf ("test_04 OK\n");
230 * Basic test to see scalar + vector addition.
232 #define NUMSAMPLE_05 15
234 fract32 buf_a_05[NUMSAMPLE_05]=
236 0x40008000, // summation test for 4 partial products
241 0x00008000, // L*L test 1
242 0x00008000, // L*L test 2
243 0x00008000, // L*L test 3
244 0x00000002, // H*L test 1
245 0x00000002, // H*L test 2
246 0x00000002, // H*L test 3
254 fract32 buf_b_05[NUMSAMPLE_05]=
267 0x00000002, // H*L test 1
268 0x00000002, // H*L test 2
269 0x00000002, // H*L test 3
274 fract32 desired_05[NUMSAMPLE_05] =
276 0x10006001, // Simple addition
282 0x00000000, // round up
283 0x00000000, // truncate to 0
285 0x00000001, // round up
286 0x00000000, // truncate to 0
288 0x00000001, // round up
289 0x00000000, // truncate to 0
290 0x00000000, // must zero
293 void test_05_fr32_vector_mul()
295 fract32 output[NUMSAMPLE_05];
299 // clear output buffer
300 clearBuffer( output, NUMSAMPLE_05);
301 // test subtraction. Sample is less than NUMSAMPLE_05 to test the count parameter
302 fr32_vector_mul( buf_a_05, buf_b_05, output, NUMSAMPLE_05-1);
304 for ( i=0; i<NUMSAMPLE_05; i++)
306 if ( output[i] != desired_05[i] )
308 printf( "test_05 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_05[i] );
312 printf ("test_05 OK\n");
320 * Basic test to see scalar + vector addition.
322 #define NUMSAMPLE_06 15
324 fract32 buf_a_06[NUMSAMPLE_06]=
326 0x40008000, // summation test for 4 partial products
331 0x00008000, // L*L test 1
332 0x00008000, // L*L test 2
333 0x00008000, // L*L test 3
334 0x00000002, // H*L test 1
335 0x00000002, // H*L test 2
336 0x00000002, // H*L test 3
344 fract32 buf_b_06[NUMSAMPLE_06]=
357 0x00000002, // H*L test 1
358 0x00000002, // H*L test 2
359 0x00000002, // H*L test 3
364 fract32 desired_06[NUMSAMPLE_06] =
366 0x10006001, // Simple addition
372 0x00000000, // round up
373 0x00000000, // truncate to 0
375 0x00000001, // round up
376 0x00000000, // truncate to 0
378 0x00000001, // round up
379 0x00000000, // truncate to 0
380 0x00000000, // must zero
383 void test_06_fr32_vector_mul_svv()
385 fract32 output[NUMSAMPLE_06];
389 // clear output buffer
390 clearBuffer( output, NUMSAMPLE_06);
391 // test subtraction. Sample is less than NUMSAMPLE_06 to test the count parameter
392 for( i=0; i<NUMSAMPLE_06-1; i++)
393 fr32_vector_mul_svv( buf_a_06[i], &buf_b_06[i], &output[i], 1);
395 for ( i=0; i<NUMSAMPLE_06; i++)
397 if ( output[i] != desired_06[i] )
399 printf( "test_06 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_06[i] );
403 printf ("test_06 OK\n");
412 * Basic test to see scalar + vector addition.
414 #define NUMSAMPLE_07 61
416 fract32 buf_ar_07[NUMSAMPLE_07]=
418 0x00000000, // offset check,
420 0x40008000, // summation test for 4 partial products
425 0x00008000, // L*L test 1
426 0x00008000, // L*L test 2
427 0x00008000, // L*L test 3
428 0x00000002, // H*L test 1
429 0x00000002, // H*L test 2
430 0x00000002, // H*L test 3
436 0x40008000, // summation test for 4 partial products
441 0x00008000, // L*L test 1
442 0x00008000, // L*L test 2
443 0x00008000, // L*L test 3
444 0x00000002, // H*L test 1
445 0x00000002, // H*L test 2
446 0x00000002, // H*L test 3
488 fract32 buf_ai_07[NUMSAMPLE_07]=
524 0x40008000, // summation test for 4 partial products
529 0x00008000, // L*L test 1
530 0x00008000, // L*L test 2
531 0x00008000, // L*L test 3
532 0x00000002, // H*L test 1
533 0x00000002, // H*L test 2
534 0x00000002, // H*L test 3
540 0x40008000, // summation test for 4 partial products
545 0x00008000, // L*L test 1
546 0x00008000, // L*L test 2
547 0x00008000, // L*L test 3
548 0x00000002, // H*L test 1
549 0x00000002, // H*L test 2
550 0x00000002, // H*L test 3
559 fract32 buf_br_07[NUMSAMPLE_07]=
574 0x00000002, // H*L test 1
575 0x00000002, // H*L test 2
576 0x00000002, // H*L test 3
606 0x00000002, // H*L test 1
607 0x00000002, // H*L test 2
608 0x00000002, // H*L test 3
630 fract32 buf_bi_07[NUMSAMPLE_07]=
661 0x00000002, // H*L test 1
662 0x00000002, // H*L test 2
663 0x00000002, // H*L test 3
693 0x00000002, // H*L test 1
694 0x00000002, // H*L test 2
695 0x00000002, // H*L test 3
701 fract32 desired_r_07[NUMSAMPLE_07] ;
703 fract32 desired_i_07[NUMSAMPLE_07] ;
705 void test_07_fr32_vector_complex_mul()
707 fract32 output_r[NUMSAMPLE_07], output_i[NUMSAMPLE_07];
711 // clear output buffer
712 clearBuffer( output_r, NUMSAMPLE_07);
713 clearBuffer( output_i, NUMSAMPLE_07);
715 for ( i=0; i<NUMSAMPLE_07; i++)
717 desired_r_07[i] = mult_fr1x32x32( buf_ar_07[i], buf_br_07[i])
718 - mult_fr1x32x32( buf_ai_07[i], buf_bi_07[i]);
719 desired_i_07[i] = mult_fr1x32x32( buf_ar_07[i], buf_bi_07[i])
720 + mult_fr1x32x32( buf_ai_07[i], buf_br_07[i]);
723 for ( i=46; i<NUMSAMPLE_07; i++)
725 desired_r_07[i] = mult_fr1x32x32( buf_ar_07[i], buf_br_07[i])
726 + neg_mult_fr1x32x32(buf_ai_07[i], buf_bi_07[i]);
729 // test subtraction. Sample is less than NUMSAMPLE_07 to test the count parameter
730 fr32_vector_complex_mul( buf_ar_07, buf_ai_07, buf_br_07, buf_bi_07,
731 output_r, output_i, NUMSAMPLE_07);
733 for ( i=0; i<NUMSAMPLE_07; i++)
735 if ( output_r[i] != desired_r_07[i] )
737 printf( "test_07 NG :output_r[%2d] = 0x%08X but should be 0x%08X\n", i, output_r[i], desired_r_07[i] );
740 if ( output_i[i] != desired_i_07[i] )
742 printf( "test_07 NG :output_i[%2d] = 0x%08X but should be 0x%08X\n", i, output_i[i], desired_i_07[i] );
746 printf ("test_07 OK\n");
754 * Basic test to see scalar + vector addition.
756 #define NUMSAMPLE_08 5
758 fract32 buf_a_08[NUMSAMPLE_08]=
768 fract32 desired_08[NUMSAMPLE_08] =
773 0x7FFFFFFF, // saturated
774 0x00000000, // 0 for count test
777 void test_08_fr32_vector_neg()
779 fract32 output[NUMSAMPLE_08];
783 // clear output buffer
784 clearBuffer( output, NUMSAMPLE_08);
785 // test subtraction. Sample is less than NUMSAMPLE_08 to test the count parameter
786 fr32_vector_neg( buf_a_08, output, NUMSAMPLE_08-1);
788 for ( i=0; i<NUMSAMPLE_08; i++)
790 if ( output[i] != desired_08[i] )
792 printf( "test_08 NG :output[%2d] = 0x%08X but should be 0x%08X\n", i, output[i], desired_08[i] );
796 printf ("test_08 OK\n");