mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-29 15:12:19 +00:00
Optimize endian routines when we know the endian at compile time.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5830 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
134de2cfb2
commit
2cf2247b84
6 changed files with 89 additions and 58 deletions
|
@ -8,13 +8,7 @@
|
||||||
|
|
||||||
#ifndef HAVE_CLIENT
|
#ifndef HAVE_CLIENT
|
||||||
//#define Con_Printf(f, ...)
|
//#define Con_Printf(f, ...)
|
||||||
//hope you're on a littleendian machine
|
float FloatSwap (float l)
|
||||||
#define LittleShort(s) s
|
|
||||||
#define LittleLong(s) s
|
|
||||||
#define LittleFloat(s) s
|
|
||||||
|
|
||||||
#define BigFloat(s) SwapFloat(s)
|
|
||||||
static float SwapFloat (float l)
|
|
||||||
{
|
{
|
||||||
union {qbyte b[4]; float f;} in, out;
|
union {qbyte b[4]; float f;} in, out;
|
||||||
in.f = l;
|
in.f = l;
|
||||||
|
|
|
@ -693,6 +693,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define FTE_LITTLE_ENDIAN
|
||||||
|
#elif defined(__BYTE_ORDER__)
|
||||||
|
#ifdef __ORDER_BIG_ENDIAN__
|
||||||
|
#if (__BYTE_ORDER__==__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__==__ORDER_BIG_ENDIAN__)
|
||||||
|
#define FTE_BIG_ENDIAN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifdef __ORDER_LITTLE_ENDIAN__
|
||||||
|
#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__==__ORDER_LITTLE_ENDIAN__)
|
||||||
|
#define FTE_LITTLE_ENDIAN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define VARGS __cdecl
|
#define VARGS __cdecl
|
||||||
#define MSVCDISABLEWARNINGS
|
#define MSVCDISABLEWARNINGS
|
||||||
|
|
|
@ -745,6 +745,7 @@ void deleetstring(char *result, const char *leet)
|
||||||
============================================================================
|
============================================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !defined(FTE_BIG_ENDIAN) && !defined(FTE_LITTLE_ENDIAN)
|
||||||
qboolean bigendian;
|
qboolean bigendian;
|
||||||
|
|
||||||
short (*BigShort) (short l);
|
short (*BigShort) (short l);
|
||||||
|
@ -754,39 +755,36 @@ int (*LittleLong) (int l);
|
||||||
float (*BigFloat) (float l);
|
float (*BigFloat) (float l);
|
||||||
float (*LittleFloat) (float l);
|
float (*LittleFloat) (float l);
|
||||||
|
|
||||||
|
static short ShortNoSwap (short l) { return l; }
|
||||||
|
static int LongNoSwap (int l) { return l; }
|
||||||
|
static qint64_t I64NoSwap (qint64_t l) { return l; }
|
||||||
|
static float FloatNoSwap (float f) { return f; }
|
||||||
|
#endif
|
||||||
|
|
||||||
short ShortSwap (short l)
|
short ShortSwap (short l)
|
||||||
{
|
{
|
||||||
qbyte b1,b2;
|
return ((l>> 8)&0x00ff)|
|
||||||
|
((l<< 8)&0xff00);
|
||||||
b1 = l&255;
|
|
||||||
b2 = (l>>8)&255;
|
|
||||||
|
|
||||||
return (b1<<8) + b2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static short ShortNoSwap (short l)
|
|
||||||
{
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LongSwap (int l)
|
int LongSwap (int l)
|
||||||
{
|
{
|
||||||
qbyte b1,b2,b3,b4;
|
return ((l>>24)&0x000000ff)|
|
||||||
|
((l>> 8)&0x0000ff00)|
|
||||||
b1 = l&255;
|
((l<< 8)&0x00ff0000)|
|
||||||
b2 = (l>>8)&255;
|
((l<<24)&0xff000000);
|
||||||
b3 = (l>>16)&255;
|
|
||||||
b4 = (l>>24)&255;
|
|
||||||
|
|
||||||
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
|
|
||||||
}
|
}
|
||||||
|
qint64_t I64Swap (qint64_t l)
|
||||||
static int LongNoSwap (int l)
|
|
||||||
{
|
{
|
||||||
return l;
|
return ((l>>56)& 0x000000ff)|
|
||||||
|
((l>>40)& 0x0000ff00)|
|
||||||
|
((l>>24)& 0x00ff0000)|
|
||||||
|
((l>> 8)& 0xff000000)|
|
||||||
|
((l<< 8)&0x000000ff00000000)|
|
||||||
|
((l<<24)&0x0000ff0000000000)|
|
||||||
|
((l<<40)&0x00ff000000000000)|
|
||||||
|
((l<<56)&0xff00000000000000);
|
||||||
}
|
}
|
||||||
|
float FloatSwap (float f)
|
||||||
static float FloatSwap (float f)
|
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -803,11 +801,6 @@ static float FloatSwap (float f)
|
||||||
return dat2.f;
|
return dat2.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float FloatNoSwap (float f)
|
|
||||||
{
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void COM_SwapLittleShortBlock (short *s, int size)
|
void COM_SwapLittleShortBlock (short *s, int size)
|
||||||
{
|
{
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
|
@ -6212,11 +6205,9 @@ COM_Init
|
||||||
*/
|
*/
|
||||||
void COM_Init (void)
|
void COM_Init (void)
|
||||||
{
|
{
|
||||||
qbyte swaptest[2] = {1,0};
|
#if !defined(FTE_BIG_ENDIAN) && !defined(FTE_LITTLE_ENDIAN)
|
||||||
|
|
||||||
wantquit = false;
|
|
||||||
|
|
||||||
// set the qbyte swapping variables in a portable manner
|
// set the qbyte swapping variables in a portable manner
|
||||||
|
qbyte swaptest[2] = {1,0};
|
||||||
if ( *(short *)swaptest == 1)
|
if ( *(short *)swaptest == 1)
|
||||||
{
|
{
|
||||||
bigendian = false;
|
bigendian = false;
|
||||||
|
@ -6237,6 +6228,9 @@ void COM_Init (void)
|
||||||
BigFloat = FloatNoSwap;
|
BigFloat = FloatNoSwap;
|
||||||
LittleFloat = FloatSwap;
|
LittleFloat = FloatSwap;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wantquit = false;
|
||||||
|
|
||||||
//random should be random from the start...
|
//random should be random from the start...
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
|
|
|
@ -232,27 +232,57 @@ void InsertLinkAfter (link_t *l, link_t *after);
|
||||||
#define Q_MAXSHORT ((short)0x7fff)
|
#define Q_MAXSHORT ((short)0x7fff)
|
||||||
#define Q_MAXINT ((int)0x7fffffff)
|
#define Q_MAXINT ((int)0x7fffffff)
|
||||||
#define Q_MAXLONG ((int)0x7fffffff)
|
#define Q_MAXLONG ((int)0x7fffffff)
|
||||||
#define Q_MAXFLOAT ((int)0x7fffffff)
|
//#define Q_MAXFLOAT ((int)0x7fffffff)
|
||||||
|
|
||||||
#define Q_MINCHAR ((char)0x80)
|
#define Q_MINCHAR ((char)0x80)
|
||||||
#define Q_MINSHORT ((short)0x8000)
|
#define Q_MINSHORT ((short)0x8000)
|
||||||
#define Q_MININT ((int)0x80000000)
|
#define Q_MININT ((int)0x80000000)
|
||||||
#define Q_MINLONG ((int)0x80000000)
|
#define Q_MINLONG ((int)0x80000000)
|
||||||
#define Q_MINFLOAT ((int)0x7fffffff)
|
//#define Q_MINFLOAT ((int)0x7fffffff)
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
|
#if defined(FTE_LITTLE_ENDIAN)
|
||||||
|
#define bigendian false
|
||||||
|
|
||||||
|
#define LittleShort(x) ((short)(x))
|
||||||
|
#define LittleLong(x) ((int)(x))
|
||||||
|
#define LittleI64(x) ((qint64_t)(x))
|
||||||
|
#define LittleFloat(x) ((float)(x))
|
||||||
|
|
||||||
|
#define BigShort(x) (ShortSwap(x))
|
||||||
|
#define BigLong(x) (LongSwap(x))
|
||||||
|
#define BigI64(x) (I64Swap(x))
|
||||||
|
#define BigFloat(x) (FloatSwap(x))
|
||||||
|
#elif defined(FTE_BIG_ENDIAN)
|
||||||
|
#define bigendian true
|
||||||
|
|
||||||
|
#define BigShort(x) ((short)(x))
|
||||||
|
#define BigLong(x) ((int)(x))
|
||||||
|
#define BigI64(x) ((qint64_t)(x))
|
||||||
|
#define BigFloat(x) ((float)(x))
|
||||||
|
|
||||||
|
#define LittleShort(x) (ShortSwap(x))
|
||||||
|
#define LittleLong(x) (LongSwap(x))
|
||||||
|
#define LittleI64(x) (I64Swap(x))
|
||||||
|
#define LittleFloat(x) (FloatSwap(x))
|
||||||
|
#else
|
||||||
extern qboolean bigendian;
|
extern qboolean bigendian;
|
||||||
|
|
||||||
extern short (*BigShort) (short l);
|
extern short (*BigShort) (short l);
|
||||||
extern short (*LittleShort) (short l);
|
extern short (*LittleShort) (short l);
|
||||||
extern int (*BigLong) (int l);
|
extern int (*BigLong) (int l);
|
||||||
extern int (*LittleLong) (int l);
|
extern int (*LittleLong) (int l);
|
||||||
|
extern qint64_t (*BigI64) (qint64_t l);
|
||||||
|
extern qint64_t (*LittleI64) (qint64_t l);
|
||||||
extern float (*BigFloat) (float l);
|
extern float (*BigFloat) (float l);
|
||||||
extern float (*LittleFloat) (float l);
|
extern float (*LittleFloat) (float l);
|
||||||
|
#endif
|
||||||
|
|
||||||
short ShortSwap (short l);
|
short ShortSwap (short l);
|
||||||
int LongSwap (int l);
|
int LongSwap (int l);
|
||||||
|
qint64_t I64Swap (qint64_t l);
|
||||||
|
float FloatSwap (float f);
|
||||||
|
|
||||||
void COM_CharBias (signed char *c, int size);
|
void COM_CharBias (signed char *c, int size);
|
||||||
void COM_SwapLittleShortBlock (short *s, int size);
|
void COM_SwapLittleShortBlock (short *s, int size);
|
||||||
|
|
|
@ -28,12 +28,12 @@ typedef struct
|
||||||
} SHA1_CTX;
|
} SHA1_CTX;
|
||||||
#define SHA1_DIGEST_SIZE 20
|
#define SHA1_DIGEST_SIZE 20
|
||||||
|
|
||||||
#define BigLong(l) (((unsigned char*)&l)[0]<<24) | (((unsigned char*)&l)[1]<<16) | (((unsigned char*)&l)[2]<<8) | (((unsigned char*)&l)[3]<<0)
|
#define ShaBigLong(l) (((unsigned char*)&l)[0]<<24) | (((unsigned char*)&l)[1]<<16) | (((unsigned char*)&l)[2]<<8) | (((unsigned char*)&l)[3]<<0)
|
||||||
|
|
||||||
|
|
||||||
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
|
||||||
|
|
||||||
#define blk0(i) (block->l[i] = BigLong(block->l[i]))
|
#define blk0(i) (block->l[i] = ShaBigLong(block->l[i]))
|
||||||
|
|
||||||
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
|
||||||
^block->l[(i+2)&15]^block->l[i&15],1))
|
^block->l[(i+2)&15]^block->l[i&15],1))
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#undef stderr
|
#undef stderr
|
||||||
#define stderr stdout
|
#define stderr stdout
|
||||||
|
|
||||||
#define LittleLong(s) s
|
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
Loading…
Reference in a new issue