Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace RAPIDJSON_CLZLL with internal clzll #1660

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions include/rapidjson/internal/clzll.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
RAPIDJSON_NAMESPACE_BEGIN
namespace internal {

#if (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll)
#define RAPIDJSON_CLZLL __builtin_clzll
#else

inline uint32_t clzll(uint64_t x) {
// Passing 0 to __builtin_clzll is UB in GCC and results in an
// infinite loop in the software implementation.
Expand All @@ -52,7 +48,11 @@ inline uint32_t clzll(uint64_t x) {
#endif // _WIN64

return 63 - r;
#elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll)
// __builtin_clzll wrapper
return static_cast<uint32_t>(__builtin_clzll(x));
#else
// naive version
uint32_t r;
while (!(x & (static_cast<uint64_t>(1) << 63))) {
x <<= 1;
Expand All @@ -64,9 +64,8 @@ inline uint32_t clzll(uint64_t x) {
}

#define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll
#endif // (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll)

} // namespace internal
RAPIDJSON_NAMESPACE_END

#endif // RAPIDJSON_CLZLL_H_
#endif // RAPIDJSON_CLZLL_H_
2 changes: 1 addition & 1 deletion include/rapidjson/internal/diyfp.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct DiyFp {
}

DiyFp Normalize() const {
int s = static_cast<int>(RAPIDJSON_CLZLL(f));
int s = static_cast<int>(clzll(f));
return DiyFp(f << s, e - s);
}

Expand Down
20 changes: 10 additions & 10 deletions include/rapidjson/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,11 @@ inline const char *SkipWhitespace_SIMD(const char* p) {

if (low == 0) {
if (high != 0) {
uint32_t lz = RAPIDJSON_CLZLL(high);
uint32_t lz = internal::clzll(high);
return p + 8 + (lz >> 3);
}
} else {
uint32_t lz = RAPIDJSON_CLZLL(low);
uint32_t lz = internal::clzll(low);
return p + (lz >> 3);
}
}
Expand Down Expand Up @@ -486,11 +486,11 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {

if (low == 0) {
if (high != 0) {
uint32_t lz = RAPIDJSON_CLZLL(high);
uint32_t lz = internal::clzll(high);
return p + 8 + (lz >> 3);
}
} else {
uint32_t lz = RAPIDJSON_CLZLL(low);
uint32_t lz = internal::clzll(low);
return p + (lz >> 3);
}
}
Expand Down Expand Up @@ -1257,12 +1257,12 @@ class GenericReader {
bool escaped = false;
if (low == 0) {
if (high != 0) {
uint32_t lz = RAPIDJSON_CLZLL(high);
uint32_t lz = internal::clzll(high);
length = 8 + (lz >> 3);
escaped = true;
}
} else {
uint32_t lz = RAPIDJSON_CLZLL(low);
uint32_t lz = internal::clzll(low);
length = lz >> 3;
escaped = true;
}
Expand Down Expand Up @@ -1327,12 +1327,12 @@ class GenericReader {
bool escaped = false;
if (low == 0) {
if (high != 0) {
uint32_t lz = RAPIDJSON_CLZLL(high);
uint32_t lz = internal::clzll(high);
length = 8 + (lz >> 3);
escaped = true;
}
} else {
uint32_t lz = RAPIDJSON_CLZLL(low);
uint32_t lz = internal::clzll(low);
length = lz >> 3;
escaped = true;
}
Expand Down Expand Up @@ -1381,12 +1381,12 @@ class GenericReader {

if (low == 0) {
if (high != 0) {
uint32_t lz = RAPIDJSON_CLZLL(high);
uint32_t lz = internal::clzll(high);
p += 8 + (lz >> 3);
break;
}
} else {
uint32_t lz = RAPIDJSON_CLZLL(low);
uint32_t lz = internal::clzll(low);
p += lz >> 3;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions include/rapidjson/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,12 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
bool escaped = false;
if (low == 0) {
if (high != 0) {
uint32_t lz = RAPIDJSON_CLZLL(high);
uint32_t lz = internal::clzll(high);
len = 8 + (lz >> 3);
escaped = true;
}
} else {
uint32_t lz = RAPIDJSON_CLZLL(low);
uint32_t lz = internal::clzll(low);
len = lz >> 3;
escaped = true;
}
Expand Down