summaryrefslogtreecommitdiff
path: root/include/SDL_bits.h
diff options
context:
space:
mode:
authorOzkan Sezer <sezeroz@gmail.com>2017-08-17 21:30:29 -0400
committerOzkan Sezer <sezeroz@gmail.com>2017-08-17 21:30:29 -0400
commit536e1ee7526a6d832d74ad6338f014ce30f4d8ba (patch)
tree7e692d65ce4bdc6adc140c3cf42894c0d91abf4e /include/SDL_bits.h
parent2225929c31bb523a6619623313fbda2365d27644 (diff)
downloadsdl-536e1ee7526a6d832d74ad6338f014ce30f4d8ba.tar.gz
SDL_bits.h: add __builtin_clz equivalent for Watcom/x86 as inline asm
Partially fixes Bugzilla #3758.
Diffstat (limited to 'include/SDL_bits.h')
-rw-r--r--include/SDL_bits.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/SDL_bits.h b/include/SDL_bits.h
index f12f2c9a1..60cedc414 100644
--- a/include/SDL_bits.h
+++ b/include/SDL_bits.h
@@ -47,6 +47,16 @@ extern "C" {
*
* \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_MostSignificantBitIndex32(Uint32 x)
{
@@ -58,6 +68,11 @@ SDL_MostSignificantBitIndex32(Uint32 x)
return -1;
}
return 31 - __builtin_clz(x);
+#elif defined(__WATCOMC__) && defined(__386__)
+ if (x == 0) {
+ return -1;
+ }
+ return 31 - _SDL_clz_watcom(x);
#else
/* Based off of Bit Twiddling Hacks by Sean Eron Anderson
* <seander@cs.stanford.edu>, released in the public domain.