Version
menu_open
link
Wwise SDK 2023.1.3
AkBitFuncs.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  Copyright (c) 2024 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 #pragma once
28 
30 #include <intrin.h>
31 
32 #define AK_BIT_SCAN_INSTRUCTIONS // mark bitscan instructions as defined to avoid duplicate definitions
33 
34 // On Xbox we can guarantee support of intrinsics like popcnt and tzcnt, so we can utilize those
35 namespace AKPLATFORM
36 {
37  // AkPopCount returns how many set bits there are in the provided value
38  // e.g. 0b0000`1111`0000`0011 would return 6
40  {
41  return (AkUInt32)__popcnt(in_bits);
42  }
43 
44  // AkBitScanForward returns how many 0s there are until the least-significant-bit is set
45  // (or the length of the param if the value is zero)
46  // e.g. 0b0000`0000`0001`0000 would return 4
48  {
49  return (AkUInt32)_tzcnt_u64(in_bits);
50  }
51 
53  {
54  return (AkUInt32)_tzcnt_u32(in_bits);
55  }
56 
57  // AkBitScanReverse returns how many 0s there are after the most-significant-bit is set
58  // (or the length of the param if the value is zero)
59  // e.g. 0b0000`0000`0001`0000 would return 11
61  {
62  return (AkUInt32)_lzcnt_u64(in_bits);
63  }
64 
66  {
67  return (AkUInt32)_lzcnt_u32(in_bits);
68  }
69 }
AkForceInline AkUInt32 AkBitScanReverse64(AkUInt64 in_bits)
Definition: AkBitFuncs.h:133
Platform-dependent helpers.
Definition: AkBitFuncs.h:43
AkForceInline AkUInt32 AkPopCount(AkUInt32 in_bits)
Definition: AkBitFuncs.h:52
AkForceInline AkUInt32 AkBitScanForward64(AkUInt64 in_bits)
Definition: AkBitFuncs.h:76
AkForceInline AkUInt32 AkBitScanReverse(AkUInt32 in_bits)
Definition: AkBitFuncs.h:160
AkForceInline AkUInt32 AkBitScanForward(AkUInt32 in_bits)
Definition: AkBitFuncs.h:104
uint64_t AkUInt64
Unsigned 64-bit integer.
uint32_t AkUInt32
Unsigned 32-bit integer.
#define AkForceInline
Definition: AkTypes.h:63

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise