Replace uses of "swap64bit" where "swapdouble" is what is really meant. There is nothing in this to handle potential platforms where sizeof(double) != sizeof(int64_t)

git-svn-id: https://svn.eduke32.com/eduke32@5724 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2016-05-13 22:15:25 +00:00
parent 2d9f205c69
commit e33d010e1a
5 changed files with 33 additions and 12 deletions

View file

@ -204,6 +204,12 @@ FORCE_INLINE void swapfloat(void *a, void *b)
*((float *)b) = *((float *)a);
*((float *)a) = t;
}
FORCE_INLINE void swapdouble(void *a, void *b)
{
double const t = *((double *) b);
*((double *) b) = *((double *) a);
*((double *) a) = t;
}
FORCE_INLINE void swap64bit(void *a, void *b)
{
uint64_t const t = *((uint64_t *)b);
@ -216,7 +222,7 @@ FORCE_INLINE void drawpixel(void *s, char a) { *((char *)(s)) = a; }
FORCE_INLINE int32_t klabs(int32_t a)
{
const uint32_t m = a >> (sizeof(int) * CHAR_BIT - 1);
const uint32_t m = a >> (sizeof(uint32_t) * CHAR_BIT - 1);
return (a ^ m) - m;
}
FORCE_INLINE int32_t ksgn(int32_t a) { return (a > 0) - (a < 0); }

View file

@ -30,27 +30,33 @@ static inline void swapchar2(void *a, void *b, int32_t s)
}
static inline void swapshort(void *a, void *b)
{
int16_t t = *((int16_t *)b);
int16_t const t = *((int16_t *)b);
*((int16_t *)b) = *((int16_t *)a);
*((int16_t *)a) = t;
}
static inline void swaplong(void *a, void *b)
{
int32_t t = *((int32_t *)b);
int32_t const t = *((int32_t *)b);
*((int32_t *)b) = *((int32_t *)a);
*((int32_t *)a) = t;
}
static inline void swapfloat(void *a, void *b)
{
float t = *((float *)b);
float const t = *((float *)b);
*((float *)b) = *((float *)a);
*((float *)a) = t;
}
static inline void swapdouble(void *a, void *b)
{
double const t = *((double *) b);
*((double *) b) = *((double *) a);
*((double *) a) = t;
}
static inline void swap64bit(void *a, void *b)
{
int64_t t = *((int64_t *)b);
*((int64_t *)b) = *((int64_t *)a);
*((int64_t *)a) = t;
uint64_t const t = *((uint64_t *)b);
*((uint64_t *)b) = *((uint64_t *)a);
*((uint64_t *)a) = t;
}
static inline char readpixel(void *s) { return (*((char *)(s))); }
@ -58,7 +64,7 @@ static inline void drawpixel(void *s, char a) { *((char *)(s)) = a; }
static inline int32_t klabs(int32_t a)
{
const uint32_t m = a >> (sizeof(int32_t) * CHAR_BIT - 1);
const uint32_t m = a >> (sizeof(uint32_t) * CHAR_BIT - 1);
return (a ^ m) - m;
}
static inline int32_t ksgn(int32_t a) { return (a > 0) - (a < 0); }

View file

@ -235,11 +235,18 @@ static inline void swapfloat(void *a, void *b)
*(float*) b = t;
}
static inline void swapdouble(void *a, void *b)
{
double const t = *((double *) b);
*((double *) b) = *((double *) a);
*((double *) a) = t;
}
static inline void swap64bit(void *a, void *b)
{
double t = *(double*) a;
*(double*) a = *(double*) b;
*(double*) b = t;
uint64_t t = *(uint64_t*) a;
*(uint64_t*) a = *(uint64_t*) b;
*(uint64_t*) b = t;
}
static inline int32_t krecipasm(int32_t i)

View file

@ -512,7 +512,7 @@ void copybufreverse(const void *S, void *D, int32_t c);
"movl %%ecx, 4(%%ebx); movl %%edx, 4(%%eax)" \
: : "a" (__a), "b" (__b) : "ecx", "edx", "memory", "cc"); \
0; })
#define swapdouble swap64bit
//swapchar2(ptr1,ptr2,xsiz); is the same as:
//swapchar(ptr1,ptr2); swapchar(ptr1+1,ptr2+xsiz);
#define swapchar2(a,b,S) \

View file

@ -400,6 +400,8 @@ static __inline void swap64bit(void *a, void *b)
}
}
#define swapdouble swap64bit
//swapchar2(ptr1,ptr2,xsiz); is the same as:
//swapchar(ptr1,ptr2); swapchar(ptr1+1,ptr2+xsiz);
static __inline void swapchar2(void *a, void *b, int32_t s)