The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

508 lines
38KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. namespace dsp
  22. {
  23. #ifndef DOXYGEN
  24. #if JUCE_GCC && (__GNUC__ >= 6)
  25. #pragma GCC diagnostic push
  26. #pragma GCC diagnostic ignored "-Wignored-attributes"
  27. #endif
  28. #ifdef _MSC_VER
  29. #define DECLARE_NEON_SIMD_CONST(type, name) \
  30. static __declspec(align(16)) const type name [16 / sizeof (type)]
  31. #define DEFINE_NEON_SIMD_CONST(type, class_type, name) \
  32. __declspec(align(16)) const type SIMDNativeOps<class_type>:: name [16 / sizeof (type)]
  33. #else
  34. #define DECLARE_NEON_SIMD_CONST(type, name) \
  35. static const type name [16 / sizeof (type)] __attribute__((aligned(16)))
  36. #define DEFINE_NEON_SIMD_CONST(type, class_type, name) \
  37. const type SIMDNativeOps<class_type>:: name [16 / sizeof (type)] __attribute__((aligned(16)))
  38. #endif
  39. template <typename type>
  40. struct SIMDNativeOps;
  41. //==============================================================================
  42. /** Unsigned 32-bit integer NEON intrinsics.
  43. @tags{DSP}
  44. */
  45. template <>
  46. struct SIMDNativeOps<uint32_t>
  47. {
  48. //==============================================================================
  49. using vSIMDType = uint32x4_t;
  50. using fb = SIMDFallbackOps<uint32_t, vSIMDType>;
  51. //==============================================================================
  52. DECLARE_NEON_SIMD_CONST (uint32_t, kAllBitsSet);
  53. //==============================================================================
  54. static forcedinline vSIMDType expand (uint32_t s) noexcept { return vdupq_n_u32 (s); }
  55. static forcedinline vSIMDType load (const uint32_t* a) noexcept { return vld1q_u32 (a); }
  56. static forcedinline void store (vSIMDType value, uint32_t* a) noexcept { vst1q_u32 (a, value); }
  57. static forcedinline uint32_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  58. static forcedinline vSIMDType set (vSIMDType v, size_t i, uint32_t s) noexcept { v[i] = s; return v; }
  59. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_u32 (a, b); }
  60. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_u32 (a, b); }
  61. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_u32 (a, b); }
  62. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_u32 (a, b); }
  63. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_u32 (a, b); }
  64. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_u32 (a, b); }
  65. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_u32 (b, a); }
  66. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_u32 ((uint32_t*) kAllBitsSet)); }
  67. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_u32 (a, b); }
  68. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_u32 (a, b); }
  69. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_u32 (a, b); }
  70. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (sum (notEqual (a, b)) == 0); }
  71. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  72. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_u32 (a, b); }
  73. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_u32 (a, b); }
  74. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_u32 (a, b, c); }
  75. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  76. static forcedinline uint32_t sum (vSIMDType a) noexcept
  77. {
  78. auto rr = vadd_u32 (vget_high_u32 (a), vget_low_u32 (a));
  79. return vget_lane_u32 (vpadd_u32 (rr, rr), 0);
  80. }
  81. };
  82. //==============================================================================
  83. /** Signed 32-bit integer NEON intrinsics.
  84. @tags{DSP}
  85. */
  86. template <>
  87. struct SIMDNativeOps<int32_t>
  88. {
  89. //==============================================================================
  90. using vSIMDType = int32x4_t;
  91. using fb = SIMDFallbackOps<int32_t, vSIMDType>;
  92. //==============================================================================
  93. DECLARE_NEON_SIMD_CONST (int32_t, kAllBitsSet);
  94. //==============================================================================
  95. static forcedinline vSIMDType expand (int32_t s) noexcept { return vdupq_n_s32 (s); }
  96. static forcedinline vSIMDType load (const int32_t* a) noexcept { return vld1q_s32 (a); }
  97. static forcedinline void store (vSIMDType value, int32_t* a) noexcept { vst1q_s32 (a, value); }
  98. static forcedinline int32_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  99. static forcedinline vSIMDType set (vSIMDType v, size_t i, int32_t s) noexcept { v[i] = s; return v; }
  100. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_s32 (a, b); }
  101. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_s32 (a, b); }
  102. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_s32 (a, b); }
  103. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_s32 (a, b); }
  104. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_s32 (a, b); }
  105. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_s32 (a, b); }
  106. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_s32 (b, a); }
  107. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_s32 ((int32_t*) kAllBitsSet)); }
  108. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_s32 (a, b); }
  109. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_s32 (a, b); }
  110. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_s32 (a, b); }
  111. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (sum (notEqual (a, b)) == 0); }
  112. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  113. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_s32 (a, b); }
  114. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_s32 (a, b); }
  115. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_s32 (a, b, c); }
  116. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  117. static forcedinline int32_t sum (vSIMDType a) noexcept
  118. {
  119. auto rr = vadd_s32 (vget_high_s32 (a), vget_low_s32 (a));
  120. rr = vpadd_s32 (rr, rr);
  121. return vget_lane_s32 (rr, 0);
  122. }
  123. };
  124. //==============================================================================
  125. /** Signed 8-bit integer NEON intrinsics.
  126. @tags{DSP}
  127. */
  128. template <>
  129. struct SIMDNativeOps<int8_t>
  130. {
  131. //==============================================================================
  132. using vSIMDType = int8x16_t;
  133. using fb = SIMDFallbackOps<int8_t, vSIMDType>;
  134. //==============================================================================
  135. DECLARE_NEON_SIMD_CONST (int8_t, kAllBitsSet);
  136. //==============================================================================
  137. static forcedinline vSIMDType expand (int8_t s) noexcept { return vdupq_n_s8 (s); }
  138. static forcedinline vSIMDType load (const int8_t* a) noexcept { return vld1q_s8 (a); }
  139. static forcedinline void store (vSIMDType value, int8_t* a) noexcept { vst1q_s8 (a, value); }
  140. static forcedinline int8_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  141. static forcedinline vSIMDType set (vSIMDType v, size_t i, int8_t s) noexcept { v[i] = s; return v; }
  142. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_s8 (a, b); }
  143. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_s8 (a, b); }
  144. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_s8 (a, b); }
  145. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_s8 (a, b); }
  146. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_s8 (a, b); }
  147. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_s8 (a, b); }
  148. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_s8 (b, a); }
  149. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_s8 ((int8_t*) kAllBitsSet)); }
  150. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_s8 (a, b); }
  151. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_s8 (a, b); }
  152. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_s8 (a, b); }
  153. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  154. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_s8 (a, b); }
  155. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_s8 (a, b); }
  156. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<int32_t>::sum ((SIMDNativeOps<int32_t>::vSIMDType) notEqual (a, b)) == 0); }
  157. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_s8 (a, b, c); }
  158. static forcedinline int8_t sum (vSIMDType a) noexcept { return fb::sum (a); }
  159. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  160. };
  161. //==============================================================================
  162. /** Unsigned 8-bit integer NEON intrinsics.
  163. @tags{DSP}
  164. */
  165. template <>
  166. struct SIMDNativeOps<uint8_t>
  167. {
  168. //==============================================================================
  169. using vSIMDType = uint8x16_t;
  170. using fb = SIMDFallbackOps<uint8_t, vSIMDType>;
  171. //==============================================================================
  172. DECLARE_NEON_SIMD_CONST (uint8_t, kAllBitsSet);
  173. //==============================================================================
  174. static forcedinline vSIMDType expand (uint8_t s) noexcept { return vdupq_n_u8 (s); }
  175. static forcedinline vSIMDType load (const uint8_t* a) noexcept { return vld1q_u8 (a); }
  176. static forcedinline void store (vSIMDType value, uint8_t* a) noexcept { vst1q_u8 (a, value); }
  177. static forcedinline uint8_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  178. static forcedinline vSIMDType set (vSIMDType v, size_t i, uint8_t s) noexcept { v[i] = s; return v; }
  179. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_u8 (a, b); }
  180. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_u8 (a, b); }
  181. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_u8 (a, b); }
  182. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_u8 (a, b); }
  183. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_u8 (a, b); }
  184. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_u8 (a, b); }
  185. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_u8 (b, a); }
  186. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_u8 ((uint8_t*) kAllBitsSet)); }
  187. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_u8 (a, b); }
  188. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_u8 (a, b); }
  189. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_u8 (a, b); }
  190. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  191. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_u8 (a, b); }
  192. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_u8 (a, b); }
  193. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<uint32_t>::sum ((SIMDNativeOps<uint32_t>::vSIMDType) notEqual (a, b)) == 0); }
  194. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_u8 (a, b, c); }
  195. static forcedinline uint8_t sum (vSIMDType a) noexcept { return fb::sum (a); }
  196. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  197. };
  198. //==============================================================================
  199. /** Signed 16-bit integer NEON intrinsics.
  200. @tags{DSP}
  201. */
  202. template <>
  203. struct SIMDNativeOps<int16_t>
  204. {
  205. //==============================================================================
  206. using vSIMDType = int16x8_t;
  207. using fb = SIMDFallbackOps<int16_t, vSIMDType>;
  208. //==============================================================================
  209. DECLARE_NEON_SIMD_CONST (int16_t, kAllBitsSet);
  210. //==============================================================================
  211. static forcedinline vSIMDType expand (int16_t s) noexcept { return vdupq_n_s16 (s); }
  212. static forcedinline vSIMDType load (const int16_t* a) noexcept { return vld1q_s16 (a); }
  213. static forcedinline void store (vSIMDType value, int16_t* a) noexcept { vst1q_s16 (a, value); }
  214. static forcedinline int16_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  215. static forcedinline vSIMDType set (vSIMDType v, size_t i, int16_t s) noexcept { v[i] = s; return v; }
  216. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_s16 (a, b); }
  217. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_s16 (a, b); }
  218. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_s16 (a, b); }
  219. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_s16 (a, b); }
  220. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_s16 (a, b); }
  221. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_s16 (a, b); }
  222. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_s16 (b, a); }
  223. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_s16 ((int16_t*) kAllBitsSet)); }
  224. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_s16 (a, b); }
  225. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_s16 (a, b); }
  226. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_s16 (a, b); }
  227. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  228. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_s16 (a, b); }
  229. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_s16 (a, b); }
  230. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<int32_t>::sum ((SIMDNativeOps<int32_t>::vSIMDType) notEqual (a, b)) == 0); }
  231. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_s16 (a, b, c); }
  232. static forcedinline int16_t sum (vSIMDType a) noexcept { return fb::sum (a); }
  233. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  234. };
  235. //==============================================================================
  236. /** Unsigned 16-bit integer NEON intrinsics.
  237. @tags{DSP}
  238. */
  239. template <>
  240. struct SIMDNativeOps<uint16_t>
  241. {
  242. //==============================================================================
  243. using vSIMDType = uint16x8_t;
  244. using fb = SIMDFallbackOps<uint16_t, vSIMDType>;
  245. //==============================================================================
  246. DECLARE_NEON_SIMD_CONST (uint16_t, kAllBitsSet);
  247. //==============================================================================
  248. static forcedinline vSIMDType expand (uint16_t s) noexcept { return vdupq_n_u16 (s); }
  249. static forcedinline vSIMDType load (const uint16_t* a) noexcept { return vld1q_u16 (a); }
  250. static forcedinline void store (vSIMDType value, uint16_t* a) noexcept { vst1q_u16 (a, value); }
  251. static forcedinline uint16_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  252. static forcedinline vSIMDType set (vSIMDType v, size_t i, uint16_t s) noexcept { v[i] = s; return v; }
  253. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_u16 (a, b); }
  254. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_u16 (a, b); }
  255. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_u16 (a, b); }
  256. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_u16 (a, b); }
  257. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_u16 (a, b); }
  258. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_u16 (a, b); }
  259. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_u16 (b, a); }
  260. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_u16 ((uint16_t*) kAllBitsSet)); }
  261. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_u16 (a, b); }
  262. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_u16 (a, b); }
  263. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_u16 (a, b); }
  264. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  265. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_u16 (a, b); }
  266. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_u16 (a, b); }
  267. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<uint32_t>::sum ((SIMDNativeOps<uint32_t>::vSIMDType) notEqual (a, b)) == 0); }
  268. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_u16 (a, b, c); }
  269. static forcedinline uint16_t sum (vSIMDType a) noexcept { return fb::sum (a); }
  270. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  271. };
  272. //==============================================================================
  273. /** Signed 64-bit integer NEON intrinsics.
  274. @tags{DSP}
  275. */
  276. template <>
  277. struct SIMDNativeOps<int64_t>
  278. {
  279. //==============================================================================
  280. using vSIMDType = int64x2_t;
  281. using fb = SIMDFallbackOps<int64_t, vSIMDType>;
  282. //==============================================================================
  283. DECLARE_NEON_SIMD_CONST (int64_t, kAllBitsSet);
  284. //==============================================================================
  285. static forcedinline vSIMDType expand (int64_t s) noexcept { return vdupq_n_s64 (s); }
  286. static forcedinline vSIMDType load (const int64_t* a) noexcept { return vld1q_s64 (a); }
  287. static forcedinline void store (vSIMDType value, int64_t* a) noexcept { vst1q_s64 (a, value); }
  288. static forcedinline int64_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  289. static forcedinline vSIMDType set (vSIMDType v, size_t i, int64_t s) noexcept { v[i] = s; return v; }
  290. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_s64 (a, b); }
  291. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_s64 (a, b); }
  292. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return fb::mul (a, b); }
  293. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_s64 (a, b); }
  294. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_s64 (a, b); }
  295. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_s64 (a, b); }
  296. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_s64 (b, a); }
  297. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_s64 ((int64_t*) kAllBitsSet)); }
  298. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return fb::min (a, b); }
  299. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return fb::max (a, b); }
  300. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return fb::equal (a, b); }
  301. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return fb::notEqual (a, b); }
  302. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return fb::greaterThan (a, b); }
  303. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return fb::greaterThanOrEqual (a, b); }
  304. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<int32_t>::sum ((SIMDNativeOps<int32_t>::vSIMDType) notEqual (a, b)) == 0); }
  305. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return fb::multiplyAdd (a, b, c); }
  306. static forcedinline int64_t sum (vSIMDType a) noexcept { return fb::sum (a); }
  307. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  308. };
  309. //==============================================================================
  310. /** Unsigned 64-bit integer NEON intrinsics.
  311. @tags{DSP}
  312. */
  313. template <>
  314. struct SIMDNativeOps<uint64_t>
  315. {
  316. //==============================================================================
  317. using vSIMDType = uint64x2_t;
  318. using fb = SIMDFallbackOps<uint64_t, vSIMDType>;
  319. //==============================================================================
  320. DECLARE_NEON_SIMD_CONST (uint64_t, kAllBitsSet);
  321. //==============================================================================
  322. static forcedinline vSIMDType expand (uint64_t s) noexcept { return vdupq_n_u64 (s); }
  323. static forcedinline vSIMDType load (const uint64_t* a) noexcept { return vld1q_u64 (a); }
  324. static forcedinline void store (vSIMDType value, uint64_t* a) noexcept { vst1q_u64 (a, value); }
  325. static forcedinline uint64_t get (vSIMDType v, size_t i) noexcept { return v[i]; }
  326. static forcedinline vSIMDType set (vSIMDType v, size_t i, uint64_t s) noexcept { v[i] = s; return v; }
  327. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_u64 (a, b); }
  328. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_u64 (a, b); }
  329. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return fb::mul (a, b); }
  330. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return vandq_u64 (a, b); }
  331. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return vorrq_u64 (a, b); }
  332. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return veorq_u64 (a, b); }
  333. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return vbicq_u64 (b, a); }
  334. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_u64 ((uint64_t*) kAllBitsSet)); }
  335. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return fb::min (a, b); }
  336. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return fb::max (a, b); }
  337. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return fb::equal (a, b); }
  338. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return fb::notEqual (a, b); }
  339. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return fb::greaterThan (a, b); }
  340. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return fb::greaterThanOrEqual (a, b); }
  341. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<uint32_t>::sum ((SIMDNativeOps<uint32_t>::vSIMDType) notEqual (a, b)) == 0); }
  342. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return fb::multiplyAdd (a, b, c); }
  343. static forcedinline uint64_t sum (vSIMDType a) noexcept { return fb::sum (a); }
  344. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return a; }
  345. };
  346. //==============================================================================
  347. /** Single-precision floating point NEON intrinsics.
  348. @tags{DSP}
  349. */
  350. template <>
  351. struct SIMDNativeOps<float>
  352. {
  353. //==============================================================================
  354. using vSIMDType = float32x4_t;
  355. using vMaskType = uint32x4_t;
  356. using fb = SIMDFallbackOps<float, vSIMDType>;
  357. //==============================================================================
  358. DECLARE_NEON_SIMD_CONST (int32_t, kAllBitsSet);
  359. DECLARE_NEON_SIMD_CONST (int32_t, kEvenHighBit);
  360. DECLARE_NEON_SIMD_CONST (float, kOne);
  361. //==============================================================================
  362. static forcedinline vSIMDType expand (float s) noexcept { return vdupq_n_f32 (s); }
  363. static forcedinline vSIMDType load (const float* a) noexcept { return vld1q_f32 (a); }
  364. static forcedinline float get (vSIMDType v, size_t i) noexcept { return v[i]; }
  365. static forcedinline vSIMDType set (vSIMDType v, size_t i, float s) noexcept { v[i] = s; return v; }
  366. static forcedinline void store (vSIMDType value, float* a) noexcept { vst1q_f32 (a, value); }
  367. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return vaddq_f32 (a, b); }
  368. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return vsubq_f32 (a, b); }
  369. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return vmulq_f32 (a, b); }
  370. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vandq_u32 ((vMaskType) a, (vMaskType) b); }
  371. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vorrq_u32 ((vMaskType) a, (vMaskType) b); }
  372. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) veorq_u32 ((vMaskType) a, (vMaskType) b); }
  373. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vbicq_u32 ((vMaskType) b, (vMaskType) a); }
  374. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return bit_notand (a, vld1q_f32 ((float*) kAllBitsSet)); }
  375. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return vminq_f32 (a, b); }
  376. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return vmaxq_f32 (a, b); }
  377. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vceqq_f32 (a, b); }
  378. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return bit_not (equal (a, b)); }
  379. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgtq_f32 (a, b); }
  380. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return (vSIMDType) vcgeq_f32 (a, b); }
  381. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return (SIMDNativeOps<uint32_t>::sum ((SIMDNativeOps<uint32_t>::vSIMDType) notEqual (a, b)) == 0); }
  382. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return vmlaq_f32 (a, b, c); }
  383. static forcedinline vSIMDType dupeven (vSIMDType a) noexcept { return fb::shuffle<(0 << 0) | (0 << 2) | (2 << 4) | (2 << 6)> (a); }
  384. static forcedinline vSIMDType dupodd (vSIMDType a) noexcept { return fb::shuffle<(1 << 0) | (1 << 2) | (3 << 4) | (3 << 6)> (a); }
  385. static forcedinline vSIMDType swapevenodd (vSIMDType a) noexcept { return fb::shuffle<(1 << 0) | (0 << 2) | (3 << 4) | (2 << 6)> (a); }
  386. static forcedinline vSIMDType oddevensum (vSIMDType a) noexcept { return add (fb::shuffle<(2 << 0) | (3 << 2) | (0 << 4) | (1 << 6)> (a), a); }
  387. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return vcvtq_f32_s32 (vcvtq_s32_f32 (a)); }
  388. //==============================================================================
  389. static forcedinline vSIMDType cmplxmul (vSIMDType a, vSIMDType b) noexcept
  390. {
  391. vSIMDType rr_ir = mul (a, dupeven (b));
  392. vSIMDType ii_ri = mul (swapevenodd (a), dupodd (b));
  393. return add (rr_ir, bit_xor (ii_ri, vld1q_f32 ((float*) kEvenHighBit)));
  394. }
  395. static forcedinline float sum (vSIMDType a) noexcept
  396. {
  397. auto rr = vadd_f32 (vget_high_f32 (a), vget_low_f32 (a));
  398. return vget_lane_f32 (vpadd_f32 (rr, rr), 0);
  399. }
  400. };
  401. //==============================================================================
  402. /** Double-precision floating point NEON intrinsics does not exist in NEON
  403. so we need to emulate this.
  404. @tags{DSP}
  405. */
  406. template <>
  407. struct SIMDNativeOps<double>
  408. {
  409. //==============================================================================
  410. using vSIMDType = struct { double v[2]; };
  411. using fb = SIMDFallbackOps<double, vSIMDType>;
  412. static forcedinline vSIMDType expand (double s) noexcept { return {{s, s}}; }
  413. static forcedinline vSIMDType load (const double* a) noexcept { return {{a[0], a[1]}}; }
  414. static forcedinline void store (vSIMDType v, double* a) noexcept { a[0] = v.v[0]; a[1] = v.v[1]; }
  415. static forcedinline double get (vSIMDType v, size_t i) noexcept { return v.v[i]; }
  416. static forcedinline vSIMDType set (vSIMDType v, size_t i, double s) noexcept { v.v[i] = s; return v; }
  417. static forcedinline vSIMDType add (vSIMDType a, vSIMDType b) noexcept { return {{a.v[0] + b.v[0], a.v[1] + b.v[1]}}; }
  418. static forcedinline vSIMDType sub (vSIMDType a, vSIMDType b) noexcept { return {{a.v[0] - b.v[0], a.v[1] - b.v[1]}}; }
  419. static forcedinline vSIMDType mul (vSIMDType a, vSIMDType b) noexcept { return {{a.v[0] * b.v[0], a.v[1] * b.v[1]}}; }
  420. static forcedinline vSIMDType bit_and (vSIMDType a, vSIMDType b) noexcept { return fb::bit_and (a, b); }
  421. static forcedinline vSIMDType bit_or (vSIMDType a, vSIMDType b) noexcept { return fb::bit_or (a, b); }
  422. static forcedinline vSIMDType bit_xor (vSIMDType a, vSIMDType b) noexcept { return fb::bit_xor (a, b); }
  423. static forcedinline vSIMDType bit_notand (vSIMDType a, vSIMDType b) noexcept { return fb::bit_notand (a, b); }
  424. static forcedinline vSIMDType bit_not (vSIMDType a) noexcept { return fb::bit_not (a); }
  425. static forcedinline vSIMDType min (vSIMDType a, vSIMDType b) noexcept { return fb::min (a, b); }
  426. static forcedinline vSIMDType max (vSIMDType a, vSIMDType b) noexcept { return fb::max (a, b); }
  427. static forcedinline vSIMDType equal (vSIMDType a, vSIMDType b) noexcept { return fb::equal (a, b); }
  428. static forcedinline vSIMDType notEqual (vSIMDType a, vSIMDType b) noexcept { return fb::notEqual (a, b); }
  429. static forcedinline vSIMDType greaterThan (vSIMDType a, vSIMDType b) noexcept { return fb::greaterThan (a, b); }
  430. static forcedinline vSIMDType greaterThanOrEqual (vSIMDType a, vSIMDType b) noexcept { return fb::greaterThanOrEqual (a, b); }
  431. static forcedinline bool allEqual (vSIMDType a, vSIMDType b) noexcept { return fb::allEqual (a, b); }
  432. static forcedinline vSIMDType multiplyAdd (vSIMDType a, vSIMDType b, vSIMDType c) noexcept { return fb::multiplyAdd (a, b, c); }
  433. static forcedinline vSIMDType cmplxmul (vSIMDType a, vSIMDType b) noexcept { return fb::cmplxmul (a, b); }
  434. static forcedinline double sum (vSIMDType a) noexcept { return fb::sum (a); }
  435. static forcedinline vSIMDType oddevensum (vSIMDType a) noexcept { return a; }
  436. static forcedinline vSIMDType truncate (vSIMDType a) noexcept { return fb::truncate (a); }
  437. };
  438. #endif
  439. #if JUCE_GCC && (__GNUC__ >= 6)
  440. #pragma GCC diagnostic pop
  441. #endif
  442. } // namespace dsp
  443. } // namespace juce