Wwise Version
Wwise SDK 2021.1.2
AkPlatformFuncs.h
Go to the documentation of this file.
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 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24  Version: v2021.1.2 Build: 7629
25  Copyright (c) 2006-2021 Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkPlatformFuncs.h
29 
30 /// \file
31 /// Platform-dependent functions definition.
32 
33 #ifndef _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
34 #define _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
35 
38 
39 // Uncomment the following to enable built-in platform profiler markers in the sound engine
40 //#define AK_ENABLE_INSTRUMENT
41 
42 #if defined(AK_WIN)
44 
45 #elif defined (AK_XBOX)
46 #include <AK/Tools/XboxOne/AkPlatformFuncs.h>
47 
48 #elif defined (AK_APPLE)
50 #include <AK/Tools/POSIX/AkPlatformFuncs.h>
51 
52 #elif defined (AK_ANDROID)
54 
55 #elif defined (AK_PS4)
57 
58 #elif defined (AK_PS5)
60 
61 #elif defined (AK_EMSCRIPTEN)
62 #include <AK/Tools/Emscripten/AkPlatformFuncs.h>
63 
64 #elif defined (AK_LINUX)
65 
66 #ifdef AK_GGP
67 #include <AK/Tools/GGP/AkPlatformFuncs.h>
68 #endif
70 #include <AK/Tools/POSIX/AkPlatformFuncs.h>
71 
72 #elif defined (AK_QNX)
73 #include <AK/Tools/QNX/AkPlatformFuncs.h>
74 #include <AK/Tools/POSIX/AkPlatformFuncs.h>
75 
76 #elif defined (AK_NX)
78 
79 #else
80 #error AkPlatformFuncs.h: Undefined platform
81 #endif
82 
83 #ifndef AkPrefetchZero
84 #define AkPrefetchZero(___Dest, ___Size)
85 #endif
86 
87 #ifndef AkPrefetchZeroAligned
88 #define AkPrefetchZeroAligned(___Dest, ___Size)
89 #endif
90 
91 #ifndef AkZeroMemAligned
92 #define AkZeroMemAligned(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
93 #endif
94 #ifndef AkZeroMemLarge
95 #define AkZeroMemLarge(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
96 #endif
97 #ifndef AkZeroMemSmall
98 #define AkZeroMemSmall(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
99 #endif
100 
101 #ifndef AkAllocaSIMD
102 #ifdef __clang__
103 #if __has_builtin( __builtin_alloca_with_align )
104 #define AkAllocaSIMD( _size_ ) __builtin_alloca_with_align( _size_, 128 )
105 #else
106 // work around alloca alignment issues in versions of clang before 4.0
107 #define AkAllocaSIMD( _size_ ) (void*)( ( ( uintptr_t )AkAlloca( _size_ + 16 ) + 0xF ) & ~0xF )
108 #endif
109 #else
110 #define AkAllocaSIMD( _size_ ) AkAlloca( _size_ )
111 #endif
112 #endif
113 
114 #ifndef AK_THREAD_INIT_CODE
115 #define AK_THREAD_INIT_CODE(_threadProperties)
116 #endif
117 
118 /// Utility functions
119 namespace AK
120 {
121  /// Count non-zero bits.
122  /// \return Number of channels.
124  {
125  AkUInt32 num = 0;
126  while( in_uWord ){ ++num; in_uWord &= in_uWord-1; }
127  return num;
128  }
129 
130  /// Computes the next power of two given a value.
131  /// \return next power of two.
133  {
134  in_uValue--;
135  in_uValue |= in_uValue >> 1;
136  in_uValue |= in_uValue >> 2;
137  in_uValue |= in_uValue >> 4;
138  in_uValue |= in_uValue >> 8;
139  in_uValue |= in_uValue >> 16;
140  in_uValue++;
141  return in_uValue;
142  }
143 
145  {
146  return ( x << r ) | ( x >> ( 32 - r ) );
147  }
148 
150  {
151  return ( x << r ) | ( x >> ( 64 - r ) );
152  }
153 }
154 
155 /// Platform-dependent helpers
156 namespace AKPLATFORM
157 {
159  {
160  AkGetDefaultThreadProperties(out_threadProperties);
161  out_threadProperties.nPriority = AK_THREAD_PRIORITY_ABOVE_NORMAL;
162  }
163 
164 
165 #if defined _MSC_VER && defined AK_CPU_X86_64
166  AkForceInline AkUInt32 AkBitScanForward64(unsigned long long in_bits)
167  {
168  unsigned long ret = 0;
169  _BitScanForward64(&ret, in_bits);
170  return ret;
171  }
172 #elif __clang__ || defined __GNUG__
174  {
175  return __builtin_ctzll(in_bits);
176  }
177 #else
178  AkForceInline AkUInt32 AkBitScanForward64(unsigned long long in_bits)
179  {
180  unsigned long ret = 0;
181  if (in_bits)
182  {
183  while ((in_bits & 1ULL) == 0)
184  {
185  in_bits >>= 1;
186  ret++;
187  }
188  }
189  return ret;
190  }
191 #endif
192 
193 #if defined _MSC_VER
194  AkForceInline AkUInt32 AkBitScanForward(unsigned long in_bits)
195  {
196  unsigned long ret = 0;
197  _BitScanForward(&ret, in_bits);
198  return ret;
199  }
200 
201 #elif __clang__ || defined __GNUG__
203  {
204  return __builtin_ctzl(in_bits);
205  }
206 #else
207  AkForceInline AkUInt32 AkBitScanForward(unsigned long in_bits)
208  {
209  unsigned long ret = 0;
210  if (in_bits)
211  {
212  while ((in_bits & 1ULL) == 0)
213  {
214  in_bits >>= 1;
215  ret++;
216  }
217  }
218  return ret;
219  }
220 #endif
221 }
222 
223 
224 #ifndef AK_PERF_RECORDING_RESET
225 #define AK_PERF_RECORDING_RESET()
226 #endif
227 #ifndef AK_PERF_RECORDING_START
228 #define AK_PERF_RECORDING_START( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ )
229 #endif
230 #ifndef AK_PERF_RECORDING_STOP
231 #define AK_PERF_RECORDING_STOP( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ )
232 #endif
233 
234 #ifndef AK_INSTRUMENT_BEGIN
235  #define AK_INSTRUMENT_BEGIN( _zone_name_ )
236  #define AK_INSTRUMENT_END( _zone_name_ )
237  #define AK_INSTRUMENT_SCOPE( _zone_name_ )
238 
239  #define AK_INSTRUMENT_BEGIN_C(_colour_, _zone_name_ )
240 
241  #define AK_INSTRUMENT_IDLE_BEGIN( _zone_name_ )
242  #define AK_INSTRUMENT_IDLE_END( _zone_name_ )
243  #define AK_INSTRUMENT_IDLE_SCOPE( _zone_name_ )
244 
245  #define AK_INSTRUMENT_STALL_BEGIN( _zone_name_ )
246  #define AK_INSTRUMENT_STALL_END( _zone_name_ )
247  #define AK_INSTRUMENT_STALL_SCOPE( _zone_name_ )
248 
249  #define AK_INSTRUMENT_THREAD_START( _thread_name_ )
250 #endif
251 
252 #endif // _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
uint64_t AkUInt64
Unsigned 64-bit integer.
Definition: AkTypes.h:78
#define AkForceInline
Force inlining.
Definition: AkTypes.h:61
Audiokinetic namespace.
int nPriority
Thread priority.
Definition: AkPlatformFuncs.h:49
Platform-dependent helpers.
Definition: AkPlatformFuncs.h:157
AkForceInline AkUInt32 AkBitScanForward64(unsigned long long in_bits)
Definition: AkPlatformFuncs.h:178
AkForceInline AkUInt32 ROTL32(AkUInt32 x, AkUInt32 r)
Definition: AkPlatformFuncs.h:144
#define AK_THREAD_PRIORITY_ABOVE_NORMAL
Definition: AkPlatformFuncs.h:79
AkForceInline AkUInt32 GetNextPowerOfTwo(AkUInt32 in_uValue)
Definition: AkPlatformFuncs.h:132
AkForceInline void AkGetDefaultThreadProperties(AkThreadProperties &out_threadProperties)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:302
void AkGetDefaultHighPriorityThreadProperties(AkThreadProperties &out_threadProperties)
Definition: AkPlatformFuncs.h:158
AkForceInline AkUInt32 GetNumNonZeroBits(AkUInt32 in_uWord)
Definition: AkPlatformFuncs.h:123
AkForceInline AkUInt64 ROTL64(AkUInt64 x, AkUInt64 r)
Definition: AkPlatformFuncs.h:149
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:77
AkForceInline AkUInt32 AkBitScanForward(unsigned long in_bits)
Definition: AkPlatformFuncs.h:207