1 #include "FastMathQ31.h" 2 #include <stdio.h> 3 #include "Error.h" 4 #include "Test.h" 5 6 #include "arm_common_tables.h" 7 #include "dsp/utils.h" 8 9 #define SNR_THRESHOLD 100 10 /* 11 12 Reference patterns are generated with 13 a double precision computation. 14 15 */ 16 #define ABS_SQRT_ERROR ((q31_t)7) 17 18 #define ABS_ERROR ((q31_t)2200) 19 #define ABS_DIV_ERROR ((q31_t)2) 20 #define LOG_ABS_ERROR ((q31_t)2) 21 22 #define ABS_ATAN_ERROR ((q31_t)3) 23 #define RECIP_ERROR ((q31_t)10) 24 test_atan2_scalar_q31()25 void FastMathQ31::test_atan2_scalar_q31() 26 { 27 const q31_t *inp = input.ptr(); 28 q31_t *outp = output.ptr(); 29 q31_t res; 30 unsigned long i; 31 arm_status status=ARM_MATH_SUCCESS; 32 33 for(i=0; i < ref.nbSamples(); i++) 34 { 35 status=arm_atan2_q31(inp[2*i],inp[2*i+1],&res); 36 outp[i]=res; 37 ASSERT_TRUE((status == ARM_MATH_SUCCESS)); 38 39 } 40 41 ASSERT_SNR(ref,output,(q31_t)SNR_THRESHOLD); 42 ASSERT_NEAR_EQ(ref,output,ABS_ATAN_ERROR); 43 } 44 test_vlog_q31()45 void FastMathQ31::test_vlog_q31() 46 { 47 const q31_t *inp = input.ptr(); 48 q31_t *outp = output.ptr(); 49 50 arm_vlog_q31(inp,outp,ref.nbSamples()); 51 52 53 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 54 ASSERT_NEAR_EQ(ref,output,LOG_ABS_ERROR); 55 ASSERT_EMPTY_TAIL(output); 56 57 } 58 test_division_q31()59 void FastMathQ31::test_division_q31() 60 { 61 const q31_t *nump = numerator.ptr(); 62 const q31_t *denp = denominator.ptr(); 63 q31_t *outp = output.ptr(); 64 int16_t *shiftp = shift.ptr(); 65 arm_status status; 66 67 68 for(unsigned long i=0; i < ref.nbSamples(); i++) 69 { 70 71 status = arm_divide_q31(nump[i],denp[i],&outp[i],&shiftp[i]); 72 } 73 74 (void)status; 75 76 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 77 ASSERT_NEAR_EQ(ref,output,ABS_DIV_ERROR); 78 ASSERT_EQ(refShift,shift); 79 80 81 } 82 test_cos_q31()83 void FastMathQ31::test_cos_q31() 84 { 85 const q31_t *inp = input.ptr(); 86 q31_t *outp = output.ptr(); 87 unsigned long i; 88 89 for(i=0; i < ref.nbSamples(); i++) 90 { 91 outp[i]=arm_cos_q31(inp[i]); 92 } 93 94 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 95 ASSERT_NEAR_EQ(ref,output,ABS_ERROR); 96 97 } 98 test_sin_q31()99 void FastMathQ31::test_sin_q31() 100 { 101 const q31_t *inp = input.ptr(); 102 q31_t *outp = output.ptr(); 103 unsigned long i; 104 105 for(i=0; i < ref.nbSamples(); i++) 106 { 107 outp[i]=arm_sin_q31(inp[i]); 108 } 109 110 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 111 ASSERT_NEAR_EQ(ref,output,ABS_ERROR); 112 113 } 114 test_sqrt_q31()115 void FastMathQ31::test_sqrt_q31() 116 { 117 const q31_t *inp = input.ptr(); 118 q31_t *outp = output.ptr(); 119 arm_status status; 120 unsigned long i; 121 122 for(i=0; i < ref.nbSamples(); i++) 123 { 124 status=arm_sqrt_q31(inp[i],&outp[i]); 125 ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] <= 0) && (status == ARM_MATH_ARGUMENT_ERROR))); 126 } 127 128 //ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 129 ASSERT_NEAR_EQ(ref,output,ABS_SQRT_ERROR); 130 131 } 132 test_recip_q31()133 void FastMathQ31::test_recip_q31() 134 { 135 const q31_t *inp = input.ptr(); 136 q31_t *outp = output.ptr(); 137 int16_t *shiftp = shift.ptr(); 138 139 140 for(unsigned long i=0; i < ref.nbSamples(); i++) 141 { 142 shiftp[i] = arm_recip_q31(inp[i],&outp[i],armRecipTableQ31); 143 } 144 145 146 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 147 ASSERT_NEAR_EQ(ref,output,RECIP_ERROR); 148 ASSERT_EQ(refShift,shift); 149 150 } 151 setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)152 void FastMathQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr) 153 { 154 (void)paramsArgs; 155 switch(id) 156 { 157 case FastMathQ31::TEST_COS_Q31_1: 158 { 159 input.reload(FastMathQ31::ANGLES1_Q31_ID,mgr); 160 ref.reload(FastMathQ31::COS1_Q31_ID,mgr); 161 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 162 163 } 164 break; 165 166 case FastMathQ31::TEST_SIN_Q31_2: 167 { 168 input.reload(FastMathQ31::ANGLES1_Q31_ID,mgr); 169 ref.reload(FastMathQ31::SIN1_Q31_ID,mgr); 170 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 171 172 } 173 break; 174 175 case FastMathQ31::TEST_SQRT_Q31_3: 176 { 177 input.reload(FastMathQ31::SQRTINPUT1_Q31_ID,mgr); 178 ref.reload(FastMathQ31::SQRT1_Q31_ID,mgr); 179 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 180 181 } 182 break; 183 184 case FastMathQ31::TEST_DIVISION_Q31_4: 185 { 186 numerator.reload(FastMathQ31::NUMERATOR_Q31_ID,mgr); 187 denominator.reload(FastMathQ31::DENOMINATOR_Q31_ID,mgr); 188 189 ref.reload(FastMathQ31::DIVISION_VALUE_Q31_ID,mgr); 190 refShift.reload(FastMathQ31::DIVISION_SHIFT_S16_ID,mgr); 191 192 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 193 shift.create(ref.nbSamples(),FastMathQ31::SHIFT_S16_ID,mgr); 194 195 } 196 break; 197 198 case FastMathQ31::TEST_VLOG_Q31_5: 199 { 200 input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr); 201 ref.reload(FastMathQ31::LOG1_Q31_ID,mgr); 202 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 203 204 } 205 break; 206 207 case FastMathQ31::TEST_VLOG_Q31_6: 208 { 209 input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr,3); 210 ref.reload(FastMathQ31::LOG1_Q31_ID,mgr,3); 211 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 212 213 } 214 break; 215 216 case FastMathQ31::TEST_VLOG_Q31_7: 217 { 218 input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr,8); 219 ref.reload(FastMathQ31::LOG1_Q31_ID,mgr,8); 220 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 221 222 } 223 break; 224 225 case FastMathQ31::TEST_VLOG_Q31_8: 226 { 227 input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr,11); 228 ref.reload(FastMathQ31::LOG1_Q31_ID,mgr,11); 229 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 230 231 } 232 break; 233 234 case FastMathQ31::TEST_ATAN2_SCALAR_Q31_9: 235 { 236 input.reload(FastMathQ31::ATAN2INPUT1_Q31_ID,mgr); 237 ref.reload(FastMathQ31::ATAN2_Q31_ID,mgr); 238 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 239 } 240 break; 241 242 case FastMathQ31::TEST_RECIP_Q31_10: 243 { 244 input.reload(FastMathQ31::RECIPINPUT1_Q31_ID,mgr); 245 246 ref.reload(FastMathQ31::RECIP_VAL_Q31_ID,mgr); 247 refShift.reload(FastMathQ31::RECIP_SHIFT_S16_ID,mgr); 248 249 output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr); 250 shift.create(ref.nbSamples(),FastMathQ31::SHIFT_S16_ID,mgr); 251 252 } 253 break; 254 255 } 256 257 } 258 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)259 void FastMathQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 260 { 261 (void)id; 262 output.dump(mgr); 263 264 } 265