Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
Platform.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <functional>
5
6#include "Inline/BasicTypes.h"
7#include "Inline/Errors.h"
8
9// Use __thread instead of the C++11 thread_local because Apple's clang doesn't support thread_local yet.
10#define THREAD_LOCAL __thread
11#define DLL_EXPORT
12#define DLL_IMPORT
13#define FORCEINLINE inline __attribute__((always_inline))
14#define SUPPRESS_UNUSED(variable) (void)(variable);
15#define PACKED_STRUCT(definition) definition __attribute__((packed));
16
17#ifndef PLATFORM_API
18 #define PLATFORM_API DLL_IMPORT
19#endif
20
21namespace Platform
22{
23 // countLeadingZeroes/countTrailingZeroes returns the number of leading/trailing zeroes, or the bit width of the input if no bits are set.
24 // __builtin_clz/__builtin_ctz are undefined if the input is 0.
25 inline U64 countLeadingZeroes(U64 value) { return value == 0 ? 64 : __builtin_clzll(value); }
26 inline U32 countLeadingZeroes(U32 value) { return value == 0 ? 32 : __builtin_clz(value); }
27 inline U64 countTrailingZeroes(U64 value) { return value == 0 ? 64 : __builtin_ctzll(value); }
28 inline U32 countTrailingZeroes(U32 value) { return value == 0 ? 32 : __builtin_ctz(value); }
29 inline U64 floorLogTwo(U64 value) { return value <= 1 ? 0 : 63 - countLeadingZeroes(value); }
30 inline U32 floorLogTwo(U32 value) { return value <= 1 ? 0 : 31 - countLeadingZeroes(value); }
31 inline U64 ceilLogTwo(U64 value) { return floorLogTwo(value * 2 - 1); }
32 inline U32 ceilLogTwo(U32 value) { return floorLogTwo(value * 2 - 1); }
33}
uint64_t U64
Definition BasicTypes.h:11
uint32_t U32
Definition BasicTypes.h:9
U64 countTrailingZeroes(U64 value)
Definition Platform.h:27
U64 countLeadingZeroes(U64 value)
Definition Platform.h:25
U64 floorLogTwo(U64 value)
Definition Platform.h:29
U64 ceilLogTwo(U64 value)
Definition Platform.h:31
#define value
Definition pkcs11.h:157