AkSimd.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #pragma once
  24. #include <AK/SoundEngine/Common/AkTypes.h>
  25. /// Get the element at index __num__ in vector __vName
  26. #define AKSIMD_GETELEMENT_V4F32( __vName, __num__ ) ((AkReal32*)&(__vName))[(__num__)]
  27. #define AKSIMD_GETELEMENT_V2F32( __vName, __num__ ) ((AkReal32*)&(__vName))[(__num__)]
  28. #define AKSIMD_GETELEMENT_V2F64( __vName, __num__ ) ((AkReal64*)&(__vName))[(__num__)]
  29. #define AKSIMD_GETELEMENT_V4I32( __vName, __num__ ) ((AkInt32*)&(__vName))[(__num__)]
  30. #define AKSIMD_GETELEMENT_V2I64( __vName, __num__ ) ((AkInt64*)&(__vName))[(__num__)]
  31. //////////////////////////////////////////////////////////////////////////
  32. // Platform-specific section.
  33. #if defined( AK_WIN ) || defined( AK_XBOX )
  34. #include <AK/SoundEngine/Platforms/Windows/AkSimd.h>
  35. #elif defined( AK_APPLE )
  36. #include <TargetConditionals.h>
  37. #include <AK/SoundEngine/Platforms/Mac/AkSimd.h>
  38. #elif defined( AK_ANDROID )
  39. #include <AK/SoundEngine/Platforms/Android/AkSimd.h>
  40. #elif defined( AK_PS4 )
  41. #include <AK/SoundEngine/Platforms/PS4/AkSimd.h>
  42. #elif defined( AK_PS5 )
  43. #include <AK/SoundEngine/Platforms/PS5/AkSimd.h>
  44. #elif defined( AK_LINUX )
  45. #include <AK/SoundEngine/Platforms/Linux/AkSimd.h>
  46. #elif defined( AK_EMSCRIPTEN )
  47. #include <AK/SoundEngine/Platforms/Emscripten/AkSimd.h>
  48. #elif defined( AK_QNX )
  49. #include <AK/SoundEngine/Platforms/QNX/AkSimd.h>
  50. #elif defined( AK_NX )
  51. #include <AK/SoundEngine/Platforms/NX/AkSimd.h>
  52. #else
  53. #error Unsupported platform, or platform-specific SIMD not defined
  54. #endif
  55. //////////////////////////////////////////////////////////////////////////
  56. // Other helpers
  57. #ifndef AKSIMD_ASSERTFLUSHZEROMODE
  58. #define AKSIMD_ASSERTFLUSHZEROMODE
  59. #endif
  60. #ifndef AKSIMD_DECLARE_V4F32_TYPE
  61. #define AKSIMD_DECLARE_V4F32_TYPE AKSIMD_V4F32
  62. #endif
  63. #ifndef AKSIMD_DECLARE_V4I32_TYPE
  64. #define AKSIMD_DECLARE_V4I32_TYPE AKSIMD_V4I32
  65. #endif
  66. #ifndef AKSIMD_DECLARE_V4F32
  67. #define AKSIMD_DECLARE_V4F32( _x, _a, _b, _c, _d ) AKSIMD_DECLARE_V4F32_TYPE _x = { _a, _b, _c, _d }
  68. #endif
  69. #ifndef AKSIMD_DECLARE_V4I32
  70. #define AKSIMD_DECLARE_V4I32( _x, _a, _b, _c, _d ) AKSIMD_DECLARE_V4I32_TYPE _x = { _a, _b, _c, _d }
  71. #endif
  72. #ifndef AKSIMD_SETELEMENT_V4F32
  73. #define AKSIMD_SETELEMENT_V4F32( __vName__, __num__, __value__ ) ( AKSIMD_GETELEMENT_V4F32( __vName__, __num__ ) = (__value__) )
  74. #endif
  75. /// Rotate four vectors. After rotation:
  76. /// A[3:0] = D[0] C[0] B[0] A[0]
  77. /// B[3:0] = D[1] C[1] B[1] A[1]
  78. /// C[3:0] = D[2] C[2] B[2] A[2]
  79. /// D[3:0] = D[3] C[3] B[3] A[3]
  80. AkForceInline void AKSIMD_TRANSPOSE4X4_V4F32(AKSIMD_V4F32 &A, AKSIMD_V4F32 &B, AKSIMD_V4F32 &C, AKSIMD_V4F32 &D)
  81. {
  82. AKSIMD_V4F32 tmp1, tmp2, tmp3, tmp4;
  83. tmp1 = AKSIMD_MOVELH_V4F32(A, B);
  84. tmp2 = AKSIMD_MOVEHL_V4F32(B, A);
  85. tmp3 = AKSIMD_MOVELH_V4F32(C, D);
  86. tmp4 = AKSIMD_MOVEHL_V4F32(D, C);
  87. A = AKSIMD_SHUFFLE_V4F32(tmp1, tmp3, AKSIMD_SHUFFLE(2, 0, 2, 0));
  88. B = AKSIMD_SHUFFLE_V4F32(tmp1, tmp3, AKSIMD_SHUFFLE(3, 1, 3, 1));
  89. C = AKSIMD_SHUFFLE_V4F32(tmp2, tmp4, AKSIMD_SHUFFLE(2, 0, 2, 0));
  90. D = AKSIMD_SHUFFLE_V4F32(tmp2, tmp4, AKSIMD_SHUFFLE(3, 1, 3, 1));
  91. }