Table of Contents

Wwise SDK 2019.2.11
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: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> 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_PELLEGRINO)
59 #include <AK/Tools/Pellegrino/AkPlatformFuncs.h>
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 
131 namespace AKPLATFORM
132 {
134  {
135  AkGetDefaultThreadProperties(out_threadProperties);
136  out_threadProperties.nPriority = AK_THREAD_PRIORITY_ABOVE_NORMAL;
137  }
138 
139 
140 #if defined _MSC_VER && defined AK_CPU_X86_64
141  AkForceInline AkUInt32 AkBitScanForward64(unsigned long long in_bits)
142  {
143  unsigned long ret = 0;
144  _BitScanForward64(&ret, in_bits);
145  return ret;
146  }
147 #elif __clang__ || defined __GNUG__
149  {
150  return __builtin_ctzll(in_bits);
151  }
152 #else
153  AkForceInline AkUInt32 AkBitScanForward64(unsigned long long in_bits)
154  {
155  unsigned long ret = 0;
156  if (in_bits)
157  {
158  while ((in_bits & 1ULL) == 0)
159  {
160  in_bits >>= 1;
161  ret++;
162  }
163  }
164  return ret;
165  }
166 #endif
167 
168 #if defined _MSC_VER
169  AkForceInline AkUInt32 AkBitScanForward(unsigned long in_bits)
170  {
171  unsigned long ret = 0;
172  _BitScanForward(&ret, in_bits);
173  return ret;
174  }
175 
176 #elif __clang__ || defined __GNUG__
178  {
179  return __builtin_ctzl(in_bits);
180  }
181 #else
182  AkForceInline AkUInt32 AkBitScanForward(unsigned long in_bits)
183  {
184  unsigned long ret = 0;
185  if (in_bits)
186  {
187  while ((in_bits & 1ULL) == 0)
188  {
189  in_bits >>= 1;
190  ret++;
191  }
192  }
193  return ret;
194  }
195 #endif
196 }
197 
198 
199 #ifndef AK_PERF_RECORDING_RESET
200 #define AK_PERF_RECORDING_RESET()
201 #endif
202 #ifndef AK_PERF_RECORDING_START
203 #define AK_PERF_RECORDING_START( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ )
204 #endif
205 #ifndef AK_PERF_RECORDING_STOP
206 #define AK_PERF_RECORDING_STOP( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ )
207 #endif
208 
209 #ifndef AK_INSTRUMENT_BEGIN
210  #define AK_INSTRUMENT_BEGIN( _zone_name_ )
211  #define AK_INSTRUMENT_END( _zone_name_ )
212  #define AK_INSTRUMENT_SCOPE( _zone_name_ )
213 
214  #define AK_INSTRUMENT_BEGIN_C(_colour_, _zone_name_ )
215 
216  #define AK_INSTRUMENT_IDLE_BEGIN( _zone_name_ )
217  #define AK_INSTRUMENT_IDLE_END( _zone_name_ )
218  #define AK_INSTRUMENT_IDLE_SCOPE( _zone_name_ )
219 
220  #define AK_INSTRUMENT_STALL_BEGIN( _zone_name_ )
221  #define AK_INSTRUMENT_STALL_END( _zone_name_ )
222  #define AK_INSTRUMENT_STALL_SCOPE( _zone_name_ )
223 
224  #define AK_INSTRUMENT_THREAD_START( _thread_name_ )
225 #endif
226 
227 #endif // _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
uint64_t AkUInt64
Unsigned 64-bit integer.
Definition: AkTypes.h:86
#define AkForceInline
Force inlining.
Definition: AkTypes.h:66
Audiokinetic namespace.
int nPriority
Thread priority.
Definition: AkPlatformFuncs.h:49
AkForceInline AkUInt32 AkBitScanForward64(unsigned long long in_bits)
Definition: AkPlatformFuncs.h:153
#define AK_THREAD_PRIORITY_ABOVE_NORMAL
Definition: AkPlatformFuncs.h:79
AkForceInline void AkGetDefaultThreadProperties(AkThreadProperties &out_threadProperties)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:240
void AkGetDefaultHighPriorityThreadProperties(AkThreadProperties &out_threadProperties)
Definition: AkPlatformFuncs.h:133
AkForceInline AkUInt32 GetNumNonZeroBits(AkUInt32 in_uWord)
Definition: AkPlatformFuncs.h:123
uint32_t AkUInt32
Unsigned 32-bit integer.
Definition: AkTypes.h:85
AkForceInline AkUInt32 AkBitScanForward(unsigned long in_bits)
Definition: AkPlatformFuncs.h:182