arm_math_memory.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /******************************************************************************
  2. * @file arm_math_memory.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2021 Arm Limited or its affiliates. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef _ARM_MATH_MEMORY_H_
  26. #define _ARM_MATH_MEMORY_H_
  27. #include "arm_math_types.h"
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #endif
  32. /**
  33. @brief definition to read/write two 16 bit values.
  34. @deprecated
  35. */
  36. #if defined ( __CC_ARM )
  37. #define __SIMD32_TYPE int32_t __packed
  38. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  39. #define __SIMD32_TYPE int32_t
  40. #elif defined ( __GNUC__ )
  41. #define __SIMD32_TYPE int32_t
  42. #elif defined ( __ICCARM__ )
  43. #define __SIMD32_TYPE int32_t __packed
  44. #elif defined ( __TI_ARM__ )
  45. #define __SIMD32_TYPE int32_t
  46. #elif defined ( __CSMC__ )
  47. #define __SIMD32_TYPE int32_t
  48. #elif defined ( __TASKING__ )
  49. #define __SIMD32_TYPE __un(aligned) int32_t
  50. #elif defined(_MSC_VER )
  51. #define __SIMD32_TYPE int32_t
  52. #else
  53. #error Unknown compiler
  54. #endif
  55. #define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr))
  56. #define __SIMD32_CONST(addr) ( (__SIMD32_TYPE * ) (addr))
  57. #define _SIMD32_OFFSET(addr) (*(__SIMD32_TYPE * ) (addr))
  58. #define __SIMD64(addr) (*( int64_t **) & (addr))
  59. /* SIMD replacement */
  60. /**
  61. @brief Read 2 Q15 from Q15 pointer.
  62. @param[in] pQ15 points to input value
  63. @return Q31 value
  64. */
  65. __STATIC_FORCEINLINE q31_t read_q15x2 (
  66. q15_t const * pQ15)
  67. {
  68. q31_t val;
  69. #ifdef __ARM_FEATURE_UNALIGNED
  70. memcpy (&val, pQ15, 4);
  71. #else
  72. val = (pQ15[1] << 16) | (pQ15[0] & 0x0FFFF) ;
  73. #endif
  74. return (val);
  75. }
  76. /**
  77. @brief Read 2 Q15 from Q15 pointer and increment pointer afterwards.
  78. @param[in] pQ15 points to input value
  79. @return Q31 value
  80. */
  81. #define read_q15x2_ia(pQ15) read_q15x2((*(pQ15) += 2) - 2)
  82. /**
  83. @brief Read 2 Q15 from Q15 pointer and decrement pointer afterwards.
  84. @param[in] pQ15 points to input value
  85. @return Q31 value
  86. */
  87. #define read_q15x2_da(pQ15) read_q15x2((*(pQ15) -= 2) + 2)
  88. /**
  89. @brief Write 2 Q15 to Q15 pointer and increment pointer afterwards.
  90. @param[in] pQ15 points to input value
  91. @param[in] value Q31 value
  92. @return none
  93. */
  94. __STATIC_FORCEINLINE void write_q15x2_ia (
  95. q15_t ** pQ15,
  96. q31_t value)
  97. {
  98. q31_t val = value;
  99. #ifdef __ARM_FEATURE_UNALIGNED
  100. memcpy (*pQ15, &val, 4);
  101. #else
  102. (*pQ15)[0] = (q15_t)(val & 0x0FFFF);
  103. (*pQ15)[1] = (q15_t)((val >> 16) & 0x0FFFF);
  104. #endif
  105. *pQ15 += 2;
  106. }
  107. /**
  108. @brief Write 2 Q15 to Q15 pointer.
  109. @param[in] pQ15 points to input value
  110. @param[in] value Q31 value
  111. @return none
  112. */
  113. __STATIC_FORCEINLINE void write_q15x2 (
  114. q15_t * pQ15,
  115. q31_t value)
  116. {
  117. q31_t val = value;
  118. #ifdef __ARM_FEATURE_UNALIGNED
  119. memcpy (pQ15, &val, 4);
  120. #else
  121. pQ15[0] = (q15_t)(val & 0x0FFFF);
  122. pQ15[1] = (q15_t)(val >> 16);
  123. #endif
  124. }
  125. /**
  126. @brief Read 4 Q7 from Q7 pointer
  127. @param[in] pQ7 points to input value
  128. @return Q31 value
  129. */
  130. __STATIC_FORCEINLINE q31_t read_q7x4 (
  131. q7_t const * pQ7)
  132. {
  133. q31_t val;
  134. #ifdef __ARM_FEATURE_UNALIGNED
  135. memcpy (&val, pQ7, 4);
  136. #else
  137. val =((pQ7[3] & 0x0FF) << 24) | ((pQ7[2] & 0x0FF) << 16) | ((pQ7[1] & 0x0FF) << 8) | (pQ7[0] & 0x0FF);
  138. #endif
  139. return (val);
  140. }
  141. /**
  142. @brief Read 4 Q7 from Q7 pointer and increment pointer afterwards.
  143. @param[in] pQ7 points to input value
  144. @return Q31 value
  145. */
  146. #define read_q7x4_ia(pQ7) read_q7x4((*(pQ7) += 4) - 4)
  147. /**
  148. @brief Read 4 Q7 from Q7 pointer and decrement pointer afterwards.
  149. @param[in] pQ7 points to input value
  150. @return Q31 value
  151. */
  152. #define read_q7x4_da(pQ7) read_q7x4((*(pQ7) -= 4) + 4)
  153. /**
  154. @brief Write 4 Q7 to Q7 pointer and increment pointer afterwards.
  155. @param[in] pQ7 points to input value
  156. @param[in] value Q31 value
  157. @return none
  158. */
  159. __STATIC_FORCEINLINE void write_q7x4_ia (
  160. q7_t ** pQ7,
  161. q31_t value)
  162. {
  163. q31_t val = value;
  164. #ifdef __ARM_FEATURE_UNALIGNED
  165. memcpy (*pQ7, &val, 4);
  166. #else
  167. (*pQ7)[0] = (q7_t)(val & 0x0FF);
  168. (*pQ7)[1] = (q7_t)((val >> 8) & 0x0FF);
  169. (*pQ7)[2] = (q7_t)((val >> 16) & 0x0FF);
  170. (*pQ7)[3] = (q7_t)((val >> 24) & 0x0FF);
  171. #endif
  172. *pQ7 += 4;
  173. }
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif /*ifndef _ARM_MATH_MEMORY_H_ */