arm_math_memory.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. */
  93. __STATIC_FORCEINLINE void write_q15x2_ia (
  94. q15_t ** pQ15,
  95. q31_t value)
  96. {
  97. q31_t val = value;
  98. #ifdef __ARM_FEATURE_UNALIGNED
  99. memcpy (*pQ15, &val, 4);
  100. #else
  101. (*pQ15)[0] = (q15_t)(val & 0x0FFFF);
  102. (*pQ15)[1] = (q15_t)((val >> 16) & 0x0FFFF);
  103. #endif
  104. *pQ15 += 2;
  105. }
  106. /**
  107. @brief Write 2 Q15 to Q15 pointer.
  108. @param[in] pQ15 points to input value
  109. @param[in] value Q31 value
  110. */
  111. __STATIC_FORCEINLINE void write_q15x2 (
  112. q15_t * pQ15,
  113. q31_t value)
  114. {
  115. q31_t val = value;
  116. #ifdef __ARM_FEATURE_UNALIGNED
  117. memcpy (pQ15, &val, 4);
  118. #else
  119. pQ15[0] = (q15_t)(val & 0x0FFFF);
  120. pQ15[1] = (q15_t)(val >> 16);
  121. #endif
  122. }
  123. /**
  124. @brief Read 4 Q7 from Q7 pointer
  125. @param[in] pQ7 points to input value
  126. @return Q31 value
  127. */
  128. __STATIC_FORCEINLINE q31_t read_q7x4 (
  129. q7_t const * pQ7)
  130. {
  131. q31_t val;
  132. #ifdef __ARM_FEATURE_UNALIGNED
  133. memcpy (&val, pQ7, 4);
  134. #else
  135. val =((pQ7[3] & 0x0FF) << 24) | ((pQ7[2] & 0x0FF) << 16) | ((pQ7[1] & 0x0FF) << 8) | (pQ7[0] & 0x0FF);
  136. #endif
  137. return (val);
  138. }
  139. /**
  140. @brief Read 4 Q7 from Q7 pointer and increment pointer afterwards.
  141. @param[in] pQ7 points to input value
  142. @return Q31 value
  143. */
  144. #define read_q7x4_ia(pQ7) read_q7x4((*(pQ7) += 4) - 4)
  145. /**
  146. @brief Read 4 Q7 from Q7 pointer and decrement pointer afterwards.
  147. @param[in] pQ7 points to input value
  148. @return Q31 value
  149. */
  150. #define read_q7x4_da(pQ7) read_q7x4((*(pQ7) -= 4) + 4)
  151. /**
  152. @brief Write 4 Q7 to Q7 pointer and increment pointer afterwards.
  153. @param[in] pQ7 points to input value
  154. @param[in] value Q31 value
  155. */
  156. __STATIC_FORCEINLINE void write_q7x4_ia (
  157. q7_t ** pQ7,
  158. q31_t value)
  159. {
  160. q31_t val = value;
  161. #ifdef __ARM_FEATURE_UNALIGNED
  162. memcpy (*pQ7, &val, 4);
  163. #else
  164. (*pQ7)[0] = (q7_t)(val & 0x0FF);
  165. (*pQ7)[1] = (q7_t)((val >> 8) & 0x0FF);
  166. (*pQ7)[2] = (q7_t)((val >> 16) & 0x0FF);
  167. (*pQ7)[3] = (q7_t)((val >> 24) & 0x0FF);
  168. #endif
  169. *pQ7 += 4;
  170. }
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif /*ifndef _ARM_MATH_MEMORY_H_ */