fix some endian macro bugs in new code from last merge

This commit is contained in:
zeromus 2016-08-17 02:51:45 -05:00
parent ae64d4659b
commit 41d26c6bd7
2 changed files with 16 additions and 142 deletions

View File

@ -19,6 +19,10 @@
#ifndef TYPES_HPP
#define TYPES_HPP
#include <retro_miscellaneous.h>
#include <retro_inline.h>
#include <math/fxp.h>
//analyze microsoft compilers
#ifdef _MSC_VER
#define HOST_WINDOWS
@ -156,14 +160,6 @@
#define _CDECL_
#endif
#ifndef INLINE
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
#define INLINE _inline
#else
#define INLINE inline
#endif
#endif
#ifndef FORCEINLINE
#if defined(_MSC_VER) || defined(__INTEL_COMPILER)
#define FORCEINLINE __forceinline
@ -314,20 +310,8 @@ typedef int desmume_BOOL;
#define FALSE 0
#endif
#ifdef __BIG_ENDIAN__
#ifndef WORDS_BIGENDIAN
#define WORDS_BIGENDIAN
#endif
#endif
#ifdef WORDS_BIGENDIAN
# define LOCAL_BE 1
#else
# define LOCAL_LE 1
#endif
/* little endian (ds' endianess) to local endianess convert macros */
#ifdef LOCAL_BE /* local arch is big endian */
#ifdef MSB_FIRST /* local arch is big endian */
# define LE_TO_LOCAL_16(x) ((((x)&0xff)<<8)|(((x)>>8)&0xff))
# define LE_TO_LOCAL_32(x) ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)>>8)&0xff00)|(((x)>>24)&0xff))
# define LE_TO_LOCAL_64(x) ((((x)&0xff)<<56)|(((x)&0xff00)<<40)|(((x)&0xff0000)<<24)|(((x)&0xff000000)<<8)|(((x)>>8)&0xff000000)|(((x)>>24)&0xff0000)|(((x)>>40)&0xff00)|(((x)>>56)&0xff))
@ -347,8 +331,6 @@ typedef int desmume_BOOL;
#define MB(x) ((x)*1024*1024)
#define KB(x) ((x)*1024)
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define CPU_STR(c) ((c==ARM9)?"ARM9":"ARM7")
typedef enum
{
@ -356,28 +338,6 @@ typedef enum
ARM7 = 1
} cpu_id_t;
///endian-flips count bytes. count should be even and nonzero.
inline void FlipByteOrder(u8 *src, u32 count)
{
u8 *start=src;
u8 *end=src+count-1;
if((count&1) || !count) return; /* This shouldn't happen. */
while(count--)
{
u8 tmp;
tmp=*end;
*end=*start;
*start=tmp;
end--;
start++;
}
}
inline u64 double_to_u64(double d) {
union {
u64 a;
@ -396,68 +356,6 @@ inline double u64_to_double(u64 u) {
return fuxor.b;
}
inline u32 float_to_u32(float f) {
union {
u32 a;
float b;
} fuxor;
fuxor.b = f;
return fuxor.a;
}
inline float u32_to_float(u32 u) {
union {
u32 a;
float b;
} fuxor;
fuxor.a = u;
return fuxor.b;
}
///stores a 32bit value into the provided byte array in guaranteed little endian form
inline void en32lsb(u8 *buf, u32 morp)
{
buf[0]=(u8)(morp);
buf[1]=(u8)(morp>>8);
buf[2]=(u8)(morp>>16);
buf[3]=(u8)(morp>>24);
}
inline void en16lsb(u8* buf, u16 morp)
{
buf[0]=(u8)morp;
buf[1]=(u8)(morp>>8);
}
///unpacks a 64bit little endian value from the provided byte array into host byte order
inline u64 de64lsb(u8 *morp)
{
return morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24)|((u64)morp[4]<<32)|((u64)morp[5]<<40)|((u64)morp[6]<<48)|((u64)morp[7]<<56);
}
///unpacks a 32bit little endian value from the provided byte array into host byte order
inline u32 de32lsb(u8 *morp)
{
return morp[0]|(morp[1]<<8)|(morp[2]<<16)|(morp[3]<<24);
}
///unpacks a 16bit little endian value from the provided byte array into host byte order
inline u16 de16lsb(u8 *morp)
{
return morp[0]|(morp[1]<<8);
}
#ifndef ARRAY_SIZE
//taken from winnt.h
extern "C++" // templates cannot be declared to have 'C' linkage
template <typename T, size_t N>
char (*BLAHBLAHBLAH( UNALIGNED T (&)[N] ))[N];
#define ARRAY_SIZE(A) (sizeof(*BLAHBLAHBLAH(A)))
#endif
//fairly standard for loop macros
#define MACRODO1(TRICK,TODO) { const size_t X = TRICK; TODO; }
#define MACRODO2(X,TODO) { MACRODO1((X),TODO) MACRODO1(((X)+1),TODO) }
@ -531,37 +429,13 @@ template<typename T> inline void reconstruct(T* t) {
new(t) T();
}
//-------------fixed point speedup macros
/* fixed point speedup macros */
#ifdef _MSC_VER
#include <intrin.h>
#endif
FORCEINLINE s64 fx32_mul(const s32 a, const s32 b)
FORCEINLINE s32 sfx32_shiftdown(const s64 a)
{
#ifdef _MSC_VER
return __emul(a,b);
#else
return ((s64)a)*((s64)b);
#endif
//TODO: replace me with direct calls to sfx32_shiftdown
return fx32_shiftdown(a);
}
FORCEINLINE s32 fx32_shiftdown(const s64 a)
{
#ifdef _MSC_VER
return (s32)__ll_rshift(a,12);
#else
return (s32)(a>>12);
#endif
}
FORCEINLINE s64 fx32_shiftup(const s32 a)
{
#ifdef _MSC_VER
return __ll_lshift(a,12);
#else
return ((s64)a)<<12;
#endif
}
#endif
#endif

View File

@ -106,20 +106,20 @@ extern CACHE_ALIGN u32 color_555_to_888[32768];
#define COLOR555TO6665_OPAQUE_SWAP_RB(col) (color_555_to_6665_opaque_swap_rb[(col)]) // Convert a 15-bit color to an opaque sparsely packed 32-bit color containing an RGBA6665 color with R and B components swapped
#define COLOR555TO666(col) (color_555_to_666[(col)]) // Convert a 15-bit color to a fully transparent sparsely packed 32-bit color containing an RGBA6665 color
#ifdef LOCAL_LE
#define COLOR555TO6665(col,alpha5) (((alpha5)<<24) | color_555_to_666[(col)]) // Convert a 15-bit color to a sparsely packed 32-bit color containing an RGBA6665 color with user-defined alpha, little-endian
#else
#ifdef MSB_FIRST
#define COLOR555TO6665(col,alpha5) ((alpha5) | color_555_to_666[(col)]) // Convert a 15-bit color to a sparsely packed 32-bit color containing an RGBA6665 color with user-defined alpha, big-endian
#else
#define COLOR555TO6665(col,alpha5) (((alpha5)<<24) | color_555_to_666[(col)]) // Convert a 15-bit color to a sparsely packed 32-bit color containing an RGBA6665 color with user-defined alpha, little-endian
#endif
#define COLOR555TO8888_OPAQUE(col) (color_555_to_8888_opaque[(col)]) // Convert a 15-bit color to an opaque 32-bit color
#define COLOR555TO8888_OPAQUE_SWAP_RB(col) (color_555_to_8888_opaque_swap_rb[(col)]) // Convert a 15-bit color to an opaque 32-bit color with R and B components swapped
#define COLOR555TO888(col) (color_555_to_888[(col)]) // Convert a 15-bit color to an opaque 24-bit color or a fully transparent 32-bit color
#ifdef LOCAL_LE
#define COLOR555TO8888(col,alpha8) (((alpha8)<<24) | color_555_to_888[(col)]) // Convert a 15-bit color to a 32-bit color with user-defined alpha, little-endian
#else
#ifdef MSB_FIRST
#define COLOR555TO8888(col,alpha8) ((alpha8) | color_555_to_888[(col)]) // Convert a 15-bit color to a 32-bit color with user-defined alpha, big-endian
#else
#define COLOR555TO8888(col,alpha8) (((alpha8)<<24) | color_555_to_888[(col)]) // Convert a 15-bit color to a 32-bit color with user-defined alpha, little-endian
#endif
//produce a 15bpp color from individual 5bit components