clzll.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_CLZLL_H_
20 #define RAPIDJSON_CLZLL_H_
21 
22 #include "../rapidjson.h"
23 
24 #if defined(_MSC_VER)
25 #include <intrin.h>
26 #if defined(_WIN64)
27 #pragma intrinsic(_BitScanReverse64)
28 #else
29 #pragma intrinsic(_BitScanReverse)
30 #endif
31 #endif
32 
34 namespace internal {
35 
36 #if (defined(__GNUC__) && __GNUC__ >= 4) || \
37  RAPIDJSON_HAS_BUILTIN(__builtin_clzll)
38 #define RAPIDJSON_CLZLL __builtin_clzll
39 #else
40 
41 inline uint32_t clzll(uint64_t x) {
42  // Passing 0 to __builtin_clzll is UB in GCC and results in an
43  // infinite loop in the software implementation.
44  RAPIDJSON_ASSERT(x != 0);
45 
46 #if defined(_MSC_VER)
47  unsigned long r = 0;
48 #if defined(_WIN64)
49  _BitScanReverse64(&r, x);
50 #else
51  // Scan the high 32 bits.
52  if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32))) return 63 - (r + 32);
53 
54  // Scan the low 32 bits.
55  _BitScanReverse(&r, static_cast<uint32_t>(x & 0xFFFFFFFF));
56 #endif // _WIN64
57 
58  return 63 - r;
59 #else
60  uint32_t r;
61  while (!(x & (static_cast<uint64_t>(1) << 63))) {
62  x <<= 1;
63  ++r;
64  }
65 
66  return r;
67 #endif // _MSC_VER
68 }
69 
70 #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll
71 #endif // (defined(__GNUC__) && __GNUC__ >= 4) ||
72  // RAPIDJSON_HAS_BUILTIN(__builtin_clzll)
73 
74 } // namespace internal
76 
77 #endif // RAPIDJSON_CLZLL_H_
uint32_t clzll(uint64_t x)
Definition: clzll.h:41
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:433
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
unsigned int uint32_t
Definition: stdint.h:127
unsigned __int64 uint64_t
Definition: stdint.h:137


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:45