2018-11-05 07:28:01 +00:00
|
|
|
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
|
|
|
|
// Ken Silverman's official web site: "http://www.advsys.net/ken"
|
|
|
|
// See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
//
|
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)
|
2018-11-05 07:28:01 +00:00
|
|
|
// by the EDuke32 team (development@voidpoint.com)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2020-07-14 18:21:16 +00:00
|
|
|
#include "templates.h"
|
2014-11-22 12:32:56 +00:00
|
|
|
#ifndef pragmas_h_
|
|
|
|
#define pragmas_h_
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-02 17:33:49 +00:00
|
|
|
|
2019-06-25 11:28:37 +00:00
|
|
|
#define EDUKE32_GENERATE_PRAGMAS \
|
|
|
|
EDUKE32_SCALER_PRAGMA(1) EDUKE32_SCALER_PRAGMA(2) EDUKE32_SCALER_PRAGMA(3) EDUKE32_SCALER_PRAGMA(4) \
|
|
|
|
EDUKE32_SCALER_PRAGMA(5) EDUKE32_SCALER_PRAGMA(6) EDUKE32_SCALER_PRAGMA(7) EDUKE32_SCALER_PRAGMA(8) \
|
|
|
|
EDUKE32_SCALER_PRAGMA(9) EDUKE32_SCALER_PRAGMA(10) EDUKE32_SCALER_PRAGMA(11) EDUKE32_SCALER_PRAGMA(12) \
|
|
|
|
EDUKE32_SCALER_PRAGMA(13) EDUKE32_SCALER_PRAGMA(14) EDUKE32_SCALER_PRAGMA(15) EDUKE32_SCALER_PRAGMA(16) \
|
|
|
|
EDUKE32_SCALER_PRAGMA(17) EDUKE32_SCALER_PRAGMA(18) EDUKE32_SCALER_PRAGMA(19) EDUKE32_SCALER_PRAGMA(20) \
|
|
|
|
EDUKE32_SCALER_PRAGMA(21) EDUKE32_SCALER_PRAGMA(22) EDUKE32_SCALER_PRAGMA(23) EDUKE32_SCALER_PRAGMA(24) \
|
|
|
|
EDUKE32_SCALER_PRAGMA(25) EDUKE32_SCALER_PRAGMA(26) EDUKE32_SCALER_PRAGMA(27) EDUKE32_SCALER_PRAGMA(28) \
|
2020-08-02 12:28:17 +00:00
|
|
|
EDUKE32_SCALER_PRAGMA(29) EDUKE32_SCALER_PRAGMA(30) EDUKE32_SCALER_PRAGMA(31) EDUKE32_SCALER_PRAGMA(32)
|
2014-09-30 04:04:53 +00:00
|
|
|
|
2020-03-29 14:59:49 +00:00
|
|
|
extern int32_t reciptable[2048];
|
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()
|
|
|
|
|
2014-11-02 05:35:22 +00:00
|
|
|
#define qw(x) ((int64_t)(x)) // quadword cast
|
|
|
|
#define dw(x) ((int32_t)(x)) // doubleword cast
|
|
|
|
#define wo(x) ((int16_t)(x)) // word cast
|
|
|
|
#define by(x) ((uint8_t)(x)) // byte cast
|
2009-09-09 07:19:14 +00:00
|
|
|
|
2014-10-25 03:29:21 +00:00
|
|
|
#define DIVTABLESIZE 16384
|
2014-08-23 10:28:17 +00:00
|
|
|
|
2020-07-14 18:21:16 +00:00
|
|
|
static inline int32_t divscale(int32_t eax, int32_t ebx, int32_t ecx) { return (int64_t(eax) << ecx) / ebx; }
|
2020-08-02 12:28:17 +00:00
|
|
|
static inline double fdivscale(double eax, double ebx, int32_t ecx) { return (eax * (double)(qw(1) << ecx)) / ebx; }
|
2019-11-04 01:07:59 +00:00
|
|
|
|
2020-07-14 18:21:16 +00:00
|
|
|
static inline int64_t divscale64(int64_t eax, int64_t ebx, int64_t ecx) { return (eax << ecx) / ebx; }
|
2019-07-24 01:37:50 +00:00
|
|
|
|
2018-10-25 23:33:52 +00:00
|
|
|
#define EDUKE32_SCALER_PRAGMA(a) \
|
2020-08-02 12:28:17 +00:00
|
|
|
static FORCE_INLINE int32_t divscale##a(int32_t eax, int32_t ebx) { return divscale(eax, ebx, a); } \
|
|
|
|
static FORCE_INLINE double fdivscale##a(double eax, double ebx) { return fdivscale(eax, ebx, a); }
|
|
|
|
EDUKE32_GENERATE_PRAGMAS
|
2014-10-29 17:03:29 +00:00
|
|
|
#undef EDUKE32_SCALER_PRAGMA
|
2014-10-25 03:29:21 +00:00
|
|
|
|
|
|
|
static inline int32_t scale(int32_t eax, int32_t edx, int32_t ecx)
|
|
|
|
{
|
2020-07-14 18:21:16 +00:00
|
|
|
return int64_t(eax) * edx / ecx;
|
2017-07-29 20:39:53 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
//
|
|
|
|
// Generic C
|
|
|
|
//
|
|
|
|
|
2018-10-25 23:33:52 +00:00
|
|
|
#define EDUKE32_SCALER_PRAGMA(a) \
|
2020-09-04 19:24:48 +00:00
|
|
|
static FORCE_INLINE int32_t mulscale##a(int32_t eax, int32_t edx) { return dw((qw(eax) * edx) >> by(a)); } \
|
|
|
|
static FORCE_INLINE double fmulscale##a(double eax, double edx) { return (eax * edx) / (double)(qw(1) << a); } \
|
|
|
|
static FORCE_INLINE int32_t dmulscale##a(int32_t eax, int32_t edx, int32_t esi, int32_t edi) \
|
2018-10-25 23:33:52 +00:00
|
|
|
{ \
|
|
|
|
return dw(((qw(eax) * edx) + (qw(esi) * edi)) >> by(a)); \
|
|
|
|
} \
|
2020-09-04 19:24:48 +00:00
|
|
|
static FORCE_INLINE double fdmulscale##a(double eax, double edx, double esi, double edi) \
|
2020-08-02 12:28:17 +00:00
|
|
|
{ \
|
|
|
|
return ((eax * edx) + (esi * edi)) / (double)(qw(1) << a); \
|
|
|
|
} \
|
2020-09-04 19:24:48 +00:00
|
|
|
static FORCE_INLINE int32_t tmulscale##a(int32_t eax, int32_t edx, int32_t ebx, int32_t ecx, int32_t esi, int32_t edi) \
|
2018-10-25 23:33:52 +00:00
|
|
|
{ \
|
|
|
|
return dw(((qw(eax) * edx) + (qw(ebx) * ecx) + (qw(esi) * edi)) >> by(a)); \
|
2020-08-02 12:28:17 +00:00
|
|
|
} \
|
2020-09-04 19:24:48 +00:00
|
|
|
static FORCE_INLINE double ftmulscale##a(double eax, double edx, double ebx, double ecx, double esi, double edi) \
|
2020-08-02 12:28:17 +00:00
|
|
|
{ \
|
|
|
|
return ((eax * edx) + (ebx * ecx) + (esi * edi)) / (double)(qw(1) << a); \
|
2018-10-25 23:33:52 +00:00
|
|
|
}
|
2014-11-02 05:35:22 +00:00
|
|
|
|
2020-08-02 12:28:17 +00:00
|
|
|
EDUKE32_GENERATE_PRAGMAS
|
2014-09-30 04:04:53 +00:00
|
|
|
|
2014-10-29 17:03:29 +00:00
|
|
|
#undef EDUKE32_SCALER_PRAGMA
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2017-06-24 09:20:46 +00:00
|
|
|
|
2019-08-01 06:50:13 +00:00
|
|
|
#define klabs(x) abs(x)
|
2020-09-04 19:24:48 +00:00
|
|
|
static inline constexpr int ksgn(int32_t a) { return (a > 0) - (a < 0); }
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2020-05-08 22:34:48 +00:00
|
|
|
inline int sgn(int32_t a) { return (a > 0) - (a < 0); }
|
|
|
|
|
2020-09-04 19:24:48 +00:00
|
|
|
static inline int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * edx) >> by(ecx)); }
|
|
|
|
static inline double fmulscale(double eax, double edx, int32_t ecx) { return (eax * edx) / (double)(qw(1) << ecx); }
|
|
|
|
static inline int32_t dmulscale(int32_t eax, int32_t edx, int32_t esi, int32_t edi, int32_t ecx)
|
2014-11-02 05:35:22 +00:00
|
|
|
{
|
|
|
|
return dw(((qw(eax) * edx) + (qw(esi) * edi)) >> by(ecx));
|
|
|
|
}
|
2020-09-04 19:24:48 +00:00
|
|
|
static inline double fdmulscale(double eax, double edx, double esi, double edi, int32_t ecx)
|
2020-08-02 12:28:17 +00:00
|
|
|
{
|
|
|
|
return ((eax * edx) + (esi * edi)) / (double)(qw(1) << ecx);
|
|
|
|
}
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2014-10-25 03:30:38 +00:00
|
|
|
static inline int32_t krecipasm(int32_t i)
|
|
|
|
{
|
|
|
|
// Ken did this
|
2018-07-23 02:55:53 +00:00
|
|
|
union { int32_t i; float f; } x;
|
|
|
|
x.f = (float)i;
|
|
|
|
i = x.i;
|
2014-11-02 05:35:22 +00:00
|
|
|
return ((reciptable[(i >> 12) & 2047] >> (((i - 0x3f800000) >> 23) & 31)) ^ (i >> 31));
|
2014-10-25 03:30:38 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-09-30 04:04:53 +00:00
|
|
|
#undef qw
|
|
|
|
#undef dw
|
|
|
|
#undef wo
|
|
|
|
#undef by
|
|
|
|
|
2014-11-22 12:32:56 +00:00
|
|
|
#endif // pragmas_h_
|