FastMathQ31.cpp 7.1 KB

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