Skip to content

Commit

Permalink
fix _BitScanReverse() usage for CE6
Browse files Browse the repository at this point in the history
  • Loading branch information
escherstair committed Aug 4, 2020
1 parent f56928d commit 6364c8e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion include/rapidjson/internal/clzll.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "../rapidjson.h"

#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(UNDER_CE)
#include <intrin.h>
#if defined(_WIN64)
#pragma intrinsic(_BitScanReverse64)
Expand All @@ -38,6 +38,27 @@ inline uint32_t clzll(uint64_t x) {
unsigned long r = 0;
#if defined(_WIN64)
_BitScanReverse64(&r, x);
#elif defined(UNDER_CE)
// Scan the high 32 bits.
uint32_t high = static_cast<uint32_t>(x >> 32);
if (high != 0)
{
unsigned long index = 31;
while((high & (1U<<index)) == 0)
{
--index;
}
return index;
}

// Scan the low 32 bits.
uint32_t low =static_cast<uint32_t>(x & 0xFFFFFFFF);
unsigned long index = 31;
while((low & (1U<<index)) == 0)
{
--index;
}
return index;
#else
// Scan the high 32 bits.
if (_BitScanReverse(&r, static_cast<uint32_t>(x >> 32)))
Expand Down

0 comments on commit 6364c8e

Please sign in to comment.