1 #include "arm_vec_math.h" 2 3 #include "FastMathF32.h" 4 #include <stdio.h> 5 6 #include "Error.h" 7 #include "Test.h" 8 9 10 #define SNR_THRESHOLD 119 11 #define SNR_ATAN2_THRESHOLD 120 12 13 /* 14 15 Reference patterns are generated with 16 a double precision computation. 17 18 */ 19 #define REL_ERROR (1.0e-6) 20 #define ABS_ERROR (1.0e-5) 21 22 #define REL_ERROR_ATAN (5.0e-7) 23 #define ABS_ERROR_ATAN (5.0e-7) 24 test_atan2_scalar_f32()25 void FastMathF32::test_atan2_scalar_f32() 26 { 27 const float32_t *inp = input.ptr(); 28 float32_t *outp = output.ptr(); 29 float32_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_f32(inp[2*i],inp[2*i+1],&res); 36 outp[i]=res; 37 ASSERT_TRUE((status == ARM_MATH_SUCCESS)); 38 39 } 40 //printf("%f %f %f\n",inp[2*i],inp[2*i+1],outp[i]); 41 42 //ASSERT_SNR(ref,output,(float32_t)SNR_ATAN2_THRESHOLD); 43 ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR_ATAN,REL_ERROR_ATAN); 44 45 } 46 47 test_cos_f32()48 void FastMathF32::test_cos_f32() 49 { 50 const float32_t *inp = input.ptr(); 51 float32_t *outp = output.ptr(); 52 unsigned long i; 53 54 for(i=0; i < ref.nbSamples(); i++) 55 { 56 outp[i]=arm_cos_f32(inp[i]); 57 } 58 59 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 60 ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR); 61 62 } 63 test_sin_f32()64 void FastMathF32::test_sin_f32() 65 { 66 const float32_t *inp = input.ptr(); 67 float32_t *outp = output.ptr(); 68 unsigned long i; 69 70 for(i=0; i < ref.nbSamples(); i++) 71 { 72 outp[i]=arm_sin_f32(inp[i]); 73 } 74 75 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 76 ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR); 77 78 } 79 test_sqrt_f32()80 void FastMathF32::test_sqrt_f32() 81 { 82 const float32_t *inp = input.ptr(); 83 float32_t *outp = output.ptr(); 84 arm_status status; 85 unsigned long i; 86 87 for(i=0; i < ref.nbSamples(); i++) 88 { 89 status=arm_sqrt_f32(inp[i],&outp[i]); 90 ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] < 0.0f) && (status == ARM_MATH_ARGUMENT_ERROR))); 91 } 92 93 94 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 95 ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR); 96 97 98 } 99 test_vlog_f32()100 void FastMathF32::test_vlog_f32() 101 { 102 const float32_t *inp = input.ptr(); 103 float32_t *outp = output.ptr(); 104 105 arm_vlog_f32(inp,outp,ref.nbSamples()); 106 107 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 108 ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR); 109 ASSERT_EMPTY_TAIL(output); 110 111 } 112 test_vexp_f32()113 void FastMathF32::test_vexp_f32() 114 { 115 const float32_t *inp = input.ptr(); 116 float32_t *outp = output.ptr(); 117 118 arm_vexp_f32(inp,outp,ref.nbSamples()); 119 120 ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD); 121 ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR); 122 ASSERT_EMPTY_TAIL(output); 123 124 } 125 126 setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)127 void FastMathF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr) 128 { 129 (void)paramsArgs; 130 switch(id) 131 { 132 case FastMathF32::TEST_COS_F32_1: 133 { 134 input.reload(FastMathF32::ANGLES1_F32_ID,mgr); 135 ref.reload(FastMathF32::COS1_F32_ID,mgr); 136 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 137 138 } 139 break; 140 141 case FastMathF32::TEST_SIN_F32_2: 142 { 143 input.reload(FastMathF32::ANGLES1_F32_ID,mgr); 144 ref.reload(FastMathF32::SIN1_F32_ID,mgr); 145 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 146 147 } 148 break; 149 150 case FastMathF32::TEST_SQRT_F32_3: 151 { 152 input.reload(FastMathF32::SQRTINPUT1_F32_ID,mgr); 153 ref.reload(FastMathF32::SQRT1_F32_ID,mgr); 154 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 155 156 } 157 break; 158 159 case FastMathF32::TEST_VLOG_F32_4: 160 { 161 input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr); 162 ref.reload(FastMathF32::LOG1_F32_ID,mgr); 163 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 164 165 } 166 break; 167 168 case FastMathF32::TEST_VLOG_F32_5: 169 { 170 input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,3); 171 ref.reload(FastMathF32::LOG1_F32_ID,mgr,3); 172 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 173 174 } 175 break; 176 177 case FastMathF32::TEST_VLOG_F32_6: 178 { 179 input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,8); 180 ref.reload(FastMathF32::LOG1_F32_ID,mgr,8); 181 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 182 183 } 184 break; 185 186 case FastMathF32::TEST_VLOG_F32_7: 187 { 188 input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,11); 189 ref.reload(FastMathF32::LOG1_F32_ID,mgr,11); 190 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 191 192 } 193 break; 194 195 case FastMathF32::TEST_VEXP_F32_8: 196 { 197 input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr); 198 ref.reload(FastMathF32::EXP1_F32_ID,mgr); 199 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 200 201 } 202 break; 203 204 case FastMathF32::TEST_VEXP_F32_9: 205 { 206 input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,3); 207 ref.reload(FastMathF32::EXP1_F32_ID,mgr,3); 208 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 209 210 } 211 break; 212 213 case FastMathF32::TEST_VEXP_F32_10: 214 { 215 input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,8); 216 ref.reload(FastMathF32::EXP1_F32_ID,mgr,8); 217 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 218 219 } 220 break; 221 222 case FastMathF32::TEST_VEXP_F32_11: 223 { 224 input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,11); 225 ref.reload(FastMathF32::EXP1_F32_ID,mgr,11); 226 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 227 228 } 229 break; 230 231 case FastMathF32::TEST_ATAN2_SCALAR_F32_12: 232 { 233 input.reload(FastMathF32::ATAN2INPUT1_F32_ID,mgr); 234 ref.reload(FastMathF32::ATAN2_F32_ID,mgr); 235 output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr); 236 } 237 break; 238 239 240 241 } 242 243 } 244 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)245 void FastMathF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 246 { 247 (void)id; 248 output.dump(mgr); 249 250 } 251