Additional const and constexpr usage in compat.h and pragmas

git-svn-id: https://svn.eduke32.com/eduke32@7132 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-10-25 23:33:52 +00:00
parent fecbe7ad8b
commit e7798d12dc
4 changed files with 43 additions and 57 deletions

View file

@ -958,9 +958,9 @@ static FORCE_INLINE void B_BUF16(void * const buf, uint16_t const x) { *(uint16_
static FORCE_INLINE void B_BUF32(void * const buf, uint32_t const x) { *(uint32_t *) buf = x; }
static FORCE_INLINE void B_BUF64(void * const buf, uint64_t const x) { *(uint64_t *) buf = x; }
static FORCE_INLINE uint16_t B_UNBUF16(void const * const buf) { return *(uint16_t const *) buf; }
static FORCE_INLINE uint32_t B_UNBUF32(void const * const buf) { return *(uint32_t const *) buf; }
static FORCE_INLINE uint64_t B_UNBUF64(void const * const buf) { return *(uint64_t const *) buf; }
static FORCE_INLINE CONSTEXPR uint16_t B_UNBUF16(void const * const buf) { return *(uint16_t const *) buf; }
static FORCE_INLINE CONSTEXPR uint32_t B_UNBUF32(void const * const buf) { return *(uint32_t const *) buf; }
static FORCE_INLINE CONSTEXPR uint64_t B_UNBUF64(void const * const buf) { return *(uint64_t const *) buf; }
#else
static FORCE_INLINE void B_BUF16(void * const vbuf, uint16_t const x)
{
@ -1013,7 +1013,7 @@ static FORCE_INLINE uint64_t B_UNBUF64(void const * const vbuf)
////////// Abstract data operations //////////
#define ABSTRACT_DECL static FORCE_INLINE WARN_UNUSED_RESULT
#define ABSTRACT_DECL static FORCE_INLINE WARN_UNUSED_RESULT CONSTEXPR
#ifdef __cplusplus
template <typename T, typename X, typename Y> ABSTRACT_DECL T clamp(T in, X min, Y max) { return in <= (T) min ? (T) min : (in >= (T) max ? (T) max : in); }

View file

@ -19,7 +19,6 @@ extern "C" {
EDUKE32_SCALER_PRAGMA(25) EDUKE32_SCALER_PRAGMA(26) EDUKE32_SCALER_PRAGMA(27) EDUKE32_SCALER_PRAGMA(28) \
EDUKE32_SCALER_PRAGMA(29) EDUKE32_SCALER_PRAGMA(30) EDUKE32_SCALER_PRAGMA(31)
extern int32_t dmval;
#if !defined(NOASM) && defined __cplusplus
extern "C" {
#endif
@ -44,7 +43,7 @@ extern libdivide_s32_t divtable32[DIVTABLESIZE];
extern void initdivtables(void);
#if defined(__arm__) || defined(LIBDIVIDE_ALWAYS)
static inline uint32_t divideu32(uint32_t n, uint32_t d)
static inline uint32_t divideu32(uint32_t const n, uint32_t const d)
{
static libdivide_u32_t udiv;
static uint32_t lastd;
@ -57,11 +56,11 @@ skip:
return libdivide_u32_do(n, &udiv);
}
static inline int64_t tabledivide64(int64_t n, int32_t d)
static inline int64_t tabledivide64(int64_t const n, int32_t const d)
{
static libdivide_s64_t sdiv;
static int32_t lastd;
auto const dptr = ((unsigned)d < DIVTABLESIZE) ? (libdivide_s64_t *)&divtable64[d] : &sdiv;
auto *const dptr = ((unsigned)d < DIVTABLESIZE) ? &divtable64[d] : &sdiv;
if (d == lastd || dptr != &sdiv)
goto skip;
@ -71,11 +70,11 @@ skip:
return libdivide_s64_do(n, dptr);
}
static inline int32_t tabledivide32(int32_t n, int32_t d)
static inline int32_t tabledivide32(int32_t const n, int32_t const d)
{
static libdivide_s32_t sdiv;
static int32_t lastd;
auto const dptr = ((unsigned)d < DIVTABLESIZE) ? (libdivide_s32_t *)&divtable32[d] : &sdiv;
auto *const dptr = ((unsigned)d < DIVTABLESIZE) ? &divtable32[d] : &sdiv;
if (d == lastd || dptr != &sdiv)
goto skip;
@ -85,16 +84,16 @@ skip:
return libdivide_s32_do(n, dptr);
}
#else
static FORCE_INLINE uint32_t divideu32(uint32_t n, uint32_t d) { return n / d; }
static FORCE_INLINE CONSTEXPR uint32_t divideu32(uint32_t const n, uint32_t const d) { return n / d; }
static inline int64_t tabledivide64(int64_t n, int32_t d)
static inline int64_t tabledivide64(int64_t const n, int32_t const d)
{
return ((unsigned)d < DIVTABLESIZE) ? libdivide_s64_do(n, (libdivide_s64_t *)&divtable64[d]) : n / d;
return ((unsigned)d < DIVTABLESIZE) ? libdivide_s64_do(n, &divtable64[d]) : n / d;
}
static inline int32_t tabledivide32(int32_t n, int32_t d)
static inline int32_t tabledivide32(int32_t const n, int32_t const d)
{
return ((unsigned)d < DIVTABLESIZE) ? libdivide_s32_do(n, (libdivide_s32_t *)&divtable32[d]) : n / d;
return ((unsigned)d < DIVTABLESIZE) ? libdivide_s32_do(n, &divtable32[d]) : n / d;
}
#endif
@ -112,7 +111,7 @@ static inline int32_t divscale(int32_t eax, int32_t ebx, int32_t ecx)
}
#endif
#define EDUKE32_SCALER_PRAGMA(a) \
#define EDUKE32_SCALER_PRAGMA(a) \
static FORCE_INLINE int32_t divscale##a(int32_t eax, int32_t ebx) { return divscale(eax, ebx, a); }
EDUKE32_GENERATE_PRAGMAS EDUKE32_SCALER_PRAGMA(32)
#undef EDUKE32_SCALER_PRAGMA
@ -164,16 +163,16 @@ static FORCE_INLINE int32_t sqr(int32_t a) { return a * a; }
#ifndef pragmas_have_mulscale
#define EDUKE32_SCALER_PRAGMA(a) \
static FORCE_INLINE int32_t mulscale##a(int32_t eax, int32_t edx) { return dw((qw(eax) * edx) >> by(a)); } \
static 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)); \
} \
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) \
{ \
return dw(((qw(eax) * edx) + (qw(ebx) * ecx) + (qw(esi) * edi)) >> by(a)); \
} \
#define EDUKE32_SCALER_PRAGMA(a) \
static FORCE_INLINE CONSTEXPR int32_t mulscale##a(int32_t eax, int32_t edx) { return dw((qw(eax) * edx) >> by(a)); } \
static FORCE_INLINE CONSTEXPR 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)); \
} \
static FORCE_INLINE CONSTEXPR int32_t tmulscale##a(int32_t eax, int32_t edx, int32_t ebx, int32_t ecx, int32_t esi, int32_t edi) \
{ \
return dw(((qw(eax) * edx) + (qw(ebx) * ecx) + (qw(esi) * edi)) >> by(a)); \
}
EDUKE32_GENERATE_PRAGMAS EDUKE32_SCALER_PRAGMA(32)
@ -255,7 +254,7 @@ static FORCE_INLINE void swapchar2(void *a, void *b, int32_t s)
}
#endif
static FORCE_INLINE char readpixel(void *s) { return *(char *)s; }
static FORCE_INLINE CONSTEXPR char readpixel(void *s) { return *(char *)s; }
static FORCE_INLINE void drawpixel(void *s, char a) { *(char *)s = a; }
#ifndef pragmas_have_klabs
@ -266,12 +265,12 @@ static FORCE_INLINE int32_t klabs(int32_t a)
}
#endif
#ifndef pragmas_have_ksgn
static FORCE_INLINE int32_t ksgn(int32_t a) { return (a > 0) - (a < 0); }
static FORCE_INLINE CONSTEXPR int32_t ksgn(int32_t a) { return (a > 0) - (a < 0); }
#endif
#ifndef pragmas_have_mulscale
static FORCE_INLINE int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * edx) >> by(ecx)); }
static FORCE_INLINE int32_t dmulscale(int32_t eax, int32_t edx, int32_t esi, int32_t edi, int32_t ecx)
static FORCE_INLINE CONSTEXPR int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * edx) >> by(ecx)); }
static FORCE_INLINE CONSTEXPR 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));
}

View file

@ -8,12 +8,6 @@
#ifndef pragmas_x86_h_
#define pragmas_x86_h_
#ifndef UNDERSCORES
#define _DMVAL "dmval"
#else
#define _DMVAL "_dmval"
#endif
#define pragmas_have_mulscale
#define mulscale(a,d,c) \

View file

@ -15,15 +15,10 @@ libdivide_s32_t divtable32[DIVTABLESIZE];
void initdivtables(void)
{
libdivide_s64_t d;
libdivide_s32_t d32;
for (bssize_t i=1; i<DIVTABLESIZE; i++)
for (int i = 1; i < DIVTABLESIZE; ++i)
{
d = libdivide_s64_gen(i);
divtable64[i].magic = d.magic, divtable64[i].more = d.more;
d32 = libdivide_s32_gen(i);
divtable32[i].magic = d32.magic, divtable32[i].more = d32.more;
divtable64[i] = libdivide_s64_gen(i);
divtable32[i] = libdivide_s32_gen(i);
}
}
@ -31,8 +26,6 @@ uint32_t divideu32_noinline(uint32_t n, uint32_t d) { return divideu32(n, d); }
int32_t tabledivide32_noinline(int32_t n, int32_t d) { return tabledivide32(n, d); }
int64_t tabledivide64_noinline(int64_t n, int32_t d) { return tabledivide64(n, d); }
int32_t dmval;
#if defined(__GNUC__) && defined(__i386__) && !defined(NOASM) // NOASM
//
@ -289,8 +282,8 @@ void clearbuf(void *d, int32_t c, int32_t a)
#ifndef pragmas_have_copybuf
void copybuf(const void *s, void *d, int32_t c)
{
auto p = (const int32_t *) s;
auto q = (int32_t *) d;
auto *p = (const int32_t *) s;
auto *q = (int32_t *) d;
while (c--)
*q++ = *p++;
@ -300,8 +293,8 @@ void copybuf(const void *s, void *d, int32_t c)
#ifndef pragmas_have_swaps
void swapbuf4(void *a, void *b, int32_t c)
{
auto p = (int32_t *) a;
auto q = (int32_t *) b;
auto *p = (int32_t *) a;
auto *q = (int32_t *) b;
while ((c--) > 0)
{
@ -316,9 +309,9 @@ void swapbuf4(void *a, void *b, int32_t c)
void clearbufbyte(void *D, int32_t c, int32_t a)
{
// Cringe City
int32_t const m[4] = { 0xffl, 0xff00l, 0xff0000l, (int32_t)0xff000000l };
int32_t z = 0;
auto p = (char *)D;
constexpr int32_t m[4] = { 0xffl, 0xff00l, 0xff0000l, (int32_t)0xff000000l };
int z = 0;
auto *p = (char *)D;
while ((c--) > 0)
{
@ -331,8 +324,8 @@ void clearbufbyte(void *D, int32_t c, int32_t a)
#ifndef pragmas_have_copybufbyte
void copybufbyte(const void *s, void *d, int32_t c)
{
auto src = (const char *)s;
auto dst = (char *)d;
auto *src = (const char *)s;
auto *dst = (char *)d;
while (c--)
*dst++ = *src++;
@ -385,8 +378,8 @@ void copybufreverse(const void *S, void *D, int32_t c)
#elif !defined pragmas_have_copybufreverse
void copybufreverse(const void *s, void *d, int32_t c)
{
auto src = (const char *)s;
auto dst = (char *)d;
auto *src = (const char *)s;
auto *dst = (char *)d;
while (c--)
*dst++ = *src--;