2006-04-13 20:47:06 +00:00
|
|
|
// This file has been modified from Ken Silverman's original release
|
2012-03-12 04:47:04 +00:00
|
|
|
// by Jonathon Fowler (jf@jonof.id.au)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __pragmas_h__
|
|
|
|
#define __pragmas_h__
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
#ifdef EXTERNC
|
2006-07-02 17:33:49 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-09-09 07:19:14 +00:00
|
|
|
#include <limits.h>
|
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
#define PRAGMA_FUNCS _scaler(1) _scaler(2) _scaler(3) _scaler(4)\
|
|
|
|
_scaler(5) _scaler(6) _scaler(7) _scaler(8)\
|
|
|
|
_scaler(9) _scaler(10) _scaler(11) _scaler(12)\
|
|
|
|
_scaler(13) _scaler(14) _scaler(15) _scaler(16)\
|
|
|
|
_scaler(17) _scaler(18) _scaler(19) _scaler(20)\
|
|
|
|
_scaler(21) _scaler(22) _scaler(23) _scaler(24)\
|
|
|
|
_scaler(25) _scaler(26) _scaler(27) _scaler(28)\
|
|
|
|
_scaler(29) _scaler(30) _scaler(31)
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
extern int32_t dmval;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-09-09 07:19:14 +00:00
|
|
|
// break the C version of divscale out from the others
|
|
|
|
// because asm version overflows in drawmapview()
|
|
|
|
|
|
|
|
#define qw(x) ((int64_t)(x)) // quadword cast
|
|
|
|
#define dw(x) ((int32_t)(x)) // doubleword cast
|
2014-09-30 04:04:53 +00:00
|
|
|
#define wo(x) ((int16_t)(x)) // word cast
|
2009-09-09 07:19:14 +00:00
|
|
|
#define by(x) ((uint8_t)(x)) // byte cast
|
|
|
|
|
2014-08-23 10:28:17 +00:00
|
|
|
// XXX: Only for testing on x86. Don't use from outside; it doesn't account for
|
|
|
|
// whether we're compiling for e.g. x86_64 which will never use asm anyway.
|
|
|
|
//#define USE_ASM_DIVSCALE
|
|
|
|
|
|
|
|
#if !defined USE_ASM_DIVSCALE
|
2012-05-01 12:37:32 +00:00
|
|
|
#ifdef GEKKO
|
|
|
|
#include <math.h>
|
|
|
|
static inline int32_t divscale(int32_t eax, int32_t ebx, int32_t ecx)
|
|
|
|
{
|
|
|
|
return ldexp(eax, ecx) / ebx;
|
|
|
|
}
|
|
|
|
|
|
|
|
# define _scaler(a) \
|
|
|
|
static inline int32_t divscale##a(int32_t eax, int32_t ebx) \
|
|
|
|
{ \
|
|
|
|
return divscale(eax, ebx, a); \
|
|
|
|
} \
|
|
|
|
|
|
|
|
#else
|
2014-09-30 04:04:53 +00:00
|
|
|
static inline int32_t divscale(int32_t eax, int32_t ebx, int32_t ecx) { return dw((qw(eax) << by(ecx)) / ebx); }
|
2012-05-01 12:37:32 +00:00
|
|
|
|
|
|
|
# define _scaler(a) \
|
2009-09-09 07:19:14 +00:00
|
|
|
static inline int32_t divscale##a(int32_t eax, int32_t ebx) \
|
|
|
|
{ \
|
2014-09-30 04:04:53 +00:00
|
|
|
return dw((qw(eax) << by(a)) / ebx); \
|
2009-09-09 07:19:14 +00:00
|
|
|
} \
|
|
|
|
|
2012-05-01 12:37:32 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
PRAGMA_FUNCS _scaler(32)
|
2009-09-09 07:19:14 +00:00
|
|
|
|
|
|
|
#undef _scaler
|
2014-08-23 10:28:17 +00:00
|
|
|
#endif // !defined USE_ASM_DIVSCALE
|
2009-09-09 07:19:14 +00:00
|
|
|
|
2012-05-01 12:37:32 +00:00
|
|
|
#if defined(__GNUC__) && defined(GEKKO)
|
|
|
|
|
|
|
|
// GCC Inline Assembler version (PowerPC)
|
2014-09-30 04:04:53 +00:00
|
|
|
#include "pragmas_ppc.h"
|
2012-05-01 12:37:32 +00:00
|
|
|
|
|
|
|
#elif defined(__GNUC__) && defined(__i386__) && !defined(NOASM)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-05-01 12:37:32 +00:00
|
|
|
// GCC Inline Assembler version (x86)
|
2014-09-30 04:04:53 +00:00
|
|
|
#include "pragmas_x86_gcc.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-07-09 02:29:48 +00:00
|
|
|
#elif defined(_MSC_VER) && !defined(NOASM) // __GNUC__
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// Microsoft C inline assembler
|
2014-09-30 04:04:53 +00:00
|
|
|
#include "pragmas_x86_msvc.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
#elif defined(__arm__) // _MSC_VER
|
2014-08-23 10:28:17 +00:00
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
// GCC Inline Assembler version (ARM)
|
|
|
|
#include "pragmas_arm.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
#else
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
//
|
|
|
|
// Generic C
|
|
|
|
//
|
|
|
|
|
|
|
|
#define _scaler(a) \
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t mulscale##a(int32_t eax, int32_t edx) \
|
2006-07-01 01:40:18 +00:00
|
|
|
{ \
|
2014-09-30 04:04:53 +00:00
|
|
|
return dw((qw(eax) * qw(edx)) >> by(a)); \
|
2006-07-01 01:40:18 +00:00
|
|
|
} \
|
|
|
|
\
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t dmulscale##a(int32_t eax, int32_t edx, int32_t esi, int32_t edi) \
|
2006-07-01 01:40:18 +00:00
|
|
|
{ \
|
2014-09-30 04:04:53 +00:00
|
|
|
return dw(((qw(eax) * qw(edx)) + (qw(esi) * qw(edi))) >> by(a)); \
|
2006-07-01 01:40:18 +00:00
|
|
|
} \
|
|
|
|
\
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t tmulscale##a(int32_t eax, int32_t edx, int32_t ebx, int32_t ecx, int32_t esi, int32_t edi) \
|
2006-07-01 01:40:18 +00:00
|
|
|
{ \
|
2014-09-30 04:04:53 +00:00
|
|
|
return dw(((qw(eax) * qw(edx)) + (qw(ebx) * qw(ecx)) + (qw(esi) * qw(edi))) >> by(a)); \
|
2006-07-01 01:40:18 +00:00
|
|
|
} \
|
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
PRAGMA_FUNCS _scaler(32)
|
|
|
|
|
|
|
|
#undef _scaler
|
2006-07-01 01:40:18 +00:00
|
|
|
|
|
|
|
static inline void swapchar(void* a, void* b) { char t = *((char*)b); *((char*)b) = *((char*)a); *((char*)a) = t; }
|
2009-01-09 09:29:17 +00:00
|
|
|
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*)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*)b) = *((int32_t*)a); *((int32_t*)a) = t; }
|
2009-09-09 07:19:14 +00:00
|
|
|
static inline void swap64bit(void* a, void* b) { int64_t t = *((int64_t*)b); *((int64_t*)b) = *((int64_t*)a); *((int64_t*)a) = t; }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
|
|
|
static inline char readpixel(void* s) { return (*((char*)(s))); }
|
|
|
|
static inline void drawpixel(void* s, char a) { *((char*)(s)) = a; }
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline void drawpixels(void* s, int16_t a) { *((int16_t*)(s)) = a; }
|
|
|
|
static inline void drawpixelses(void* s, int32_t a) { *((int32_t*)(s)) = a; }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t mul3(int32_t a) { return (a<<1)+a; }
|
|
|
|
static inline int32_t mul5(int32_t a) { return (a<<2)+a; }
|
|
|
|
static inline int32_t mul9(int32_t a) { return (a<<3)+a; }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t divmod(int32_t a, int32_t b) { uint32_t _a=(uint32_t)a, _b=(uint32_t)b; dmval = _a%_b; return _a/_b; }
|
|
|
|
static inline int32_t moddiv(int32_t a, int32_t b) { uint32_t _a=(uint32_t)a, _b=(uint32_t)b; dmval = _a/_b; return _a%_b; }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t klabs(int32_t a) { if (a < 0) return -a; return a; }
|
|
|
|
static inline int32_t ksgn(int32_t a) { if (a > 0) return 1; if (a < 0) return -1; return 0; }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t umin(int32_t a, int32_t b) { if ((uint32_t)a < (uint32_t)b) return a; return b; }
|
|
|
|
static inline int32_t umax(int32_t a, int32_t b) { if ((uint32_t)a < (uint32_t)b) return b; return a; }
|
|
|
|
static inline int32_t kmin(int32_t a, int32_t b) { if ((int32_t)a < (int32_t)b) return a; return b; }
|
|
|
|
static inline int32_t kmax(int32_t a, int32_t b) { if ((int32_t)a < (int32_t)b) return b; return a; }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static inline int32_t sqr(int32_t eax) { return (eax) * (eax); }
|
|
|
|
static inline int32_t scale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * qw(edx)) / qw(ecx)); }
|
|
|
|
static inline int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * qw(edx)) >> by(ecx)); }
|
|
|
|
static 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)); }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
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);
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void clearbuf(void* d, int32_t c, int32_t a);
|
2012-02-18 22:14:45 +00:00
|
|
|
void copybuf(const void* s, void* d, int32_t c);
|
2009-01-09 09:29:17 +00:00
|
|
|
void swapbuf4(void* a, void* b, int32_t c);
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void clearbufbyte(void *D, int32_t c, int32_t a);
|
2012-02-18 22:14:45 +00:00
|
|
|
void copybufbyte(const void *S, void *D, int32_t c);
|
|
|
|
void copybufreverse(const void *S, void *D, int32_t c);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
#undef qw
|
|
|
|
#undef dw
|
|
|
|
#undef wo
|
|
|
|
#undef by
|
|
|
|
|
2014-03-05 21:12:59 +00:00
|
|
|
static inline void swapbufreverse(void *s, void *d, int32_t c)
|
|
|
|
{
|
|
|
|
uint8_t *src = (uint8_t*)s, *dst = (uint8_t*)d;
|
|
|
|
while (c--) {
|
|
|
|
swapchar(dst++, src--);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
#ifdef EXTERNC
|
2006-07-02 17:33:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif // __pragmas_h__
|
|
|
|
|