FastMathF32.cpp 5.7 KB

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