Skip to content

Commit

Permalink
added bswap and clz inline asm to dr_flac for Watcom builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Mar 15, 2021
1 parent fc4ea81 commit 194725b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/dr_flac.h
Expand Up @@ -884,6 +884,27 @@ drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterator* pIter,
#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
#define DRFLAC_HAS_BYTESWAP16_INTRINSIC
#endif
#elif defined(__WATCOMC__) && defined(__386__)
#define DRFLAC_HAS_BYTESWAP16_INTRINSIC
#define DRFLAC_HAS_BYTESWAP32_INTRINSIC
#define DRFLAC_HAS_BYTESWAP64_INTRINSIC
extern __inline drflac_uint16 _watcom_bswap16(drflac_uint16);
extern __inline drflac_uint32 _watcom_bswap32(drflac_uint32);
extern __inline drflac_uint64 _watcom_bswap64(drflac_uint64);
#pragma aux _watcom_bswap16 = \
"xchg al, ah" \
parm [ax] \
modify [ax];
#pragma aux _watcom_bswap32 = \
"bswap eax" \
parm [eax] \
modify [eax];
#pragma aux _watcom_bswap64 = \
"bswap eax" \
"bswap edx" \
"xchg eax,edx" \
parm [eax edx] \
modify [eax edx];
#endif


Expand Down Expand Up @@ -986,6 +1007,8 @@ static DRFLAC_INLINE drflac_uint16 drflac__swap_endian_uint16(drflac_uint16 n)
return _byteswap_ushort(n);
#elif defined(__GNUC__) || defined(__clang__)
return __builtin_bswap16(n);
#elif defined(__WATCOMC__) && defined(__386__)
return _watcom_bswap16(n);
#else
#error "This compiler does not support the byte swap intrinsic."
#endif
Expand All @@ -1002,6 +1025,8 @@ static DRFLAC_INLINE drflac_uint32 drflac__swap_endian_uint32(drflac_uint32 n)
return _byteswap_ulong(n);
#elif defined(__GNUC__) || defined(__clang__)
return __builtin_bswap32(n);
#elif defined(__WATCOMC__) && defined(__386__)
return _watcom_bswap32(n);
#else
#error "This compiler does not support the byte swap intrinsic."
#endif
Expand All @@ -1020,6 +1045,8 @@ static DRFLAC_INLINE drflac_uint64 drflac__swap_endian_uint64(drflac_uint64 n)
return _byteswap_uint64(n);
#elif defined(__GNUC__) || defined(__clang__)
return __builtin_bswap64(n);
#elif defined(__WATCOMC__) && defined(__386__)
return _watcom_bswap64(n);
#else
#error "This compiler does not support the byte swap intrinsic."
#endif
Expand Down Expand Up @@ -1769,6 +1796,9 @@ static drflac_bool32 drflac__find_and_seek_to_next_sync_code(drflac_bs* bs)
#if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(DRFLAC_X64) || defined(DRFLAC_X86))
#define DRFLAC_IMPLEMENT_CLZ_MSVC
#endif
#if defined(__WATCOMC__) && defined(__386__)
#define DRFLAC_IMPLEMENT_CLZ_WATCOM
#endif

static DRFLAC_INLINE drflac_uint32 drflac__clz_software(drflac_cache_t x)
{
Expand Down Expand Up @@ -1847,6 +1877,16 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz_msvc(drflac_cache_t x)
}
#endif

#ifdef DRFLAC_IMPLEMENT_CLZ_WATCOM
static __inline drflac_uint32 drflac__clz_watcom (drflac_uint32);
#pragma aux drflac__clz_watcom = \
"bsr eax, eax" \
"xor eax, 31" \
parm [eax] nomemory \
value [eax] \
modify exact [eax] nomemory;
#endif

static DRFLAC_INLINE drflac_uint32 drflac__clz(drflac_cache_t x)
{
// This function assumes at least one bit is set. Checking for 0 needs to be done at a higher level, outside this function.
Expand All @@ -1858,6 +1898,8 @@ static DRFLAC_INLINE drflac_uint32 drflac__clz(drflac_cache_t x)
{
#ifdef DRFLAC_IMPLEMENT_CLZ_MSVC
return drflac__clz_msvc(x);
#elif defined(DRFLAC_IMPLEMENT_CLZ_WATCOM)
return drflac__clz_watcom(x);
#else
return drflac__clz_software(x);
#endif
Expand Down

0 comments on commit 194725b

Please sign in to comment.