AkSimd.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. // AkSimd.h
  21. /// \file
  22. /// Simd definitions.
  23. #ifndef _AK_SIMD_H_
  24. #define _AK_SIMD_H_
  25. #include <AK/SoundEngine/Common/AkTypes.h>
  26. /// Get the element at index __num__ in vector __vName
  27. #define AKSIMD_GETELEMENT_V4F32( __vName, __num__ ) ((AkReal32*)&(__vName))[(__num__)]
  28. #define AKSIMD_GETELEMENT_V2F32( __vName, __num__ ) ((AkReal32*)&(__vName))[(__num__)]
  29. #define AKSIMD_GETELEMENT_V2F64( __vName, __num__ ) ((AkReal64*)&(__vName))[(__num__)]
  30. #define AKSIMD_GETELEMENT_V4I32( __vName, __num__ ) ((AkInt32*)&(__vName))[(__num__)]
  31. #define AKSIMD_GETELEMENT_V2I64( __vName, __num__ ) ((AkInt64*)&(__vName))[(__num__)]
  32. //////////////////////////////////////////////////////////////////////////
  33. // Platform-specific section.
  34. #if defined( AK_WIN ) || defined( AK_XBOX )
  35. #include <AK/SoundEngine/Platforms/Windows/AkSimd.h>
  36. #elif defined( AK_APPLE )
  37. #include <TargetConditionals.h>
  38. #if TARGET_OS_IPHONE
  39. #include <AK/SoundEngine/Platforms/iOS/AkSimd.h>
  40. #else
  41. #include <AK/SoundEngine/Platforms/Mac/AkSimd.h>
  42. #endif
  43. #elif defined( AK_ANDROID )
  44. #include <AK/SoundEngine/Platforms/Android/AkSimd.h>
  45. #elif defined( AK_PS4 )
  46. #include <AK/SoundEngine/Platforms/PS4/AkSimd.h>
  47. #elif defined( AK_PS5 )
  48. #include <AK/SoundEngine/Platforms/PS5/AkSimd.h>
  49. #elif defined( AK_LINUX )
  50. #include <AK/SoundEngine/Platforms/Linux/AkSimd.h>
  51. #elif defined( AK_EMSCRIPTEN )
  52. #include <AK/SoundEngine/Platforms/Emscripten/AkSimd.h>
  53. #elif defined( AK_QNX )
  54. #include <AK/SoundEngine/Platforms/QNX/AkSimd.h>
  55. #elif defined( AK_NX )
  56. #include <AK/SoundEngine/Platforms/NX/AkSimd.h>
  57. #else
  58. #error Unsupported platform, or platform-specific SIMD not defined
  59. #endif
  60. //////////////////////////////////////////////////////////////////////////
  61. // Other helpers
  62. #ifndef AKSIMD_ASSERTFLUSHZEROMODE
  63. #define AKSIMD_ASSERTFLUSHZEROMODE
  64. #endif
  65. #ifndef AKSIMD_DECLARE_V4F32_TYPE
  66. #define AKSIMD_DECLARE_V4F32_TYPE AKSIMD_V4F32
  67. #endif
  68. #ifndef AKSIMD_DECLARE_V4I32_TYPE
  69. #define AKSIMD_DECLARE_V4I32_TYPE AKSIMD_V4I32
  70. #endif
  71. #ifndef AKSIMD_DECLARE_V4F32
  72. #define AKSIMD_DECLARE_V4F32( _x, _a, _b, _c, _d ) AKSIMD_DECLARE_V4F32_TYPE _x = { _a, _b, _c, _d }
  73. #endif
  74. #ifndef AKSIMD_DECLARE_V4I32
  75. #define AKSIMD_DECLARE_V4I32( _x, _a, _b, _c, _d ) AKSIMD_DECLARE_V4I32_TYPE _x = { _a, _b, _c, _d }
  76. #endif
  77. #ifndef AKSIMD_SETELEMENT_V4F32
  78. #define AKSIMD_SETELEMENT_V4F32( __vName__, __num__, __value__ ) ( AKSIMD_GETELEMENT_V4F32( __vName__, __num__ ) = (__value__) )
  79. #endif
  80. /// Rotate four vectors. After rotation:
  81. /// A[3:0] = D[0] C[0] B[0] A[0]
  82. /// B[3:0] = D[1] C[1] B[1] A[1]
  83. /// C[3:0] = D[2] C[2] B[2] A[2]
  84. /// D[3:0] = D[3] C[3] B[3] A[3]
  85. AkForceInline void AKSIMD_TRANSPOSE4X4_V4F32(AKSIMD_V4F32 &A, AKSIMD_V4F32 &B, AKSIMD_V4F32 &C, AKSIMD_V4F32 &D)
  86. {
  87. AKSIMD_V4F32 tmp1, tmp2, tmp3, tmp4;
  88. tmp1 = AKSIMD_MOVELH_V4F32(A, B);
  89. tmp2 = AKSIMD_MOVEHL_V4F32(B, A);
  90. tmp3 = AKSIMD_MOVELH_V4F32(C, D);
  91. tmp4 = AKSIMD_MOVEHL_V4F32(D, C);
  92. A = AKSIMD_SHUFFLE_V4F32(tmp1, tmp3, AKSIMD_SHUFFLE(2, 0, 2, 0));
  93. B = AKSIMD_SHUFFLE_V4F32(tmp1, tmp3, AKSIMD_SHUFFLE(3, 1, 3, 1));
  94. C = AKSIMD_SHUFFLE_V4F32(tmp2, tmp4, AKSIMD_SHUFFLE(2, 0, 2, 0));
  95. D = AKSIMD_SHUFFLE_V4F32(tmp2, tmp4, AKSIMD_SHUFFLE(3, 1, 3, 1));
  96. }
  97. #endif //_AK_DATA_TYPES_H_