static inline UINT16 bsr64()

in MsCorePkg/Library/MathLib/MathLib.c [133:173]


static inline UINT16 bsr64(UINT64 value) {
#if __GNUC__ > 3 //if we are using GCC take advantage of their builtins
    return 64 - __builtin_clzl(value);

#elif _MSC_VER > 1500 //if we are using MS VS compiler 15 or greater
    unsigned long result;
    #if defined _M_X64
        //https://msdn.microsoft.com/en-us/library/fbxyd7zd.aspx
        //this will only work on ARM and x64
		_BitScanReverse64(&result, value);
		return (UINT16) result + 1;
    #else

		UINT32 valueLow = value & 0xffffffff;
		UINT32 valueHigh = value >> 32;
		//https://msdn.microsoft.com/en-us/library/fbxyd7zd.aspx
		// we split the operation up - first we check the upper bits and then check
		if (_BitScanReverse(&result, valueHigh)) {
			result += 32;
		} else {
			_BitScanReverse(&result, valueLow);
		}

		return (UINT16)result + 1;

    #endif
#else //this is our fallback
	UINT16 count = 1;
	UINT16 result = value;
	if (value == 0) {
		return 0;
	}

	while (count < 64 && value != 0x1) {
		value = value >> 1;
		//printf("Checking %x at %d\n",value,count);
		count++;
	}
	return count;
#endif
}