mirror of https://github.com/encounter/SDL.git
SDL_bits.h: add __builtin_clz equivalent for Watcom/x86 as inline asm
Partially fixes Bugzilla #3758.
This commit is contained in:
parent
7a9b9e05e0
commit
eccbe366bc
|
@ -47,6 +47,16 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* \return Index of the most significant bit, or -1 if the value is 0.
|
* \return Index of the most significant bit, or -1 if the value is 0.
|
||||||
*/
|
*/
|
||||||
|
#if defined(__WATCOMC__) && defined(__386__)
|
||||||
|
extern _inline int _SDL_clz_watcom (Uint32);
|
||||||
|
#pragma aux _SDL_clz_watcom = \
|
||||||
|
"bsr eax, eax" \
|
||||||
|
"xor eax, 31" \
|
||||||
|
parm [eax] nomemory \
|
||||||
|
value [eax] \
|
||||||
|
modify exact [eax] nomemory;
|
||||||
|
#endif
|
||||||
|
|
||||||
SDL_FORCE_INLINE int
|
SDL_FORCE_INLINE int
|
||||||
SDL_MostSignificantBitIndex32(Uint32 x)
|
SDL_MostSignificantBitIndex32(Uint32 x)
|
||||||
{
|
{
|
||||||
|
@ -58,6 +68,11 @@ SDL_MostSignificantBitIndex32(Uint32 x)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 31 - __builtin_clz(x);
|
return 31 - __builtin_clz(x);
|
||||||
|
#elif defined(__WATCOMC__) && defined(__386__)
|
||||||
|
if (x == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 31 - _SDL_clz_watcom(x);
|
||||||
#else
|
#else
|
||||||
/* Based off of Bit Twiddling Hacks by Sean Eron Anderson
|
/* Based off of Bit Twiddling Hacks by Sean Eron Anderson
|
||||||
* <seander@cs.stanford.edu>, released in the public domain.
|
* <seander@cs.stanford.edu>, released in the public domain.
|
||||||
|
|
Loading…
Reference in New Issue