FastMathF32.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include "arm_vec_math.h"
  2. #include "FastMathF32.h"
  3. #include <stdio.h>
  4. #include "Error.h"
  5. #include "Test.h"
  6. #define SNR_THRESHOLD 119
  7. #define SNR_ATAN2_THRESHOLD 120
  8. /*
  9. Reference patterns are generated with
  10. a double precision computation.
  11. */
  12. #define REL_ERROR (1.0e-6)
  13. #define ABS_ERROR (1.0e-5)
  14. #define REL_ERROR_ATAN (5.0e-7)
  15. #define ABS_ERROR_ATAN (5.0e-7)
  16. void FastMathF32::test_atan2_scalar_f32()
  17. {
  18. const float32_t *inp = input.ptr();
  19. float32_t *outp = output.ptr();
  20. float32_t res;
  21. unsigned long i;
  22. arm_status status=ARM_MATH_SUCCESS;
  23. for(i=0; i < ref.nbSamples(); i++)
  24. {
  25. status=arm_atan2_f32(inp[2*i],inp[2*i+1],&res);
  26. outp[i]=res;
  27. ASSERT_TRUE((status == ARM_MATH_SUCCESS));
  28. }
  29. //printf("%f %f %f\n",inp[2*i],inp[2*i+1],outp[i]);
  30. //ASSERT_SNR(ref,output,(float32_t)SNR_ATAN2_THRESHOLD);
  31. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR_ATAN,REL_ERROR_ATAN);
  32. }
  33. void FastMathF32::test_cos_f32()
  34. {
  35. const float32_t *inp = input.ptr();
  36. float32_t *outp = output.ptr();
  37. unsigned long i;
  38. for(i=0; i < ref.nbSamples(); i++)
  39. {
  40. outp[i]=arm_cos_f32(inp[i]);
  41. }
  42. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  43. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  44. }
  45. void FastMathF32::test_sin_f32()
  46. {
  47. const float32_t *inp = input.ptr();
  48. float32_t *outp = output.ptr();
  49. unsigned long i;
  50. for(i=0; i < ref.nbSamples(); i++)
  51. {
  52. outp[i]=arm_sin_f32(inp[i]);
  53. }
  54. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  55. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  56. }
  57. void FastMathF32::test_sqrt_f32()
  58. {
  59. const float32_t *inp = input.ptr();
  60. float32_t *outp = output.ptr();
  61. arm_status status;
  62. unsigned long i;
  63. for(i=0; i < ref.nbSamples(); i++)
  64. {
  65. status=arm_sqrt_f32(inp[i],&outp[i]);
  66. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] < 0.0f) && (status == ARM_MATH_ARGUMENT_ERROR)));
  67. }
  68. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  69. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  70. }
  71. void FastMathF32::test_vlog_f32()
  72. {
  73. const float32_t *inp = input.ptr();
  74. float32_t *outp = output.ptr();
  75. arm_vlog_f32(inp,outp,ref.nbSamples());
  76. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  77. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  78. ASSERT_EMPTY_TAIL(output);
  79. }
  80. void FastMathF32::test_vexp_f32()
  81. {
  82. const float32_t *inp = input.ptr();
  83. float32_t *outp = output.ptr();
  84. arm_vexp_f32(inp,outp,ref.nbSamples());
  85. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  86. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  87. ASSERT_EMPTY_TAIL(output);
  88. }
  89. void FastMathF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  90. {
  91. (void)paramsArgs;
  92. switch(id)
  93. {
  94. case FastMathF32::TEST_COS_F32_1:
  95. {
  96. input.reload(FastMathF32::ANGLES1_F32_ID,mgr);
  97. ref.reload(FastMathF32::COS1_F32_ID,mgr);
  98. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  99. }
  100. break;
  101. case FastMathF32::TEST_SIN_F32_2:
  102. {
  103. input.reload(FastMathF32::ANGLES1_F32_ID,mgr);
  104. ref.reload(FastMathF32::SIN1_F32_ID,mgr);
  105. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  106. }
  107. break;
  108. case FastMathF32::TEST_SQRT_F32_3:
  109. {
  110. input.reload(FastMathF32::SQRTINPUT1_F32_ID,mgr);
  111. ref.reload(FastMathF32::SQRT1_F32_ID,mgr);
  112. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  113. }
  114. break;
  115. case FastMathF32::TEST_VLOG_F32_4:
  116. {
  117. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr);
  118. ref.reload(FastMathF32::LOG1_F32_ID,mgr);
  119. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  120. }
  121. break;
  122. case FastMathF32::TEST_VLOG_F32_5:
  123. {
  124. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,3);
  125. ref.reload(FastMathF32::LOG1_F32_ID,mgr,3);
  126. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  127. }
  128. break;
  129. case FastMathF32::TEST_VLOG_F32_6:
  130. {
  131. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,8);
  132. ref.reload(FastMathF32::LOG1_F32_ID,mgr,8);
  133. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  134. }
  135. break;
  136. case FastMathF32::TEST_VLOG_F32_7:
  137. {
  138. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,11);
  139. ref.reload(FastMathF32::LOG1_F32_ID,mgr,11);
  140. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  141. }
  142. break;
  143. case FastMathF32::TEST_VEXP_F32_8:
  144. {
  145. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr);
  146. ref.reload(FastMathF32::EXP1_F32_ID,mgr);
  147. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  148. }
  149. break;
  150. case FastMathF32::TEST_VEXP_F32_9:
  151. {
  152. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,3);
  153. ref.reload(FastMathF32::EXP1_F32_ID,mgr,3);
  154. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  155. }
  156. break;
  157. case FastMathF32::TEST_VEXP_F32_10:
  158. {
  159. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,8);
  160. ref.reload(FastMathF32::EXP1_F32_ID,mgr,8);
  161. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  162. }
  163. break;
  164. case FastMathF32::TEST_VEXP_F32_11:
  165. {
  166. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,11);
  167. ref.reload(FastMathF32::EXP1_F32_ID,mgr,11);
  168. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  169. }
  170. break;
  171. case FastMathF32::TEST_ATAN2_SCALAR_F32_12:
  172. {
  173. input.reload(FastMathF32::ATAN2INPUT1_F32_ID,mgr);
  174. ref.reload(FastMathF32::ATAN2_F32_ID,mgr);
  175. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  176. }
  177. break;
  178. }
  179. }
  180. void FastMathF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  181. {
  182. (void)id;
  183. output.dump(mgr);
  184. }