FastMathQ15.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #include "FastMathQ15.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 69
  8. /*
  9. Reference patterns are generated with
  10. a double precision computation.
  11. */
  12. #define ABS_SQRT_ERROR ((q15_t)6)
  13. #define ABS_ERROR ((q15_t)10)
  14. #define LOG_ABS_ERROR ((q15_t)3)
  15. #define ABS_ATAN_ERROR ((q15_t)3)
  16. #define DIV_ERROR ((q15_t)2)
  17. #define RECIP_ERROR ((q15_t)2)
  18. void FastMathQ15::test_vlog_q15()
  19. {
  20. const q15_t *inp = input.ptr();
  21. q15_t *outp = output.ptr();
  22. arm_vlog_q15(inp,outp,ref.nbSamples());
  23. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  24. ASSERT_NEAR_EQ(ref,output,LOG_ABS_ERROR);
  25. ASSERT_EMPTY_TAIL(output);
  26. }
  27. void FastMathQ15::test_atan2_scalar_q15()
  28. {
  29. const q15_t *inp = input.ptr();
  30. q15_t *outp = output.ptr();
  31. q15_t res;
  32. unsigned long i;
  33. arm_status status=ARM_MATH_SUCCESS;
  34. for(i=0; i < ref.nbSamples(); i++)
  35. {
  36. status=arm_atan2_q15(inp[2*i],inp[2*i+1],&res);
  37. outp[i]=res;
  38. ASSERT_TRUE((status == ARM_MATH_SUCCESS));
  39. }
  40. ASSERT_SNR(ref,output,(q15_t)SNR_THRESHOLD);
  41. ASSERT_NEAR_EQ(ref,output,ABS_ATAN_ERROR);
  42. }
  43. void FastMathQ15::test_division_q15()
  44. {
  45. const q15_t *nump = numerator.ptr();
  46. const q15_t *denp = denominator.ptr();
  47. q15_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_q15(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,DIV_ERROR);
  57. ASSERT_EQ(refShift,shift);
  58. }
  59. void FastMathQ15::test_cos_q15()
  60. {
  61. const q15_t *inp = input.ptr();
  62. q15_t *outp = output.ptr();
  63. unsigned long i;
  64. for(i=0; i < ref.nbSamples(); i++)
  65. {
  66. outp[i]=arm_cos_q15(inp[i]);
  67. }
  68. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  69. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  70. }
  71. void FastMathQ15::test_sin_q15()
  72. {
  73. const q15_t *inp = input.ptr();
  74. q15_t *outp = output.ptr();
  75. unsigned long i;
  76. for(i=0; i < ref.nbSamples(); i++)
  77. {
  78. outp[i]=arm_sin_q15(inp[i]);
  79. }
  80. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  81. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  82. }
  83. void FastMathQ15::test_sqrt_q15()
  84. {
  85. const q15_t *inp = input.ptr();
  86. q15_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_q15(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 FastMathQ15::test_recip_q15()
  98. {
  99. const q15_t *inp = input.ptr();
  100. q15_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_q15(inp[i],&outp[i],armRecipTableQ15);
  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 FastMathQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  111. {
  112. (void)paramsArgs;
  113. switch(id)
  114. {
  115. case FastMathQ15::TEST_COS_Q15_1:
  116. {
  117. input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr);
  118. ref.reload(FastMathQ15::COS1_Q15_ID,mgr);
  119. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  120. }
  121. break;
  122. case FastMathQ15::TEST_SIN_Q15_2:
  123. {
  124. input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr);
  125. ref.reload(FastMathQ15::SIN1_Q15_ID,mgr);
  126. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  127. }
  128. break;
  129. case FastMathQ15::TEST_SQRT_Q15_3:
  130. {
  131. input.reload(FastMathQ15::SQRTINPUT1_Q15_ID,mgr);
  132. ref.reload(FastMathQ15::SQRT1_Q15_ID,mgr);
  133. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  134. }
  135. break;
  136. case FastMathQ15::TEST_DIVISION_Q15_4:
  137. {
  138. numerator.reload(FastMathQ15::NUMERATOR_Q15_ID,mgr);
  139. denominator.reload(FastMathQ15::DENOMINATOR_Q15_ID,mgr);
  140. ref.reload(FastMathQ15::DIVISION_VALUE_Q15_ID,mgr);
  141. refShift.reload(FastMathQ15::DIVISION_SHIFT_S16_ID,mgr);
  142. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  143. shift.create(ref.nbSamples(),FastMathQ15::SHIFT_S16_ID,mgr);
  144. }
  145. break;
  146. case FastMathQ15::TEST_VLOG_Q15_5:
  147. {
  148. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr);
  149. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr);
  150. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  151. }
  152. break;
  153. case FastMathQ15::TEST_VLOG_Q15_6:
  154. {
  155. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,7);
  156. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,7);
  157. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  158. }
  159. break;
  160. case FastMathQ15::TEST_VLOG_Q15_7:
  161. {
  162. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,16);
  163. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,16);
  164. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  165. }
  166. break;
  167. case FastMathQ15::TEST_VLOG_Q15_8:
  168. {
  169. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,23);
  170. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,23);
  171. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  172. }
  173. break;
  174. case FastMathQ15::TEST_ATAN2_SCALAR_Q15_9:
  175. {
  176. input.reload(FastMathQ15::ATAN2INPUT1_Q15_ID,mgr);
  177. ref.reload(FastMathQ15::ATAN2_Q15_ID,mgr);
  178. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  179. }
  180. break;
  181. case FastMathQ15::TEST_RECIP_Q15_10:
  182. {
  183. input.reload(FastMathQ15::RECIPINPUT1_Q15_ID,mgr);
  184. ref.reload(FastMathQ15::RECIP_VAL_Q15_ID,mgr);
  185. refShift.reload(FastMathQ15::RECIP_SHIFT_S16_ID,mgr);
  186. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  187. shift.create(ref.nbSamples(),FastMathQ15::SHIFT_S16_ID,mgr);
  188. }
  189. break;
  190. }
  191. }
  192. void FastMathQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  193. {
  194. (void)id;
  195. output.dump(mgr);
  196. }