From e33d010e1a8748901685996e7b4ae30ba2a6ab5f Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 13 May 2016 22:15:25 +0000 Subject: [PATCH] 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 --- polymer/eduke32/build/include/pragmas.h | 8 +++++++- polymer/eduke32/build/include/pragmas_arm.h | 20 ++++++++++++------- polymer/eduke32/build/include/pragmas_ppc.h | 13 +++++++++--- .../eduke32/build/include/pragmas_x86_gcc.h | 2 +- .../eduke32/build/include/pragmas_x86_msvc.h | 2 ++ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/polymer/eduke32/build/include/pragmas.h b/polymer/eduke32/build/include/pragmas.h index 97b1c0df5..c61be75ba 100644 --- a/polymer/eduke32/build/include/pragmas.h +++ b/polymer/eduke32/build/include/pragmas.h @@ -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); } diff --git a/polymer/eduke32/build/include/pragmas_arm.h b/polymer/eduke32/build/include/pragmas_arm.h index bdab85add..2b69eef1c 100644 --- a/polymer/eduke32/build/include/pragmas_arm.h +++ b/polymer/eduke32/build/include/pragmas_arm.h @@ -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); } diff --git a/polymer/eduke32/build/include/pragmas_ppc.h b/polymer/eduke32/build/include/pragmas_ppc.h index 0b9c2f870..867622ea0 100644 --- a/polymer/eduke32/build/include/pragmas_ppc.h +++ b/polymer/eduke32/build/include/pragmas_ppc.h @@ -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) diff --git a/polymer/eduke32/build/include/pragmas_x86_gcc.h b/polymer/eduke32/build/include/pragmas_x86_gcc.h index 64cdeec72..64cc9f435 100644 --- a/polymer/eduke32/build/include/pragmas_x86_gcc.h +++ b/polymer/eduke32/build/include/pragmas_x86_gcc.h @@ -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) \ diff --git a/polymer/eduke32/build/include/pragmas_x86_msvc.h b/polymer/eduke32/build/include/pragmas_x86_msvc.h index 8a92fbe07..0eccdfe1b 100644 --- a/polymer/eduke32/build/include/pragmas_x86_msvc.h +++ b/polymer/eduke32/build/include/pragmas_x86_msvc.h @@ -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)