1 #include "FastMathQ15.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 69 10 /* 11 12 Reference patterns are generated with 13 a double precision computation. 14 15 */ 16 #define ABS_SQRT_ERROR ((q15_t)6) 17 18 #define ABS_ERROR ((q15_t)10) 19 20 #define LOG_ABS_ERROR ((q15_t)3) 21 #define ABS_ATAN_ERROR ((q15_t)3) 22 #define DIV_ERROR ((q15_t)2) 23 #define RECIP_ERROR ((q15_t)2) 24 25 test_vlog_q15()26 void FastMathQ15::test_vlog_q15() 27 { 28 const q15_t *inp = input.ptr(); 29 q15_t *outp = output.ptr(); 30 31 arm_vlog_q15(inp,outp,ref.nbSamples()); 32 33 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 34 ASSERT_NEAR_EQ(ref,output,LOG_ABS_ERROR); 35 ASSERT_EMPTY_TAIL(output); 36 37 } 38 test_atan2_scalar_q15()39 void FastMathQ15::test_atan2_scalar_q15() 40 { 41 const q15_t *inp = input.ptr(); 42 q15_t *outp = output.ptr(); 43 q15_t res; 44 unsigned long i; 45 arm_status status=ARM_MATH_SUCCESS; 46 47 for(i=0; i < ref.nbSamples(); i++) 48 { 49 status=arm_atan2_q15(inp[2*i],inp[2*i+1],&res); 50 outp[i]=res; 51 52 ASSERT_TRUE((status == ARM_MATH_SUCCESS)); 53 54 } 55 56 ASSERT_SNR(ref,output,(q15_t)SNR_THRESHOLD); 57 ASSERT_NEAR_EQ(ref,output,ABS_ATAN_ERROR); 58 } 59 60 test_division_q15()61 void FastMathQ15::test_division_q15() 62 { 63 const q15_t *nump = numerator.ptr(); 64 const q15_t *denp = denominator.ptr(); 65 q15_t *outp = output.ptr(); 66 int16_t *shiftp = shift.ptr(); 67 arm_status status; 68 69 70 for(unsigned long i=0; i < ref.nbSamples(); i++) 71 { 72 status = arm_divide_q15(nump[i],denp[i],&outp[i],&shiftp[i]); 73 } 74 75 (void)status; 76 77 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 78 ASSERT_NEAR_EQ(ref,output,DIV_ERROR); 79 ASSERT_EQ(refShift,shift); 80 81 } 82 83 test_cos_q15()84 void FastMathQ15::test_cos_q15() 85 { 86 const q15_t *inp = input.ptr(); 87 q15_t *outp = output.ptr(); 88 unsigned long i; 89 90 for(i=0; i < ref.nbSamples(); i++) 91 { 92 outp[i]=arm_cos_q15(inp[i]); 93 } 94 95 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 96 ASSERT_NEAR_EQ(ref,output,ABS_ERROR); 97 98 } 99 test_sin_q15()100 void FastMathQ15::test_sin_q15() 101 { 102 const q15_t *inp = input.ptr(); 103 q15_t *outp = output.ptr(); 104 unsigned long i; 105 106 for(i=0; i < ref.nbSamples(); i++) 107 { 108 outp[i]=arm_sin_q15(inp[i]); 109 } 110 111 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 112 ASSERT_NEAR_EQ(ref,output,ABS_ERROR); 113 114 } 115 test_sqrt_q15()116 void FastMathQ15::test_sqrt_q15() 117 { 118 const q15_t *inp = input.ptr(); 119 q15_t *outp = output.ptr(); 120 arm_status status; 121 unsigned long i; 122 123 124 for(i=0; i < ref.nbSamples(); i++) 125 { 126 127 status=arm_sqrt_q15(inp[i],&outp[i]); 128 ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] <= 0) && (status == ARM_MATH_ARGUMENT_ERROR))); 129 } 130 131 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 132 ASSERT_NEAR_EQ(ref,output,ABS_SQRT_ERROR); 133 134 } 135 test_recip_q15()136 void FastMathQ15::test_recip_q15() 137 { 138 const q15_t *inp = input.ptr(); 139 q15_t *outp = output.ptr(); 140 int16_t *shiftp = shift.ptr(); 141 142 143 for(unsigned long i=0; i < ref.nbSamples(); i++) 144 { 145 shiftp[i] = arm_recip_q15(inp[i],&outp[i],armRecipTableQ15); 146 } 147 148 149 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 150 ASSERT_NEAR_EQ(ref,output,RECIP_ERROR); 151 ASSERT_EQ(refShift,shift); 152 153 } 154 setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)155 void FastMathQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr) 156 { 157 (void)paramsArgs; 158 switch(id) 159 { 160 case FastMathQ15::TEST_COS_Q15_1: 161 { 162 input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr); 163 ref.reload(FastMathQ15::COS1_Q15_ID,mgr); 164 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 165 166 } 167 break; 168 169 case FastMathQ15::TEST_SIN_Q15_2: 170 { 171 input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr); 172 ref.reload(FastMathQ15::SIN1_Q15_ID,mgr); 173 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 174 175 } 176 break; 177 178 case FastMathQ15::TEST_SQRT_Q15_3: 179 { 180 input.reload(FastMathQ15::SQRTINPUT1_Q15_ID,mgr); 181 ref.reload(FastMathQ15::SQRT1_Q15_ID,mgr); 182 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 183 184 } 185 break; 186 187 case FastMathQ15::TEST_DIVISION_Q15_4: 188 { 189 numerator.reload(FastMathQ15::NUMERATOR_Q15_ID,mgr); 190 denominator.reload(FastMathQ15::DENOMINATOR_Q15_ID,mgr); 191 192 ref.reload(FastMathQ15::DIVISION_VALUE_Q15_ID,mgr); 193 refShift.reload(FastMathQ15::DIVISION_SHIFT_S16_ID,mgr); 194 195 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 196 shift.create(ref.nbSamples(),FastMathQ15::SHIFT_S16_ID,mgr); 197 198 } 199 break; 200 201 case FastMathQ15::TEST_VLOG_Q15_5: 202 { 203 input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr); 204 ref.reload(FastMathQ15::LOG1_Q15_ID,mgr); 205 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 206 207 } 208 break; 209 210 case FastMathQ15::TEST_VLOG_Q15_6: 211 { 212 input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,7); 213 ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,7); 214 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 215 216 } 217 break; 218 219 case FastMathQ15::TEST_VLOG_Q15_7: 220 { 221 input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,16); 222 ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,16); 223 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 224 225 } 226 break; 227 228 case FastMathQ15::TEST_VLOG_Q15_8: 229 { 230 input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,23); 231 ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,23); 232 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 233 234 } 235 break; 236 237 case FastMathQ15::TEST_ATAN2_SCALAR_Q15_9: 238 { 239 input.reload(FastMathQ15::ATAN2INPUT1_Q15_ID,mgr); 240 ref.reload(FastMathQ15::ATAN2_Q15_ID,mgr); 241 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 242 } 243 break; 244 245 case FastMathQ15::TEST_RECIP_Q15_10: 246 { 247 input.reload(FastMathQ15::RECIPINPUT1_Q15_ID,mgr); 248 249 ref.reload(FastMathQ15::RECIP_VAL_Q15_ID,mgr); 250 refShift.reload(FastMathQ15::RECIP_SHIFT_S16_ID,mgr); 251 252 output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr); 253 shift.create(ref.nbSamples(),FastMathQ15::SHIFT_S16_ID,mgr); 254 255 } 256 break; 257 258 } 259 260 } 261 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)262 void FastMathQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 263 { 264 (void)id; 265 output.dump(mgr); 266 267 } 268