mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
Replace the bswap function used in kplib with B_SWAP32, and merge the 32-bit MSVC and GCC assembly into compat.h.
TODO: Review the value of the continued use of special cases of these swap functions, including the OS-based variants for BSD and OS X, and this assembly. git-svn-id: https://svn.eduke32.com/eduke32@5173 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
f141cc71f2
commit
5c4622a8ab
2 changed files with 28 additions and 47 deletions
|
@ -248,12 +248,12 @@
|
|||
# define B_LITTLE_ENDIAN 0
|
||||
# define B_BIG_ENDIAN 1
|
||||
# endif
|
||||
# define B_ENDIAN_C_INLINE 1
|
||||
# define B_USE_COMPAT_SWAP 1
|
||||
|
||||
#elif defined(GEKKO) || defined(__ANDROID__)
|
||||
# define B_LITTLE_ENDIAN 0
|
||||
# define B_BIG_ENDIAN 1
|
||||
# define B_ENDIAN_C_INLINE 1
|
||||
# define B_USE_COMPAT_SWAP 1
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
# include <machine/endian.h>
|
||||
|
@ -316,7 +316,7 @@
|
|||
# define B_LITTLE_ENDIAN 0
|
||||
# define B_BIG_ENDIAN 1
|
||||
# endif
|
||||
# define B_ENDIAN_C_INLINE 1
|
||||
# define B_USE_COMPAT_SWAP 1
|
||||
|
||||
#elif defined(__QNX__)
|
||||
# if defined __LITTLEENDIAN__
|
||||
|
@ -326,7 +326,7 @@
|
|||
# define B_LITTLE_ENDIAN 0
|
||||
# define B_BIG_ENDIAN 1
|
||||
# endif
|
||||
# define B_ENDIAN_C_INLINE 1
|
||||
# define B_USE_COMPAT_SWAP 1
|
||||
|
||||
#elif defined(__sun)
|
||||
# if defined _LITTLE_ENDIAN
|
||||
|
@ -336,12 +336,12 @@
|
|||
# define B_LITTLE_ENDIAN 0
|
||||
# define B_BIG_ENDIAN 1
|
||||
# endif
|
||||
# define B_ENDIAN_C_INLINE 1
|
||||
# define B_USE_COMPAT_SWAP 1
|
||||
|
||||
#elif defined(_WIN32) || defined(SKYOS) || defined(__SYLLABLE__)
|
||||
# define B_LITTLE_ENDIAN 1
|
||||
# define B_BIG_ENDIAN 0
|
||||
# define B_ENDIAN_C_INLINE 1
|
||||
# define B_USE_COMPAT_SWAP 1
|
||||
#endif
|
||||
|
||||
#if !defined(B_LITTLE_ENDIAN) || !defined(B_BIG_ENDIAN)
|
||||
|
@ -365,18 +365,30 @@ defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 ||
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined B_ENDIAN_X86_INLINE
|
||||
# if defined(_MSC_VER)
|
||||
// inline asm using bswap/xchg
|
||||
# elif defined(__GNUC__)
|
||||
// inline asm using bswap/xchg
|
||||
# endif
|
||||
#elif defined B_ENDIAN_C_INLINE
|
||||
#if defined B_USE_COMPAT_SWAP
|
||||
FORCE_INLINE uint16_t B_SWAP16(uint16_t s) { return (s >> 8) | (s << 8); }
|
||||
|
||||
# if !defined NOASM && defined __i386__ && defined _MSC_VER
|
||||
FORCE_INLINE uint32_t B_SWAP32(uint32_t a)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
mov eax, a
|
||||
bswap eax
|
||||
}
|
||||
}
|
||||
# elif !defined NOASM && defined __i386__ && defined __GNUC__
|
||||
FORCE_INLINE uint32_t B_SWAP32(uint32_t a)
|
||||
{
|
||||
__asm__ __volatile__("bswap %0" : "+r"(a) : : "cc");
|
||||
return a;
|
||||
}
|
||||
# else
|
||||
FORCE_INLINE uint32_t B_SWAP32(uint32_t l)
|
||||
{
|
||||
return ((l >> 8) & 0xff00) | ((l & 0xff00) << 8) | (l << 24) | (l >> 24);
|
||||
}
|
||||
# endif
|
||||
FORCE_INLINE uint64_t B_SWAP64(uint64_t l)
|
||||
{
|
||||
return (l >> 56) | ((l >> 40) & 0xff00) | ((l >> 24) & 0xff0000) | ((l >> 8) & 0xff000000) |
|
||||
|
|
|
@ -72,11 +72,6 @@ static __inline int32_t _lrotl(int32_t i, int sh)
|
|||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#if defined __clang__ && __clang_major__==3 && __clang_minor__==1
|
||||
// clang 3.1 SVN r149129, assertion failure with inline asm
|
||||
# define NOASM 1
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#undef _inline
|
||||
#define _inline inline
|
||||
|
@ -177,17 +172,6 @@ static uint8_t qhufbit0[1<<LOGQHUFSIZ0], qhufbit1[1<<LOGQHUFSIZ1];
|
|||
|
||||
#if defined(_MSC_VER) && !defined(NOASM)
|
||||
|
||||
#if B_BIG_ENDIAN == 1
|
||||
static _inline uint32_t bswap(uint32_t a)
|
||||
{
|
||||
_asm
|
||||
{
|
||||
mov eax, a
|
||||
bswap eax
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static _inline int32_t bitrev(int32_t b, int32_t c)
|
||||
{
|
||||
_asm
|
||||
|
@ -204,14 +188,6 @@ static _inline int32_t bitrev(int32_t b, int32_t c)
|
|||
|
||||
#elif defined(__GNUC__) && defined(__i386__) && !defined(NOASM)
|
||||
|
||||
#if B_BIG_ENDIAN == 1
|
||||
static inline uint32_t bswap(uint32_t a)
|
||||
{
|
||||
__asm__ __volatile__("bswap %0" : "+r"(a) : : "cc");
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int32_t bitrev(int32_t b, int32_t c)
|
||||
{
|
||||
int32_t a = 0;
|
||||
|
@ -223,13 +199,6 @@ static inline int32_t bitrev(int32_t b, int32_t c)
|
|||
|
||||
#else
|
||||
|
||||
#if B_BIG_ENDIAN == 1
|
||||
static inline uint32_t bswap(uint32_t a)
|
||||
{
|
||||
return(((a&0xff0000)>>8) + ((a&0xff00)<<8) + (a<<24) + (a>>24));
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline int32_t bitrev(int32_t b, int32_t c)
|
||||
{
|
||||
int32_t i, j;
|
||||
|
@ -1120,9 +1089,9 @@ static void initkpeg()
|
|||
#if B_BIG_ENDIAN == 1
|
||||
for (i=0; i<1024; i++)
|
||||
{
|
||||
colclip[i] = bswap(colclip[i]);
|
||||
colclipup8[i] = bswap(colclipup8[i]);
|
||||
colclipup16[i] = bswap(colclipup16[i]);
|
||||
colclip[i] = B_SWAP32(colclip[i]);
|
||||
colclipup8[i] = B_SWAP32(colclipup8[i]);
|
||||
colclipup16[i] = B_SWAP32(colclipup16[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue