diff --git a/polymer/eduke32/build/include/pragmas.h b/polymer/eduke32/build/include/pragmas.h index ec3ef7780..66884954c 100644 --- a/polymer/eduke32/build/include/pragmas.h +++ b/polymer/eduke32/build/include/pragmas.h @@ -155,12 +155,14 @@ FORCE_INLINE int32_t sqr(int32_t a) { return a * a; } // GCC Inline Assembler version (ARM) #include "pragmas_arm.h" -#else +#endif // // Generic C // +#ifndef pragmas_have_mulscale + #define EDUKE32_SCALER_PRAGMA(a) \ FORCE_INLINE int32_t mulscale##a(int32_t eax, int32_t edx) { return dw((qw(eax) * edx) >> by(a)); } \ FORCE_INLINE int32_t dmulscale##a(int32_t eax, int32_t edx, int32_t esi, int32_t edi) \ @@ -172,6 +174,9 @@ EDUKE32_GENERATE_PRAGMAS EDUKE32_SCALER_PRAGMA(32) #undef EDUKE32_SCALER_PRAGMA +#endif + +#ifndef pragmas_have_swaps FORCE_INLINE void swapchar(void *a, void *b) { char const t = *(char *)b; @@ -213,34 +218,56 @@ FORCE_INLINE void swap64bit(void *a, void *b) *(uint64_t *)b = *(uint64_t *)a; *(uint64_t *)a = t; } +#endif FORCE_INLINE char readpixel(void *s) { return *(char *)s; } FORCE_INLINE void drawpixel(void *s, char a) { *(char *)s = a; } +#ifndef pragmas_have_klabs FORCE_INLINE int32_t klabs(int32_t a) { const uint32_t m = a >> (sizeof(uint32_t) * CHAR_BIT - 1); return (a ^ m) - m; } +#endif +#ifndef pragmas_have_ksgn FORCE_INLINE int32_t ksgn(int32_t a) { return (a > 0) - (a < 0); } +#endif +#ifndef pragmas_have_mulscale FORCE_INLINE int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * edx) >> by(ecx)); } FORCE_INLINE int32_t dmulscale(int32_t eax, int32_t edx, int32_t esi, int32_t edi, int32_t ecx) { return dw(((qw(eax) * edx) + (qw(esi) * edi)) >> by(ecx)); } +#endif +#ifndef pragmas_have_qinterpolatedown16 void qinterpolatedown16(intptr_t bufptr, int32_t num, int32_t val, int32_t add); void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t add); +#endif +#ifndef pragmas_have_clearbuf void clearbuf(void *d, int32_t c, int32_t a); +#endif +#ifndef pragmas_have_copybuf void copybuf(const void *s, void *d, int32_t c); +#endif +#ifndef pragmas_have_swaps void swapbuf4(void *a, void *b, int32_t c); +#endif +#ifndef pragmas_have_clearbufbyte void clearbufbyte(void *D, int32_t c, int32_t a); +#endif +#ifndef pragmas_have_copybufbyte void copybufbyte(const void *S, void *D, int32_t c); +#endif +#ifndef pragmas_have_copybufreverse void copybufreverse(const void *S, void *D, int32_t c); +#endif +#ifndef pragmas_have_krecipasm static inline int32_t krecipasm(int32_t i) { // Ken did this @@ -248,7 +275,6 @@ static inline int32_t krecipasm(int32_t i) i = *(int32_t const *)&f; return ((reciptable[(i >> 12) & 2047] >> (((i - 0x3f800000) >> 23) & 31)) ^ (i >> 31)); } - #endif #undef qw diff --git a/polymer/eduke32/build/include/pragmas_arm.h b/polymer/eduke32/build/include/pragmas_arm.h index 67cf42f85..c052687b8 100644 --- a/polymer/eduke32/build/include/pragmas_arm.h +++ b/polymer/eduke32/build/include/pragmas_arm.h @@ -5,91 +5,6 @@ #ifndef pragmas_arm_h_ #define pragmas_arm_h_ -#define EDUKE32_SCALER_PRAGMA(a) \ - FORCE_INLINE int32_t mulscale##a(int32_t eax, int32_t edx) { return dw((qw(eax) * edx) >> by(a)); } \ - FORCE_INLINE int32_t dmulscale##a(int32_t eax, int32_t edx, int32_t esi, int32_t edi) \ - { \ - return dw(((qw(eax) * edx) + (qw(esi) * edi)) >> by(a)); \ - } +// :( -EDUKE32_GENERATE_PRAGMAS EDUKE32_SCALER_PRAGMA(32) - -#undef EDUKE32_SCALER_PRAGMA - -FORCE_INLINE void swapchar(void *a, void *b) -{ - char t = *((char *)b); - *((char *)b) = *((char *)a); - *((char *)a) = t; -} -FORCE_INLINE void swapchar2(void *a, void *b, int32_t s) -{ - swapchar(a, b); - swapchar((char *)a + 1, (char *)b + s); -} -FORCE_INLINE void swapshort(void *a, void *b) -{ - int16_t const t = *((int16_t *)b); - *((int16_t *)b) = *((int16_t *)a); - *((int16_t *)a) = t; -} -FORCE_INLINE void swaplong(void *a, void *b) -{ - int32_t const t = *((int32_t *)b); - *((int32_t *)b) = *((int32_t *)a); - *((int32_t *)a) = t; -} -FORCE_INLINE void swapfloat(void *a, void *b) -{ - float const t = *((float *)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); - *((uint64_t *)b) = *((uint64_t *)a); - *((uint64_t *)a) = t; -} - -FORCE_INLINE char readpixel(void *s) { return (*((char *)(s))); } -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(uint32_t) * CHAR_BIT - 1); - return (a ^ m) - m; -} -FORCE_INLINE int32_t ksgn(int32_t a) { return (a > 0) - (a < 0); } - -FORCE_INLINE int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * qw(edx)) >> by(ecx)); } -FORCE_INLINE int32_t dmulscale(int32_t eax, int32_t edx, int32_t esi, int32_t edi, int32_t ecx) -{ - return dw(((qw(eax) * qw(edx)) + (qw(esi) * qw(edi))) >> by(ecx)); -} - -void qinterpolatedown16(intptr_t bufptr, int32_t num, int32_t val, int32_t add); -void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t add); - -void clearbuf(void *d, int32_t c, int32_t a); -void copybuf(const void *s, void *d, int32_t c); -void swapbuf4(void *a, void *b, int32_t c); - -void clearbufbyte(void *D, int32_t c, int32_t a); -void copybufbyte(const void *S, void *D, int32_t c); -void copybufreverse(const void *S, void *D, int32_t c); - -static inline int32_t krecipasm(int32_t i) -{ - // Ken did this - float const f = (float const)i; - i = *(int32_t const *)&f; - return ((reciptable[(i >> 12) & 2047] >> (((i - 0x3f800000) >> 23) & 31)) ^ (i >> 31)); -} #endif diff --git a/polymer/eduke32/build/include/pragmas_ppc.h b/polymer/eduke32/build/include/pragmas_ppc.h index e8cd1f254..4ac849c0a 100644 --- a/polymer/eduke32/build/include/pragmas_ppc.h +++ b/polymer/eduke32/build/include/pragmas_ppc.h @@ -4,6 +4,8 @@ #ifndef pragmas_ppc_h_ #define pragmas_ppc_h_ +#define pragmas_have_mulscale + #define EDUKE32_SCALER_PRAGMA(x) \ static inline int32_t mulscale##x(int32_t a, int32_t d) \ { \ @@ -104,73 +106,7 @@ static inline int32_t dmulscale32(int32_t a, int32_t d, int32_t S, int32_t D) return sumhi; } -static inline char readpixel(void *d) -{ - return *(char*) d; -} - -static inline void drawpixel(void *d, char a) -{ - *(char*) d = a; -} - -void clearbufbyte(void *d, int32_t c, int32_t a); - -static inline void clearbuf(void *d, int32_t c, int32_t a) -{ - int32_t *p = (int32_t*) d; - if (a==0) { - clearbufbyte(d, c<<2, 0); - return; - } - while (c--) { - *p++ = a; - } -} - -static inline void copybuf(void *s, void *d, int32_t c) -{ - int32_t *p = (int32_t*) s, *q = (int32_t*) d; - while (c--) { - *q++ = *p++; - } -} - -static inline void copybufbyte(void *s, void *d, int32_t c) -{ - uint8_t *src = (uint8_t*) s, *dst = (uint8_t*) d; - while (c--) { - *dst++ = *src++; - } -} - -static inline void copybufreverse(void *s, void *d, int32_t c) -{ - uint8_t *src = (uint8_t*) s, *dst = (uint8_t*) d; - while (c--) { - *dst++ = *src--; - } -} - -static inline void qinterpolatedown16(intptr_t bufptr, int32_t num, int32_t val, int32_t add) -{ - int i; - int32_t *lptr = (int32_t *) bufptr; - for (i=0; i>16); - val += add; - } -} - -static inline void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t add) -{ - int i; - int16_t *sptr = (int16_t *) bufptr; - for (i=0; i>16); - val += add; - } -} +#define pragmas_have_klabs static inline int32_t klabs(int32_t a) { @@ -186,6 +122,8 @@ static inline int32_t klabs(int32_t a) return a; } +#define pragmas_have_ksgn + static inline int32_t ksgn(int32_t a) { int32_t s, t; @@ -201,61 +139,5 @@ static inline int32_t ksgn(int32_t a) return s; } -static inline void swapchar(void *a, void *b) -{ - char t = *(char*) a; - *(char*) a = *(char*) b; - *(char*) b = t; -} - -static inline void swapchar2(void *a, void *b, int32_t s) -{ - swapchar(a, b); - swapchar((char*) a+1, (char*) b+s); -} - -static inline void swapshort(void *a, void *b) -{ - int16_t t = *(int16_t*) a; - *(int16_t*) a = *(int16_t*) b; - *(int16_t*) b = t; -} - -static inline void swaplong(void *a, void *b) -{ - int32_t t = *(int32_t*) a; - *(int32_t*) a = *(int32_t*) b; - *(int32_t*) b = t; -} - -static inline void swapfloat(void *a, void *b) -{ - float t = *(float*) a; - *(float*) a = *(float*) 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) -{ - uint64_t t = *(uint64_t*) a; - *(uint64_t*) a = *(uint64_t*) b; - *(uint64_t*) b = t; -} - -static inline int32_t krecipasm(int32_t i) -{ - // Ken did this - float const f = (float const)i; - i = *(int32_t const *)&f; - return ((reciptable[(i>>12)&2047]>>(((i-0x3f800000)>>23)&31))^(i>>31)); -} - #endif // pragmas_ppc_h_ #endif // pragmas_h_ diff --git a/polymer/eduke32/build/include/pragmas_x86_gcc.h b/polymer/eduke32/build/include/pragmas_x86_gcc.h index 37541be74..ee0ebee84 100644 --- a/polymer/eduke32/build/include/pragmas_x86_gcc.h +++ b/polymer/eduke32/build/include/pragmas_x86_gcc.h @@ -14,11 +14,7 @@ #define _DMVAL "_dmval" #endif - -// maybe one day I'll make these into macros -void clearbufbyte(void *D, int32_t c, int32_t a); -void copybufbyte(const void *S, void *D, int32_t c); -void copybufreverse(const void *S, void *D, int32_t c); +#define pragmas_have_mulscale #define mulscale(a,d,c) \ ({ int32_t __a=(a), __d=(d), __c=(c); \ @@ -451,31 +447,40 @@ void copybufreverse(const void *S, void *D, int32_t c); : "a" (__a), "d" (__d), "S" (__S), "D" (__D) : "ebx", "cc"); \ __d; }) -FORCE_INLINE char readpixel(void *s) { return *(char *)s; } -FORCE_INLINE void drawpixel(void *s, char a) { *(char *)s = a; } +#define pragmas_have_clearbuf #define clearbuf(D,c,a) \ ({ void *__D=(D); int32_t __c=(c), __a=(a); \ __asm__ __volatile__ ("rep; stosl" \ : "=&D" (__D), "=&c" (__c) : "0" (__D), "1" (__c), "a" (__a) : "memory", "cc"); \ 0; }) + +#define pragmas_have_copybuf + #define copybuf(S,D,c) \ ({ const void *__S=(S), *__D=(D); int32_t __c=(c); \ __asm__ __volatile__ ("rep; movsl" \ : "=&S" (__S), "=&D" (__D), "=&c" (__c) : "0" (__S), "1" (__D), "2" (__c) : "memory", "cc"); \ 0; }) +#define pragmas_have_klabs + #define klabs(a) \ ({ int32_t __a=(a); \ __asm__ __volatile__ ("testl %%eax, %%eax; jns 0f; negl %%eax; 0:" \ : "=a" (__a) : "a" (__a) : "cc"); \ __a; }) + +#define pragmas_have_ksgn + #define ksgn(b) \ ({ int32_t __b=(b), __r; \ __asm__ __volatile__ ("addl %%ebx, %%ebx; sbbl %%eax, %%eax; cmpl %%ebx, %%eax; adcb $0, %%al" \ : "=a" (__r) : "b" (__b) : "cc"); \ __r; }) +#define pragmas_have_swaps + #define swapchar(a,b) \ ({ void *__a=(a), *__b=(b); \ __asm__ __volatile__ ("movb (%%eax), %%cl; movb (%%ebx), %%ch; movb %%cl, (%%ebx); movb %%ch, (%%eax)" \ @@ -517,6 +522,8 @@ FORCE_INLINE void drawpixel(void *s, char a) { *(char *)s = a; } 0; }) +#define pragmas_have_qinterpolatedown16 + #define qinterpolatedown16(a,c,d,S) \ ({ void *__a=(void*)(a); int32_t __c=(c), __d=(d), __S=(S); \ __asm__ __volatile__ ("movl %%ecx, %%ebx; shrl $1, %%ecx; jz 1f; " \ @@ -543,6 +550,8 @@ FORCE_INLINE void drawpixel(void *s, char a) { *(char *)s = a; } : "ebx", "edi", "memory", "cc"); \ 0; }) +#define pragmas_have_krecipasm + #define krecipasm(a) \ ({ int32_t __a=(a); \ __asm__ __volatile__ ( \ diff --git a/polymer/eduke32/build/include/pragmas_x86_msvc.h b/polymer/eduke32/build/include/pragmas_x86_msvc.h index 6207da205..6904b1c1b 100644 --- a/polymer/eduke32/build/include/pragmas_x86_msvc.h +++ b/polymer/eduke32/build/include/pragmas_x86_msvc.h @@ -8,6 +8,8 @@ #ifndef pragmas_x86_h_ #define pragmas_x86_h_ +#define pragmas_have_mulscale + static __inline int32_t mulscale(int32_t a, int32_t d, int32_t c) { _asm { @@ -82,8 +84,7 @@ static __inline int32_t dmulscale32(int32_t a, int32_t d, int32_t S, int32_t D) } } -static __inline char readpixel(void *s) { return *(char *)s; } -static __inline void drawpixel(void *s, char a) { *(char *)s = a; } +#define pragmas_have_clearbuf static __inline void clearbuf(void *d, int32_t c, int32_t a) { @@ -95,6 +96,8 @@ static __inline void clearbuf(void *d, int32_t c, int32_t a) } } +#define pragmas_have_clearbufbyte + static __inline void clearbufbyte(void *d, int32_t c, int32_t a) { _asm { @@ -135,6 +138,8 @@ static __inline void clearbufbyte(void *d, int32_t c, int32_t a) } } +#define pragmas_have_copybuf + static __inline void copybuf(const void *s, void *d, int32_t c) { _asm { @@ -145,6 +150,8 @@ static __inline void copybuf(const void *s, void *d, int32_t c) } } +#define pragmas_have_copybufbyte + static __inline void copybufbyte(const void *s, void *d, int32_t c) { _asm { @@ -185,6 +192,8 @@ static __inline void copybufbyte(const void *s, void *d, int32_t c) } } +#define pragmas_have_copybufreverse + static __inline void copybufreverse(const void *s, void *d, int32_t c) { _asm { @@ -220,6 +229,8 @@ static __inline void copybufreverse(const void *s, void *d, int32_t c) } } +#define pragmas_have_qinterpolatedown16 + static __inline void qinterpolatedown16(int32_t a, int32_t c, int32_t d, int32_t s) { _asm { @@ -292,6 +303,8 @@ static __inline void qinterpolatedown16short(int32_t a, int32_t c, int32_t d, in } } +#define pragmas_have_klabs + static __inline int32_t klabs(int32_t a) { _asm { @@ -303,6 +316,8 @@ static __inline int32_t klabs(int32_t a) } } +#define pragmas_have_ksgn + static __inline int32_t ksgn(int32_t b) { _asm { @@ -314,6 +329,8 @@ static __inline int32_t ksgn(int32_t b) } } +#define pragmas_have_swaps + static __inline void swapchar(void *a, void *b) { _asm { @@ -406,6 +423,8 @@ static __inline void swapchar2(void *a, void *b, int32_t s) } } +#define pragmas_have_krecipasm + //0x007ff000 is (11<<13), 0x3f800000 is (127<<23) static inline int32_t krecipasm(int32_t a) { diff --git a/polymer/eduke32/build/src/pragmas.c b/polymer/eduke32/build/src/pragmas.c index 557c425ca..61b784fe6 100644 --- a/polymer/eduke32/build/src/pragmas.c +++ b/polymer/eduke32/build/src/pragmas.c @@ -41,6 +41,8 @@ int32_t dmval; #define ASM __asm__ __volatile__ +#define pragmas_have_clearbufbyte + void clearbufbyte(void *D, int32_t c, int32_t a) { ASM( @@ -82,6 +84,8 @@ void clearbufbyte(void *D, int32_t c, int32_t a) ); } +#define pragmas_have_copybufbyte + void copybufbyte(const void *S, void *D, int32_t c) { ASM( @@ -123,6 +127,8 @@ void copybufbyte(const void *S, void *D, int32_t c) ); } +#define pragmas_have_copybufreverse + void copybufreverse(const void *S, void *D, int32_t c) { ASM( @@ -165,6 +171,8 @@ void copybufreverse(const void *S, void *D, int32_t c) #elif defined(__GNUC__) && defined(GEKKO) +#define pragmas_have_clearbufbyte + void clearbufbyte(void *d, int32_t c, int32_t a) { if (a==0) { @@ -232,12 +240,13 @@ void clearbufbyte(void *d, int32_t c, int32_t a) ); } -#else +#endif // // Generic C version // +#ifndef pragmas_have_qinterpolatedown16 void qinterpolatedown16(intptr_t bufptr, int32_t num, int32_t val, int32_t add) { int32_t *lptr = (int32_t *)bufptr; @@ -257,7 +266,9 @@ void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t val += add; } } +#endif +#ifndef pragmas_have_clearbuf void clearbuf(void *d, int32_t c, int32_t a) { int32_t *p = (int32_t *)d; @@ -273,7 +284,9 @@ void clearbuf(void *d, int32_t c, int32_t a) while (c--) *p++ = a; } +#endif +#ifndef pragmas_have_copybuf void copybuf(const void *s, void *d, int32_t c) { const int32_t *p = (const int32_t *)s; @@ -282,7 +295,9 @@ void copybuf(const void *s, void *d, int32_t c) while (c--) *q++ = *p++; } +#endif +#ifndef pragmas_have_swaps void swapbuf4(void *a, void *b, int32_t c) { int32_t *p = (int32_t *)a, *q = (int32_t *)b; @@ -295,7 +310,9 @@ void swapbuf4(void *a, void *b, int32_t c) *(p++) = x; } } +#endif +#ifndef pragmas_have_clearbufbyte void clearbufbyte(void *D, int32_t c, int32_t a) { // Cringe City @@ -309,7 +326,9 @@ void clearbufbyte(void *D, int32_t c, int32_t a) z=(z+1)&3; } } +#endif +#ifndef pragmas_have_copybufbyte void copybufbyte(const void *s, void *d, int32_t c) { const char *src = (const char *)s; @@ -318,6 +337,7 @@ void copybufbyte(const void *s, void *d, int32_t c) while (c--) *dst++ = *src++; } +#endif // copybufreverse() is a special case: use the assembly version for GCC on x86 @@ -362,7 +382,7 @@ void copybufreverse(const void *S, void *D, int32_t c) : "eax", "memory", "cc" ); } -#else +#elif !defined pragmas_have_copybufreverse void copybufreverse(const void *s, void *d, int32_t c) { const char *src = (const char *)s; @@ -372,6 +392,3 @@ void copybufreverse(const void *s, void *d, int32_t c) *dst++ = *src--; } #endif - - -#endif