FastMathQ31.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #include "FastMathQ31.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "Test.h"
  5. #define SNR_THRESHOLD 100
  6. /*
  7. Reference patterns are generated with
  8. a double precision computation.
  9. */
  10. #define ABS_SQRT_ERROR ((q31_t)7)
  11. #define ABS_ERROR ((q31_t)2200)
  12. #define ABS_DIV_ERROR ((q31_t)2)
  13. #define LOG_ABS_ERROR ((q31_t)2)
  14. #define ABS_ATAN_ERROR ((q31_t)3)
  15. void FastMathQ31::test_atan2_scalar_q31()
  16. {
  17. const q31_t *inp = input.ptr();
  18. q31_t *outp = output.ptr();
  19. q31_t res;
  20. unsigned long i;
  21. arm_status status=ARM_MATH_SUCCESS;
  22. for(i=0; i < ref.nbSamples(); i++)
  23. {
  24. status=arm_atan2_q31(inp[2*i],inp[2*i+1],&res);
  25. outp[i]=res;
  26. ASSERT_TRUE((status == ARM_MATH_SUCCESS));
  27. }
  28. ASSERT_SNR(ref,output,(q31_t)SNR_THRESHOLD);
  29. ASSERT_NEAR_EQ(ref,output,ABS_ATAN_ERROR);
  30. }
  31. void FastMathQ31::test_vlog_q31()
  32. {
  33. const q31_t *inp = input.ptr();
  34. q31_t *outp = output.ptr();
  35. arm_vlog_q31(inp,outp,ref.nbSamples());
  36. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  37. ASSERT_NEAR_EQ(ref,output,LOG_ABS_ERROR);
  38. ASSERT_EMPTY_TAIL(output);
  39. }
  40. void FastMathQ31::test_division_q31()
  41. {
  42. const q31_t *nump = numerator.ptr();
  43. const q31_t *denp = denominator.ptr();
  44. q31_t *outp = output.ptr();
  45. int16_t *shiftp = shift.ptr();
  46. arm_status status;
  47. for(unsigned long i=0; i < ref.nbSamples(); i++)
  48. {
  49. status = arm_divide_q31(nump[i],denp[i],&outp[i],&shiftp[i]);
  50. }
  51. (void)status;
  52. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  53. ASSERT_NEAR_EQ(ref,output,ABS_DIV_ERROR);
  54. ASSERT_EQ(refShift,shift);
  55. }
  56. void FastMathQ31::test_cos_q31()
  57. {
  58. const q31_t *inp = input.ptr();
  59. q31_t *outp = output.ptr();
  60. unsigned long i;
  61. for(i=0; i < ref.nbSamples(); i++)
  62. {
  63. outp[i]=arm_cos_q31(inp[i]);
  64. }
  65. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  66. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  67. }
  68. void FastMathQ31::test_sin_q31()
  69. {
  70. const q31_t *inp = input.ptr();
  71. q31_t *outp = output.ptr();
  72. unsigned long i;
  73. for(i=0; i < ref.nbSamples(); i++)
  74. {
  75. outp[i]=arm_sin_q31(inp[i]);
  76. }
  77. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  78. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  79. }
  80. void FastMathQ31::test_sqrt_q31()
  81. {
  82. const q31_t *inp = input.ptr();
  83. q31_t *outp = output.ptr();
  84. arm_status status;
  85. unsigned long i;
  86. for(i=0; i < ref.nbSamples(); i++)
  87. {
  88. status=arm_sqrt_q31(inp[i],&outp[i]);
  89. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] <= 0) && (status == ARM_MATH_ARGUMENT_ERROR)));
  90. }
  91. //ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  92. ASSERT_NEAR_EQ(ref,output,ABS_SQRT_ERROR);
  93. }
  94. void FastMathQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  95. {
  96. (void)paramsArgs;
  97. switch(id)
  98. {
  99. case FastMathQ31::TEST_COS_Q31_1:
  100. {
  101. input.reload(FastMathQ31::ANGLES1_Q31_ID,mgr);
  102. ref.reload(FastMathQ31::COS1_Q31_ID,mgr);
  103. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  104. }
  105. break;
  106. case FastMathQ31::TEST_SIN_Q31_2:
  107. {
  108. input.reload(FastMathQ31::ANGLES1_Q31_ID,mgr);
  109. ref.reload(FastMathQ31::SIN1_Q31_ID,mgr);
  110. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  111. }
  112. break;
  113. case FastMathQ31::TEST_SQRT_Q31_3:
  114. {
  115. input.reload(FastMathQ31::SQRTINPUT1_Q31_ID,mgr);
  116. ref.reload(FastMathQ31::SQRT1_Q31_ID,mgr);
  117. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  118. }
  119. break;
  120. case FastMathQ31::TEST_DIVISION_Q31_4:
  121. {
  122. numerator.reload(FastMathQ31::NUMERATOR_Q31_ID,mgr);
  123. denominator.reload(FastMathQ31::DENOMINATOR_Q31_ID,mgr);
  124. ref.reload(FastMathQ31::DIVISION_VALUE_Q31_ID,mgr);
  125. refShift.reload(FastMathQ31::DIVISION_SHIFT_S16_ID,mgr);
  126. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  127. shift.create(ref.nbSamples(),FastMathQ31::SHIFT_S16_ID,mgr);
  128. }
  129. break;
  130. case FastMathQ31::TEST_VLOG_Q31_5:
  131. {
  132. input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr);
  133. ref.reload(FastMathQ31::LOG1_Q31_ID,mgr);
  134. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  135. }
  136. break;
  137. case FastMathQ31::TEST_VLOG_Q31_6:
  138. {
  139. input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr,3);
  140. ref.reload(FastMathQ31::LOG1_Q31_ID,mgr,3);
  141. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  142. }
  143. break;
  144. case FastMathQ31::TEST_VLOG_Q31_7:
  145. {
  146. input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr,8);
  147. ref.reload(FastMathQ31::LOG1_Q31_ID,mgr,8);
  148. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  149. }
  150. break;
  151. case FastMathQ31::TEST_VLOG_Q31_8:
  152. {
  153. input.reload(FastMathQ31::LOGINPUT1_Q31_ID,mgr,11);
  154. ref.reload(FastMathQ31::LOG1_Q31_ID,mgr,11);
  155. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  156. }
  157. break;
  158. case FastMathQ31::TEST_ATAN2_SCALAR_Q31_9:
  159. {
  160. input.reload(FastMathQ31::ATAN2INPUT1_Q31_ID,mgr);
  161. ref.reload(FastMathQ31::ATAN2_Q31_ID,mgr);
  162. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  163. }
  164. break;
  165. }
  166. }
  167. void FastMathQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  168. {
  169. (void)id;
  170. output.dump(mgr);
  171. }