FastMathQ15.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #include "FastMathQ15.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "Test.h"
  5. #define SNR_THRESHOLD 69
  6. /*
  7. Reference patterns are generated with
  8. a double precision computation.
  9. */
  10. #define ABS_SQRT_ERROR ((q15_t)6)
  11. #define ABS_ERROR ((q15_t)10)
  12. #define LOG_ABS_ERROR ((q15_t)3)
  13. void FastMathQ15::test_vlog_q15()
  14. {
  15. const q15_t *inp = input.ptr();
  16. q15_t *outp = output.ptr();
  17. arm_vlog_q15(inp,outp,ref.nbSamples());
  18. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  19. ASSERT_NEAR_EQ(ref,output,LOG_ABS_ERROR);
  20. ASSERT_EMPTY_TAIL(output);
  21. }
  22. void FastMathQ15::test_division_q15()
  23. {
  24. const q15_t *nump = numerator.ptr();
  25. const q15_t *denp = denominator.ptr();
  26. q15_t *outp = output.ptr();
  27. int16_t *shiftp = shift.ptr();
  28. arm_status status;
  29. for(unsigned long i=0; i < ref.nbSamples(); i++)
  30. {
  31. status = arm_divide_q15(nump[i],denp[i],&outp[i],&shiftp[i]);
  32. }
  33. (void)status;
  34. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  35. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  36. ASSERT_EQ(refShift,shift);
  37. }
  38. void FastMathQ15::test_cos_q15()
  39. {
  40. const q15_t *inp = input.ptr();
  41. q15_t *outp = output.ptr();
  42. unsigned long i;
  43. for(i=0; i < ref.nbSamples(); i++)
  44. {
  45. outp[i]=arm_cos_q15(inp[i]);
  46. }
  47. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  48. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  49. }
  50. void FastMathQ15::test_sin_q15()
  51. {
  52. const q15_t *inp = input.ptr();
  53. q15_t *outp = output.ptr();
  54. unsigned long i;
  55. for(i=0; i < ref.nbSamples(); i++)
  56. {
  57. outp[i]=arm_sin_q15(inp[i]);
  58. }
  59. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  60. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  61. }
  62. void FastMathQ15::test_sqrt_q15()
  63. {
  64. const q15_t *inp = input.ptr();
  65. q15_t *outp = output.ptr();
  66. arm_status status;
  67. unsigned long i;
  68. for(i=0; i < ref.nbSamples(); i++)
  69. {
  70. status=arm_sqrt_q15(inp[i],&outp[i]);
  71. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] <= 0) && (status == ARM_MATH_ARGUMENT_ERROR)));
  72. }
  73. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  74. ASSERT_NEAR_EQ(ref,output,ABS_SQRT_ERROR);
  75. }
  76. void FastMathQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  77. {
  78. (void)paramsArgs;
  79. switch(id)
  80. {
  81. case FastMathQ15::TEST_COS_Q15_1:
  82. {
  83. input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr);
  84. ref.reload(FastMathQ15::COS1_Q15_ID,mgr);
  85. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  86. }
  87. break;
  88. case FastMathQ15::TEST_SIN_Q15_2:
  89. {
  90. input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr);
  91. ref.reload(FastMathQ15::SIN1_Q15_ID,mgr);
  92. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  93. }
  94. break;
  95. case FastMathQ15::TEST_SQRT_Q15_3:
  96. {
  97. input.reload(FastMathQ15::SQRTINPUT1_Q15_ID,mgr);
  98. ref.reload(FastMathQ15::SQRT1_Q15_ID,mgr);
  99. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  100. }
  101. break;
  102. case FastMathQ15::TEST_DIVISION_Q15_4:
  103. {
  104. numerator.reload(FastMathQ15::NUMERATOR_Q15_ID,mgr);
  105. denominator.reload(FastMathQ15::DENOMINATOR_Q15_ID,mgr);
  106. ref.reload(FastMathQ15::DIVISION_VALUE_Q15_ID,mgr);
  107. refShift.reload(FastMathQ15::DIVISION_SHIFT_S16_ID,mgr);
  108. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  109. shift.create(ref.nbSamples(),FastMathQ15::SHIFT_S16_ID,mgr);
  110. }
  111. break;
  112. case FastMathQ15::TEST_VLOG_Q15_5:
  113. {
  114. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr);
  115. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr);
  116. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  117. }
  118. break;
  119. case FastMathQ15::TEST_VLOG_Q15_6:
  120. {
  121. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,7);
  122. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,7);
  123. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  124. }
  125. break;
  126. case FastMathQ15::TEST_VLOG_Q15_7:
  127. {
  128. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,16);
  129. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,16);
  130. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  131. }
  132. break;
  133. case FastMathQ15::TEST_VLOG_Q15_8:
  134. {
  135. input.reload(FastMathQ15::LOGINPUT1_Q15_ID,mgr,23);
  136. ref.reload(FastMathQ15::LOG1_Q15_ID,mgr,23);
  137. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  138. }
  139. break;
  140. }
  141. }
  142. void FastMathQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  143. {
  144. (void)id;
  145. output.dump(mgr);
  146. }