hopefully speed up byte swaps

This commit is contained in:
Bill Currie 2007-05-26 23:18:46 +00:00 committed by Jeff Teunissen
parent 6884f97694
commit 201f01b66c
4 changed files with 52 additions and 33 deletions

View File

@ -76,12 +76,37 @@
extern qboolean bigendien;
short ShortSwap (short l);
short ShortNoSwap (short l);
int LongSwap (int l);
int LongNoSwap (int l);
float FloatSwap (float f);
float FloatNoSwap (float f);
short _ShortSwap (short l);
short _ShortNoSwap (short l);
int _LongSwap (int l);
int _LongNoSwap (int l);
float _FloatSwap (float f);
float _FloatNoSwap (float f);
#ifdef __GNUC__
#define ShortSwap(l) ({ uint16_t x = (uint16_t) (l); \
x = ( ((x >> 8) & 0xff) \
| ((x << 8) & 0xff00)); \
x; })
#define LongSwap(l) ({ uint32_t z = (uint32_t) (l); \
z = (ShortSwap (z >> 16)) | (ShortSwap (z) << 16); \
z; })
#define FloatSwap(l) ({ union { uint32_t i; float f; } y; \
y.f = (l); \
y.i = LongSwap (y.i); \
y.f; })
#else
#define ShortSwap(l) _ShortSwap (l)
#define LongSwap(l) _LongSwap (l)
#define FloatSwap(l) _FloatSwap (l)
#endif
#define ShortNoSwap(l) (l)
#define LongNoSwap(l) (l)
#define FloatNoSwap(l) (l)
// NOTE: these /always/ read and write /little/ endian entities.
struct QFile_s;

View File

@ -61,6 +61,15 @@ typedef struct {
cvar_t *snd_loadas8bit;
cvar_t *snd_interp;
static void
check_buffer_integrity (sfxbuffer_t *sc, int width, const char *func)
{
byte *x = sc->data + sc->length * width;
if (memcmp (x, "\xde\xad\xbe\xef", 4))
Sys_Error ("%s screwed the pooch %02x%02x%02x%02x", func,
x[0], x[1], x[2], x[3]);
}
void
SND_ResampleMono (sfxbuffer_t *sc, byte *data, int length, void *prev)
{
@ -195,12 +204,7 @@ general_Mono:
}
}
}
{
byte *x = sc->data + sc->length * outwidth;
if (memcmp (x, "\xde\xad\xbe\xef", 4))
Sys_Error ("SND_ResampleMono screwed the pooch %02x%02x%02x%02x",
x[0], x[1], x[2], x[3]);
}
check_buffer_integrity (sc, outwidth, __FUNCTION__);
}
void
@ -359,12 +363,7 @@ general_Stereo:
}
}
}
{
byte *x = sc->data + sc->length * outwidth * 2;
if (memcmp (x, "\xde\xad\xbe\xef", 4))
Sys_Error ("SND_ResampleStereo screwed the pooch %02x%02x%02x%02x",
x[0], x[1], x[2], x[3]);
}
check_buffer_integrity (sc, outwidth * 2, __FUNCTION__);
}
void
@ -429,10 +428,5 @@ SND_NoResampleStereo (sfxbuffer_t *sc, byte *data, int length, void *prev)
}
}
}
{
byte *x = sc->data + sc->length * outwidth * 2;
if (memcmp (x, "\xde\xad\xbe\xef", 4))
Sys_Error ("SND_ResampleStereo screwed the pooch %02x%02x%02x%02x",
x[0], x[1], x[2], x[3]);
}
check_buffer_integrity (sc, outwidth * 2, __FUNCTION__);
}

View File

@ -51,7 +51,7 @@ VISIBLE qboolean bigendien = true;;
VISIBLE short
ShortSwap (short l)
_ShortSwap (short l)
{
byte b1, b2;
@ -62,13 +62,13 @@ ShortSwap (short l)
}
VISIBLE short
ShortNoSwap (short l)
_ShortNoSwap (short l)
{
return l;
}
VISIBLE int
LongSwap (int l)
_LongSwap (int l)
{
byte b1, b2, b3, b4;
@ -81,13 +81,13 @@ LongSwap (int l)
}
VISIBLE int
LongNoSwap (int l)
_LongNoSwap (int l)
{
return l;
}
VISIBLE float
FloatSwap (float f)
_FloatSwap (float f)
{
union {
float f;
@ -103,7 +103,7 @@ FloatSwap (float f)
}
VISIBLE float
FloatNoSwap (float f)
_FloatNoSwap (float f)
{
return f;
}

View File

@ -499,9 +499,9 @@ WriteLBMfile (char *filename, byte *data, int width, int height, byte *palette)
memset (&basebmhd, 0, sizeof (basebmhd));
basebmhd.w = BigShort ((short) width);
basebmhd.h = BigShort ((short) height);
basebmhd.nPlanes = BigShort (8);
basebmhd.xAspect = BigShort (5);
basebmhd.yAspect = BigShort (6);
basebmhd.nPlanes = 8;
basebmhd.xAspect = 5;
basebmhd.yAspect = 6;
basebmhd.pageWidth = BigShort ((short) width);
basebmhd.pageHeight = BigShort ((short) height);