FastMathQ15.cpp 3.7 KB

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