Skip to content

Commit ce81bc9

Browse files
authored
Merge pull request Tencent#1760 from escherstair/fix_ce6_support
fix _BitScanReverse() usage for CE6
2 parents f56928d + 5fbf8bf commit ce81bc9

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

include/rapidjson/internal/clzll.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "../rapidjson.h"
1919

20-
#if defined(_MSC_VER)
20+
#if defined(_MSC_VER) && !defined(UNDER_CE)
2121
#include <intrin.h>
2222
#if defined(_WIN64)
2323
#pragma intrinsic(_BitScanReverse64)
@@ -34,7 +34,7 @@ inline uint32_t clzll(uint64_t x) {
3434
// infinite loop in the software implementation.
3535
RAPIDJSON_ASSERT(x != 0);
3636

37-
#if defined(_MSC_VER)
37+
#if defined(_MSC_VER) && !defined(UNDER_CE)
3838
unsigned long r = 0;
3939
#if defined(_WIN64)
4040
_BitScanReverse64(&r, x);
@@ -53,7 +53,7 @@ inline uint32_t clzll(uint64_t x) {
5353
return static_cast<uint32_t>(__builtin_clzll(x));
5454
#else
5555
// naive version
56-
uint32_t r;
56+
uint32_t r = 0;
5757
while (!(x & (static_cast<uint64_t>(1) << 63))) {
5858
x <<= 1;
5959
++r;

test/unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include(CheckCXXCompilerFlag)
33
set(UNITTEST_SOURCES
44
allocatorstest.cpp
55
bigintegertest.cpp
6+
clzlltest.cpp
67
cursorstreamwrappertest.cpp
78
documenttest.cpp
89
dtoatest.cpp

test/unittest/clzlltest.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Tencent is pleased to support the open source community by making RapidJSON available.
2+
//
3+
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4+
//
5+
// Licensed under the MIT License (the "License"); you may not use this file except
6+
// in compliance with the License. You may obtain a copy of the License at
7+
//
8+
// http://opensource.org/licenses/MIT
9+
//
10+
// Unless required by applicable law or agreed to in writing, software distributed
11+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
// specific language governing permissions and limitations under the License.
14+
15+
#include "unittest.h"
16+
#include "rapidjson/internal/clzll.h"
17+
18+
#ifdef __GNUC__
19+
RAPIDJSON_DIAG_PUSH
20+
#endif
21+
22+
using namespace rapidjson::internal;
23+
24+
TEST(clzll, normal) {
25+
EXPECT_EQ(clzll(1), 63U);
26+
EXPECT_EQ(clzll(2), 62U);
27+
EXPECT_EQ(clzll(12), 60U);
28+
EXPECT_EQ(clzll(0x0000000080000001UL), 32U);
29+
EXPECT_EQ(clzll(0x8000000000000001UL), 0U);
30+
}
31+
32+
#ifdef __GNUC__
33+
RAPIDJSON_DIAG_POP
34+
#endif

0 commit comments

Comments
 (0)