Function GetFirstBit

Summary

#include <include/EASTL/bitset.h>

(1) uint32_t GetFirstBit(uint8_t x)

(2) uint32_t GetFirstBit(uint16_t x)

(3) uint32_t GetFirstBit(uint32_t x)

(4) uint32_t GetFirstBit(uint64_t x)

Function overload

Synopsis

#include <include/EASTL/bitset.h>

uint32_t GetFirstBit(uint8_t x)

Description

No description yet.

Source

Lines 484-497 in include/EASTL/bitset.h.

inline uint32_t GetFirstBit(uint8_t x)
{
    if(x)
    {
        uint32_t n = 1;
        if((x & 0x0000000F) == 0) { n +=  4; x >>=  4; }
        if((x & 0x00000003) == 0) { n +=  2; x >>=  2; }
        return (uint32_t)(n - (x & 1));
    }
    return 8;
}

Synopsis

#include <include/EASTL/bitset.h>

uint32_t GetFirstBit(uint16_t x)

Description

No description yet.

Source

Lines 499-513 in include/EASTL/bitset.h.

inline uint32_t GetFirstBit(uint16_t x) // To do: Update this to use VC++ _BitScanForward, _BitScanForward64; GCC __builtin_ctz, __builtin_ctzl. VC++ __lzcnt16, __lzcnt, __lzcnt64 requires recent CPUs (2013+) and probably can't be used. http://en.wikipedia.org/wiki/Haswell_%28microarchitecture%29#New_features
{
    if(x)
    {
        uint32_t n = 1;
        if((x & 0x000000FF) == 0) { n +=  8; x >>=  8; }
        if((x & 0x0000000F) == 0) { n +=  4; x >>=  4; }
        if((x & 0x00000003) == 0) { n +=  2; x >>=  2; }
        return (uint32_t)(n - (x & 1));
    }
    return 16;
}

Synopsis

#include <include/EASTL/bitset.h>

uint32_t GetFirstBit(uint32_t x)

Description

No description yet.

Source

Lines 515-530 in include/EASTL/bitset.h.

inline uint32_t GetFirstBit(uint32_t x)
{
    if(x)
    {
        uint32_t n = 1;
        if((x & 0x0000FFFF) == 0) { n += 16; x >>= 16; }
        if((x & 0x000000FF) == 0) { n +=  8; x >>=  8; }
        if((x & 0x0000000F) == 0) { n +=  4; x >>=  4; }
        if((x & 0x00000003) == 0) { n +=  2; x >>=  2; }
        return (n - (x & 1));
    }
    return 32;
}

Synopsis

#include <include/EASTL/bitset.h>

uint32_t GetFirstBit(uint64_t x)

Description

No description yet.

Source

Lines 532-548 in include/EASTL/bitset.h.

inline uint32_t GetFirstBit(uint64_t x)
{
    if(x)
    {
        uint32_t n = 1;
        if((x & 0xFFFFFFFF) == 0) { n += 32; x >>= 32; }
        if((x & 0x0000FFFF) == 0) { n += 16; x >>= 16; }
        if((x & 0x000000FF) == 0) { n +=  8; x >>=  8; }
        if((x & 0x0000000F) == 0) { n +=  4; x >>=  4; }
        if((x & 0x00000003) == 0) { n +=  2; x >>=  2; }
        return (n - ((uint32_t)x & 1));
    }
    return 64;
}





Add Discussion as Guest

Log in