quickjs-ng / quickjs

QuickJS, the Next Generation: a mighty JavaScript engine
MIT License
687 stars 66 forks source link

MSVC clz64 for x86 #430

Closed mekhontsev closed 2 weeks ago

mekhontsev commented 2 weeks ago

clz64 function for MSVC in cutils.h and tests/test_conv.c uses _BitScanReverse64 which is not defined for x86. I suggest to use the following implementation:

static inline int clz64(uint64_t a)
{
#if defined(_MSC_VER) && !defined(__clang__)
#if INTPTR_MAX == INT64_MAX
    unsigned long index;
    _BitScanReverse64(&index, a);
    return 63 - index;
#else
    if (a >> 32)
        return clz32((unsigned)(a >> 32));
    else
        return clz32((unsigned)a) + 32;
#endif  
#else
    return __builtin_clzll(a);
#endif
}

Similar fix: videolan project

saghul commented 2 weeks ago

Sounds good, can you send a PR?

startewho commented 2 weeks ago

i send a fix.https://github.com/quickjs-ng/quickjs/pull/435