FastMathQ15.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  23. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  24. ASSERT_EQ(refShift,shift);
  25. }
  26. void FastMathQ15::test_cos_q15()
  27. {
  28. const q15_t *inp = input.ptr();
  29. q15_t *outp = output.ptr();
  30. unsigned long i;
  31. for(i=0; i < ref.nbSamples(); i++)
  32. {
  33. outp[i]=arm_cos_q15(inp[i]);
  34. }
  35. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  36. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  37. }
  38. void FastMathQ15::test_sin_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_sin_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_sqrt_q15()
  51. {
  52. const q15_t *inp = input.ptr();
  53. q15_t *outp = output.ptr();
  54. arm_status status;
  55. unsigned long i;
  56. for(i=0; i < ref.nbSamples(); i++)
  57. {
  58. status=arm_sqrt_q15(inp[i],&outp[i]);
  59. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] <= 0) && (status == ARM_MATH_ARGUMENT_ERROR)));
  60. }
  61. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  62. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  63. }
  64. void FastMathQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  65. {
  66. (void)paramsArgs;
  67. switch(id)
  68. {
  69. case FastMathQ15::TEST_COS_Q15_1:
  70. {
  71. input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr);
  72. ref.reload(FastMathQ15::COS1_Q15_ID,mgr);
  73. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  74. }
  75. break;
  76. case FastMathQ15::TEST_SIN_Q15_2:
  77. {
  78. input.reload(FastMathQ15::ANGLES1_Q15_ID,mgr);
  79. ref.reload(FastMathQ15::SIN1_Q15_ID,mgr);
  80. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  81. }
  82. break;
  83. case FastMathQ15::TEST_SQRT_Q15_3:
  84. {
  85. input.reload(FastMathQ15::SQRTINPUT1_Q15_ID,mgr);
  86. ref.reload(FastMathQ15::SQRT1_Q15_ID,mgr);
  87. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  88. }
  89. break;
  90. case FastMathQ15::TEST_DIVISION_Q15_4:
  91. {
  92. numerator.reload(FastMathQ15::NUMERATOR_Q15_ID,mgr);
  93. denominator.reload(FastMathQ15::DENOMINATOR_Q15_ID,mgr);
  94. ref.reload(FastMathQ15::DIVISION_VALUE_Q15_ID,mgr);
  95. refShift.reload(FastMathQ15::DIVISION_SHIFT_S16_ID,mgr);
  96. output.create(ref.nbSamples(),FastMathQ15::OUT_Q15_ID,mgr);
  97. shift.create(ref.nbSamples(),FastMathQ15::SHIFT_S16_ID,mgr);
  98. }
  99. break;
  100. }
  101. }
  102. void FastMathQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  103. {
  104. (void)id;
  105. output.dump(mgr);
  106. }