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