… | |
… | |
535 | ecb_function_ ecb_const int ecb_clz32 (uint32_t x) |
535 | ecb_function_ ecb_const int ecb_clz32 (uint32_t x) |
536 | { |
536 | { |
537 | #if 1400 <= _MSC_VER && (_M_IX86 || _M_X64 || _M_IA64 || _M_ARM) |
537 | #if 1400 <= _MSC_VER && (_M_IX86 || _M_X64 || _M_IA64 || _M_ARM) |
538 | unsigned long r; |
538 | unsigned long r; |
539 | _BitScanReverse (&r, x); |
539 | _BitScanReverse (&r, x); |
540 | return (int)r; |
540 | return 31 - (int)r; |
541 | #else |
541 | #else |
542 | |
542 | |
543 | /* Robert Harley's algorithm from comp.arch 1996-12-07 */ |
543 | /* Robert Harley's algorithm from comp.arch 1996-12-07 */ |
544 | /* This happens to return 32 for x == 0, but the API does not support this */ |
544 | /* This happens to return 32 for x == 0, but the API does not support this */ |
545 | |
545 | |
… | |
… | |
570 | ecb_function_ ecb_const int ecb_clz64 (uint64_t x) |
570 | ecb_function_ ecb_const int ecb_clz64 (uint64_t x) |
571 | { |
571 | { |
572 | #if 1400 <= _MSC_VER && (_M_X64 || _M_IA64 || _M_ARM) |
572 | #if 1400 <= _MSC_VER && (_M_X64 || _M_IA64 || _M_ARM) |
573 | unsigned long r; |
573 | unsigned long r; |
574 | _BitScanReverse64 (&r, x); |
574 | _BitScanReverse64 (&r, x); |
575 | return (int)r; |
575 | return 63 - (int)r; |
576 | #else |
576 | #else |
577 | uint32_t l = x >> 32; |
577 | uint32_t l = x >> 32; |
578 | int shift = l ? 0 : 32; |
578 | int shift = l ? 0 : 32; |
579 | return ecb_clz32 (l ? l : x) + shift; |
579 | return ecb_clz32 (l ? l : x) + shift; |
580 | #endif |
580 | #endif |