FastMathF32.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include "FastMathF32.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "arm_math.h"
  5. #include "arm_vec_math.h"
  6. #include "Test.h"
  7. #define SNR_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. void FastMathF32::test_cos_f32()
  15. {
  16. const float32_t *inp = input.ptr();
  17. float32_t *refp = ref.ptr();
  18. float32_t *outp = output.ptr();
  19. int i;
  20. for(i=0; i < ref.nbSamples(); i++)
  21. {
  22. outp[i]=arm_cos_f32(inp[i]);
  23. }
  24. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  25. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  26. }
  27. void FastMathF32::test_sin_f32()
  28. {
  29. const float32_t *inp = input.ptr();
  30. float32_t *refp = ref.ptr();
  31. float32_t *outp = output.ptr();
  32. int i;
  33. for(i=0; i < ref.nbSamples(); i++)
  34. {
  35. outp[i]=arm_sin_f32(inp[i]);
  36. }
  37. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  38. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  39. }
  40. void FastMathF32::test_sqrt_f32()
  41. {
  42. const float32_t *inp = input.ptr();
  43. float32_t *refp = ref.ptr();
  44. float32_t *outp = output.ptr();
  45. arm_status status;
  46. int i;
  47. for(i=0; i < ref.nbSamples(); i++)
  48. {
  49. status=arm_sqrt_f32(inp[i],&outp[i]);
  50. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] < 0.0f) && (status == ARM_MATH_ARGUMENT_ERROR)));
  51. }
  52. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  53. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  54. }
  55. void FastMathF32::test_vlog_f32()
  56. {
  57. const float32_t *inp = input.ptr();
  58. float32_t *outp = output.ptr();
  59. arm_vlog_f32(inp,outp,ref.nbSamples());
  60. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  61. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  62. ASSERT_EMPTY_TAIL(output);
  63. }
  64. void FastMathF32::test_vexp_f32()
  65. {
  66. const float32_t *inp = input.ptr();
  67. float32_t *outp = output.ptr();
  68. arm_vexp_f32(inp,outp,ref.nbSamples());
  69. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  70. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  71. ASSERT_EMPTY_TAIL(output);
  72. }
  73. void FastMathF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  74. {
  75. switch(id)
  76. {
  77. case FastMathF32::TEST_COS_F32_1:
  78. {
  79. input.reload(FastMathF32::ANGLES1_F32_ID,mgr);
  80. ref.reload(FastMathF32::COS1_F32_ID,mgr);
  81. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  82. }
  83. break;
  84. case FastMathF32::TEST_SIN_F32_2:
  85. {
  86. input.reload(FastMathF32::ANGLES1_F32_ID,mgr);
  87. ref.reload(FastMathF32::SIN1_F32_ID,mgr);
  88. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  89. }
  90. break;
  91. case FastMathF32::TEST_SQRT_F32_3:
  92. {
  93. input.reload(FastMathF32::SQRTINPUT1_F32_ID,mgr);
  94. ref.reload(FastMathF32::SQRT1_F32_ID,mgr);
  95. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  96. }
  97. break;
  98. case FastMathF32::TEST_VLOG_F32_4:
  99. {
  100. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr);
  101. ref.reload(FastMathF32::LOG1_F32_ID,mgr);
  102. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  103. }
  104. break;
  105. case FastMathF32::TEST_VLOG_F32_5:
  106. {
  107. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,3);
  108. ref.reload(FastMathF32::LOG1_F32_ID,mgr,3);
  109. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  110. }
  111. break;
  112. case FastMathF32::TEST_VLOG_F32_6:
  113. {
  114. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,8);
  115. ref.reload(FastMathF32::LOG1_F32_ID,mgr,8);
  116. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  117. }
  118. break;
  119. case FastMathF32::TEST_VLOG_F32_7:
  120. {
  121. input.reload(FastMathF32::LOGINPUT1_F32_ID,mgr,11);
  122. ref.reload(FastMathF32::LOG1_F32_ID,mgr,11);
  123. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  124. }
  125. break;
  126. case FastMathF32::TEST_VEXP_F32_8:
  127. {
  128. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr);
  129. ref.reload(FastMathF32::EXP1_F32_ID,mgr);
  130. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  131. }
  132. break;
  133. case FastMathF32::TEST_VEXP_F32_9:
  134. {
  135. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,3);
  136. ref.reload(FastMathF32::EXP1_F32_ID,mgr,3);
  137. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  138. }
  139. break;
  140. case FastMathF32::TEST_VEXP_F32_10:
  141. {
  142. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,8);
  143. ref.reload(FastMathF32::EXP1_F32_ID,mgr,8);
  144. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  145. }
  146. break;
  147. case FastMathF32::TEST_VEXP_F32_11:
  148. {
  149. input.reload(FastMathF32::EXPINPUT1_F32_ID,mgr,11);
  150. ref.reload(FastMathF32::EXP1_F32_ID,mgr,11);
  151. output.create(ref.nbSamples(),FastMathF32::OUT_F32_ID,mgr);
  152. }
  153. break;
  154. }
  155. }
  156. void FastMathF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  157. {
  158. output.dump(mgr);
  159. }