mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 11:10:47 +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_LITTLE_ENDIAN 0
|
||||||
# define B_BIG_ENDIAN 1
|
# define B_BIG_ENDIAN 1
|
||||||
# endif
|
# endif
|
||||||
# define B_ENDIAN_C_INLINE 1
|
# define B_USE_COMPAT_SWAP 1
|
||||||
|
|
||||||
#elif defined(GEKKO) || defined(__ANDROID__)
|
#elif defined(GEKKO) || defined(__ANDROID__)
|
||||||
# define B_LITTLE_ENDIAN 0
|
# define B_LITTLE_ENDIAN 0
|
||||||
# define B_BIG_ENDIAN 1
|
# define B_BIG_ENDIAN 1
|
||||||
# define B_ENDIAN_C_INLINE 1
|
# define B_USE_COMPAT_SWAP 1
|
||||||
|
|
||||||
#elif defined(__OpenBSD__)
|
#elif defined(__OpenBSD__)
|
||||||
# include <machine/endian.h>
|
# include <machine/endian.h>
|
||||||
|
@ -316,7 +316,7 @@
|
||||||
# define B_LITTLE_ENDIAN 0
|
# define B_LITTLE_ENDIAN 0
|
||||||
# define B_BIG_ENDIAN 1
|
# define B_BIG_ENDIAN 1
|
||||||
# endif
|
# endif
|
||||||
# define B_ENDIAN_C_INLINE 1
|
# define B_USE_COMPAT_SWAP 1
|
||||||
|
|
||||||
#elif defined(__QNX__)
|
#elif defined(__QNX__)
|
||||||
# if defined __LITTLEENDIAN__
|
# if defined __LITTLEENDIAN__
|
||||||
|
@ -326,7 +326,7 @@
|
||||||
# define B_LITTLE_ENDIAN 0
|
# define B_LITTLE_ENDIAN 0
|
||||||
# define B_BIG_ENDIAN 1
|
# define B_BIG_ENDIAN 1
|
||||||
# endif
|
# endif
|
||||||
# define B_ENDIAN_C_INLINE 1
|
# define B_USE_COMPAT_SWAP 1
|
||||||
|
|
||||||
#elif defined(__sun)
|
#elif defined(__sun)
|
||||||
# if defined _LITTLE_ENDIAN
|
# if defined _LITTLE_ENDIAN
|
||||||
|
@ -336,12 +336,12 @@
|
||||||
# define B_LITTLE_ENDIAN 0
|
# define B_LITTLE_ENDIAN 0
|
||||||
# define B_BIG_ENDIAN 1
|
# define B_BIG_ENDIAN 1
|
||||||
# endif
|
# endif
|
||||||
# define B_ENDIAN_C_INLINE 1
|
# define B_USE_COMPAT_SWAP 1
|
||||||
|
|
||||||
#elif defined(_WIN32) || defined(SKYOS) || defined(__SYLLABLE__)
|
#elif defined(_WIN32) || defined(SKYOS) || defined(__SYLLABLE__)
|
||||||
# define B_LITTLE_ENDIAN 1
|
# define B_LITTLE_ENDIAN 1
|
||||||
# define B_BIG_ENDIAN 0
|
# define B_BIG_ENDIAN 0
|
||||||
# define B_ENDIAN_C_INLINE 1
|
# define B_USE_COMPAT_SWAP 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(B_LITTLE_ENDIAN) || !defined(B_BIG_ENDIAN)
|
#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" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined B_ENDIAN_X86_INLINE
|
#if defined B_USE_COMPAT_SWAP
|
||||||
# if defined(_MSC_VER)
|
|
||||||
// inline asm using bswap/xchg
|
|
||||||
# elif defined(__GNUC__)
|
|
||||||
// inline asm using bswap/xchg
|
|
||||||
# endif
|
|
||||||
#elif defined B_ENDIAN_C_INLINE
|
|
||||||
FORCE_INLINE uint16_t B_SWAP16(uint16_t s) { return (s >> 8) | (s << 8); }
|
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)
|
FORCE_INLINE uint32_t B_SWAP32(uint32_t l)
|
||||||
{
|
{
|
||||||
return ((l >> 8) & 0xff00) | ((l & 0xff00) << 8) | (l << 24) | (l >> 24);
|
return ((l >> 8) & 0xff00) | ((l & 0xff00) << 8) | (l << 24) | (l >> 24);
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
FORCE_INLINE uint64_t B_SWAP64(uint64_t l)
|
FORCE_INLINE uint64_t B_SWAP64(uint64_t l)
|
||||||
{
|
{
|
||||||
return (l >> 56) | ((l >> 40) & 0xff00) | ((l >> 24) & 0xff0000) | ((l >> 8) & 0xff000000) |
|
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))
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||||
#endif
|
#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__)
|
#if defined(__GNUC__)
|
||||||
#undef _inline
|
#undef _inline
|
||||||
#define _inline inline
|
#define _inline inline
|
||||||
|
@ -177,17 +172,6 @@ static uint8_t qhufbit0[1<<LOGQHUFSIZ0], qhufbit1[1<<LOGQHUFSIZ1];
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(NOASM)
|
#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)
|
static _inline int32_t bitrev(int32_t b, int32_t c)
|
||||||
{
|
{
|
||||||
_asm
|
_asm
|
||||||
|
@ -204,14 +188,6 @@ static _inline int32_t bitrev(int32_t b, int32_t c)
|
||||||
|
|
||||||
#elif defined(__GNUC__) && defined(__i386__) && !defined(NOASM)
|
#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)
|
static inline int32_t bitrev(int32_t b, int32_t c)
|
||||||
{
|
{
|
||||||
int32_t a = 0;
|
int32_t a = 0;
|
||||||
|
@ -223,13 +199,6 @@ static inline int32_t bitrev(int32_t b, int32_t c)
|
||||||
|
|
||||||
#else
|
#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)
|
static inline int32_t bitrev(int32_t b, int32_t c)
|
||||||
{
|
{
|
||||||
int32_t i, j;
|
int32_t i, j;
|
||||||
|
@ -1120,9 +1089,9 @@ static void initkpeg()
|
||||||
#if B_BIG_ENDIAN == 1
|
#if B_BIG_ENDIAN == 1
|
||||||
for (i=0; i<1024; i++)
|
for (i=0; i<1024; i++)
|
||||||
{
|
{
|
||||||
colclip[i] = bswap(colclip[i]);
|
colclip[i] = B_SWAP32(colclip[i]);
|
||||||
colclipup8[i] = bswap(colclipup8[i]);
|
colclipup8[i] = B_SWAP32(colclipup8[i]);
|
||||||
colclipup16[i] = bswap(colclipup16[i]);
|
colclipup16[i] = B_SWAP32(colclipup16[i]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue