ref_common.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef __REF_COMMON_H__
  2. #define __REF_COMMON_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <riscv_math.h>
  7. #include <stdint.h>
  8. #include <stdlib.h>
  9. /**
  10. * @brief Error status returned by some functions in the library.
  11. */
  12. typedef enum {
  13. REF_Q7 = 0,
  14. REF_Q15,
  15. REF_Q31,
  16. REF_F32,
  17. } dataType;
  18. #ifndef FLT_MAX
  19. #define FLT_MAX 3.40282347e+38F
  20. #endif
  21. #ifndef DBL_MAX
  22. #define DBL_MAX 1.79769313486231571e+308
  23. #endif
  24. #ifndef FLT_MIN
  25. #define FLT_MIN 1.175494351e-38F
  26. #endif
  27. #ifndef DBL_MIN
  28. #define DBL_MIN 2.22507385850720138e-308
  29. #endif
  30. #ifndef SCHAR_MIN
  31. #define SCHAR_MIN (-128)
  32. /* mimimum value for an object of type signed char */
  33. #define SCHAR_MAX 127
  34. /* maximum value for an object of type signed char */
  35. #define UCHAR_MAX 255
  36. /* maximum value for an object of type unsigned char */
  37. #define SHRT_MIN (-0x8000)
  38. /* minimum value for an object of type short int */
  39. #define SHRT_MAX 0x7fff
  40. /* maximum value for an object of type short int */
  41. #define USHRT_MAX 65535
  42. /* maximum value for an object of type unsigned short int */
  43. #define INT_MIN (~0x7fffffff) /* -2147483648 and 0x80000000 are unsigned */
  44. /* minimum value for an object of type int */
  45. #define INT_MAX 0x7fffffff
  46. /* maximum value for an object of type int */
  47. #define UINT_MAX 0xffffffffU
  48. /* maximum value for an object of type unsigned int */
  49. #define LONG_MIN (~0x7fffffffL)
  50. /* minimum value for an object of type long int */
  51. #define LONG_MAX 0x7fffffffL
  52. /* maximum value for an object of type long int */
  53. #define ULONG_MAX 0xffffffffUL
  54. /* maximum value for an object of type unsigned long int */
  55. #endif
  56. /*
  57. * Helper Functions
  58. */
  59. q31_t ref_sat_n(q31_t num, uint32_t bits);
  60. q31_t ref_sat_q31(q63_t num);
  61. q15_t ref_sat_q15(q31_t num);
  62. q7_t ref_sat_q7(q15_t num);
  63. float32_t ref_pow(float32_t a, uint32_t b);
  64. float32_t ref_detrm(float32_t* pSrc, float32_t* temp, uint32_t size);
  65. void ref_cofact(float32_t* pSrc, float32_t* pDst, float32_t* temp,
  66. uint32_t size);
  67. float64_t ref_detrm64(float64_t* pSrc, float64_t* temp, uint32_t size);
  68. void ref_cofact64(float64_t* pSrc, float64_t* pDst, float64_t* temp,
  69. uint32_t size);
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif /** __REF_COMMON_H__ */