include/SDL_bits.h
changeset 11314 d66e1e9ab531
parent 10737 3406a0f8b041
child 11433 b5e2b88d5193
     1.1 --- a/include/SDL_bits.h	Thu Aug 17 20:47:16 2017 -0400
     1.2 +++ b/include/SDL_bits.h	Thu Aug 17 21:30:29 2017 -0400
     1.3 @@ -47,6 +47,16 @@
     1.4   *
     1.5   *  \return Index of the most significant bit, or -1 if the value is 0.
     1.6   */
     1.7 +#if defined(__WATCOMC__) && defined(__386__)
     1.8 +extern _inline int _SDL_clz_watcom (Uint32);
     1.9 +#pragma aux _SDL_clz_watcom = \
    1.10 +    "bsr eax, eax" \
    1.11 +    "xor eax, 31" \
    1.12 +    parm [eax] nomemory \
    1.13 +    value [eax] \
    1.14 +    modify exact [eax] nomemory;
    1.15 +#endif
    1.16 +
    1.17  SDL_FORCE_INLINE int
    1.18  SDL_MostSignificantBitIndex32(Uint32 x)
    1.19  {
    1.20 @@ -58,6 +68,11 @@
    1.21          return -1;
    1.22      }
    1.23      return 31 - __builtin_clz(x);
    1.24 +#elif defined(__WATCOMC__) && defined(__386__)
    1.25 +    if (x == 0) {
    1.26 +        return -1;
    1.27 +    }
    1.28 +    return 31 - _SDL_clz_watcom(x);
    1.29  #else
    1.30      /* Based off of Bit Twiddling Hacks by Sean Eron Anderson
    1.31       * <seander@cs.stanford.edu>, released in the public domain.