FastMathF64.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include "arm_vec_math.h"
  2. #include "FastMathF64.h"
  3. #include <stdio.h>
  4. #include "Error.h"
  5. #include "Test.h"
  6. #define SNR_THRESHOLD 310
  7. /*
  8. Reference patterns are generated with
  9. a double precision computation.
  10. */
  11. #define REL_ERROR (2.0e-16)
  12. #define ABS_ERROR (2.0e-16)
  13. /*
  14. void FastMathF64::test_cos_f64()
  15. {
  16. const float64_t *inp = input.ptr();
  17. float64_t *outp = output.ptr();
  18. unsigned long i;
  19. for(i=0; i < ref.nbSamples(); i++)
  20. {
  21. outp[i]=arm_cos_f64(inp[i]);
  22. }
  23. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  24. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  25. }
  26. void FastMathF64::test_sin_f64()
  27. {
  28. const float64_t *inp = input.ptr();
  29. float64_t *outp = output.ptr();
  30. unsigned long i;
  31. for(i=0; i < ref.nbSamples(); i++)
  32. {
  33. outp[i]=arm_sin_f64(inp[i]);
  34. }
  35. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  36. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  37. }
  38. void FastMathF64::test_sqrt_f64()
  39. {
  40. const float64_t *inp = input.ptr();
  41. float64_t *outp = output.ptr();
  42. arm_status status;
  43. unsigned long i;
  44. for(i=0; i < ref.nbSamples(); i++)
  45. {
  46. status=arm_sqrt_f64(inp[i],&outp[i]);
  47. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] < 0.0f) && (status == ARM_MATH_ARGUMENT_ERROR)));
  48. }
  49. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  50. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  51. }
  52. */
  53. void FastMathF64::test_vlog_f64()
  54. {
  55. const float64_t *inp = input.ptr();
  56. float64_t *outp = output.ptr();
  57. arm_vlog_f64(inp,outp,ref.nbSamples());
  58. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  59. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  60. ASSERT_EMPTY_TAIL(output);
  61. }
  62. void FastMathF64::test_vexp_f64()
  63. {
  64. const float64_t *inp = input.ptr();
  65. float64_t *outp = output.ptr();
  66. arm_vexp_f64(inp,outp,ref.nbSamples());
  67. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  68. ASSERT_CLOSE_ERROR(ref,output,ABS_ERROR,REL_ERROR);
  69. ASSERT_EMPTY_TAIL(output);
  70. }
  71. void FastMathF64::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  72. {
  73. (void)paramsArgs;
  74. switch(id)
  75. {
  76. case FastMathF64::TEST_COS_F64_1:
  77. {
  78. input.reload(FastMathF64::ANGLES1_F64_ID,mgr);
  79. ref.reload(FastMathF64::COS1_F64_ID,mgr);
  80. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  81. }
  82. break;
  83. case FastMathF64::TEST_SIN_F64_2:
  84. {
  85. input.reload(FastMathF64::ANGLES1_F64_ID,mgr);
  86. ref.reload(FastMathF64::SIN1_F64_ID,mgr);
  87. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  88. }
  89. break;
  90. case FastMathF64::TEST_SQRT_F64_3:
  91. {
  92. input.reload(FastMathF64::SQRTINPUT1_F64_ID,mgr);
  93. ref.reload(FastMathF64::SQRT1_F64_ID,mgr);
  94. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  95. }
  96. break;
  97. case FastMathF64::TEST_VLOG_F64_4:
  98. {
  99. input.reload(FastMathF64::LOGINPUT1_F64_ID,mgr);
  100. ref.reload(FastMathF64::LOG1_F64_ID,mgr);
  101. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  102. }
  103. break;
  104. case FastMathF64::TEST_VLOG_F64_5:
  105. {
  106. /*
  107. If only one sample was taken here, the SNR
  108. computation would give 0 / 0 because the
  109. first value (1.0) has a log of 0.
  110. */
  111. input.reload(FastMathF64::LOGINPUT1_F64_ID,mgr,2);
  112. ref.reload(FastMathF64::LOG1_F64_ID,mgr,2);
  113. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  114. }
  115. break;
  116. case FastMathF64::TEST_VLOG_F64_6:
  117. {
  118. input.reload(FastMathF64::LOGINPUT1_F64_ID,mgr,4);
  119. ref.reload(FastMathF64::LOG1_F64_ID,mgr,4);
  120. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  121. }
  122. break;
  123. case FastMathF64::TEST_VLOG_F64_7:
  124. {
  125. input.reload(FastMathF64::LOGINPUT1_F64_ID,mgr,5);
  126. ref.reload(FastMathF64::LOG1_F64_ID,mgr,5);
  127. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  128. }
  129. break;
  130. case FastMathF64::TEST_VEXP_F64_8:
  131. {
  132. input.reload(FastMathF64::EXPINPUT1_F64_ID,mgr);
  133. ref.reload(FastMathF64::EXP1_F64_ID,mgr);
  134. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  135. }
  136. break;
  137. case FastMathF64::TEST_VEXP_F64_9:
  138. {
  139. input.reload(FastMathF64::EXPINPUT1_F64_ID,mgr,2);
  140. ref.reload(FastMathF64::EXP1_F64_ID,mgr,2);
  141. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  142. }
  143. break;
  144. case FastMathF64::TEST_VEXP_F64_10:
  145. {
  146. input.reload(FastMathF64::EXPINPUT1_F64_ID,mgr,4);
  147. ref.reload(FastMathF64::EXP1_F64_ID,mgr,4);
  148. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  149. }
  150. break;
  151. case FastMathF64::TEST_VEXP_F64_11:
  152. {
  153. input.reload(FastMathF64::EXPINPUT1_F64_ID,mgr,5);
  154. ref.reload(FastMathF64::EXP1_F64_ID,mgr,5);
  155. output.create(ref.nbSamples(),FastMathF64::OUT_F64_ID,mgr);
  156. }
  157. break;
  158. }
  159. }
  160. void FastMathF64::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  161. {
  162. (void)id;
  163. output.dump(mgr);
  164. }