FastMathQ31.cpp 5.3 KB

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