GteBitHacks.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 #include <cstdint>
12 
13 // Convenient macros for manipulating 64-bit integers.
14 #define GTE_I64(v) v##LL
15 #define GTE_U64(v) v##ULL
16 #define GTE_GET_LO_I64(v) (int32_t)((v) & 0x00000000ffffffffLL)
17 #define GTE_GET_HI_I64(v) (int32_t)(((v) >> 32) & 0x00000000ffffffffLL)
18 #define GTE_GET_LO_U64(v) (uint32_t)((v) & 0x00000000ffffffffULL)
19 #define GTE_GET_HI_U64(v) (uint32_t)(((v) >> 32) & 0x00000000ffffffffULL)
20 #define GTE_SET_LO_I64(v,lo) (((v) & 0xffffffff00000000LL) | (int64_t)(lo))
21 #define GTE_SET_HI_I64(v,hi) (((v) & 0x00000000ffffffffLL) | ((int64_t)(hi) << 32))
22 #define GTE_MAKE_I64(hi,lo) ((int64_t)(lo) | ((int64_t)(hi) << 32))
23 #define GTE_SET_LO_U64(v,lo) (((v) & 0xffffffff00000000ULL) | (uint64_t)(lo))
24 #define GTE_SET_HI_U64(v,hi) (((v) & 0x00000000ffffffffULL) | ((uint64_t)(hi) << 32))
25 #define GTE_MAKE_U64(hi,lo) ((uint64_t)(lo) | ((uint64_t)(hi) << 32))
26 
27 namespace gte
28 {
29 
30 GTE_IMPEXP bool IsPowerOfTwo(uint32_t value);
31 GTE_IMPEXP bool IsPowerOfTwo(int32_t value);
32 
33 GTE_IMPEXP uint32_t Log2OfPowerOfTwo(uint32_t powerOfTwo);
34 GTE_IMPEXP int32_t Log2OfPowerOfTwo(int32_t powerOfTwo);
35 
36 // Call these only for nonzero values. If value is zero, then GetLeadingBit
37 // and GetTrailingBit return zero.
38 GTE_IMPEXP int32_t GetLeadingBit(uint32_t value);
39 GTE_IMPEXP int32_t GetLeadingBit(int32_t value);
40 GTE_IMPEXP int32_t GetLeadingBit(uint64_t value);
41 GTE_IMPEXP int32_t GetLeadingBit(int64_t value);
42 GTE_IMPEXP int32_t GetTrailingBit(uint32_t value);
43 GTE_IMPEXP int32_t GetTrailingBit(int32_t value);
44 GTE_IMPEXP int32_t GetTrailingBit(uint64_t value);
45 GTE_IMPEXP int32_t GetTrailingBit(int64_t value);
46 
47 // Round up to a power of two. If input is zero, the return is 1. If input
48 // is larger than 2^{31}, the return is 2^{32}.
49 GTE_IMPEXP uint64_t RoundUpToPowerOfTwo(uint32_t value);
50 
51 // Round down to a power of two. If input is zero, the return is 0.
52 GTE_IMPEXP uint32_t RoundDownToPowerOfTwo(uint32_t value);
53 
54 }
GTE_IMPEXP int32_t GetTrailingBit(uint32_t value)
GTE_IMPEXP uint32_t RoundDownToPowerOfTwo(uint32_t value)
GTE_IMPEXP int32_t GetLeadingBit(uint32_t value)
Definition: GteBitHacks.cpp:61
GLsizei const GLfloat * value
Definition: glcorearb.h:819
GTE_IMPEXP bool IsPowerOfTwo(uint32_t value)
Definition: GteBitHacks.cpp:31
GTE_IMPEXP uint64_t RoundUpToPowerOfTwo(uint32_t value)
GTE_IMPEXP uint32_t Log2OfPowerOfTwo(uint32_t powerOfTwo)
Definition: GteBitHacks.cpp:41
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59