FastMathQ31.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_ERROR ((q31_t)2200)
  11. void FastMathQ31::test_cos_q31()
  12. {
  13. const q31_t *inp = input.ptr();
  14. q31_t *outp = output.ptr();
  15. unsigned long i;
  16. for(i=0; i < ref.nbSamples(); i++)
  17. {
  18. outp[i]=arm_cos_q31(inp[i]);
  19. }
  20. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  21. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  22. }
  23. void FastMathQ31::test_sin_q31()
  24. {
  25. const q31_t *inp = input.ptr();
  26. q31_t *outp = output.ptr();
  27. unsigned long i;
  28. for(i=0; i < ref.nbSamples(); i++)
  29. {
  30. outp[i]=arm_sin_q31(inp[i]);
  31. }
  32. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  33. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  34. }
  35. void FastMathQ31::test_sqrt_q31()
  36. {
  37. const q31_t *inp = input.ptr();
  38. q31_t *outp = output.ptr();
  39. arm_status status;
  40. unsigned long i;
  41. for(i=0; i < ref.nbSamples(); i++)
  42. {
  43. status=arm_sqrt_q31(inp[i],&outp[i]);
  44. ASSERT_TRUE((status == ARM_MATH_SUCCESS) || ((inp[i] <= 0) && (status == ARM_MATH_ARGUMENT_ERROR)));
  45. }
  46. ASSERT_SNR(ref,output,(float32_t)SNR_THRESHOLD);
  47. ASSERT_NEAR_EQ(ref,output,ABS_ERROR);
  48. }
  49. void FastMathQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  50. {
  51. (void)paramsArgs;
  52. switch(id)
  53. {
  54. case FastMathQ31::TEST_COS_Q31_1:
  55. {
  56. input.reload(FastMathQ31::ANGLES1_Q31_ID,mgr);
  57. ref.reload(FastMathQ31::COS1_Q31_ID,mgr);
  58. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  59. }
  60. break;
  61. case FastMathQ31::TEST_SIN_Q31_2:
  62. {
  63. input.reload(FastMathQ31::ANGLES1_Q31_ID,mgr);
  64. ref.reload(FastMathQ31::SIN1_Q31_ID,mgr);
  65. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  66. }
  67. break;
  68. case FastMathQ31::TEST_SQRT_Q31_3:
  69. {
  70. input.reload(FastMathQ31::SQRTINPUT1_Q31_ID,mgr);
  71. ref.reload(FastMathQ31::SQRT1_Q31_ID,mgr);
  72. output.create(ref.nbSamples(),FastMathQ31::OUT_Q31_ID,mgr);
  73. }
  74. break;
  75. }
  76. }
  77. void FastMathQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  78. {
  79. (void)id;
  80. output.dump(mgr);
  81. }