mirror of
https://github.com/holub/mame
synced 2025-07-01 08:18:59 +03:00
macros should be turned into constexpr or they can't be used in many situations they were previously use in
the silly _partialNN functions are necessary because MSVC doesn't support C++14 properly
This commit is contained in:
parent
8594237ba6
commit
6bf9f2fd9c
@ -122,23 +122,12 @@ using unicode_char = std::uint32_t;
|
|||||||
|
|
||||||
|
|
||||||
/* Concatenate/extract 32-bit halves of 64-bit values */
|
/* Concatenate/extract 32-bit halves of 64-bit values */
|
||||||
inline UINT64 concat_64(UINT32 hi, UINT32 lo)
|
constexpr UINT64 concat_64(UINT32 hi, UINT32 lo) { return (UINT64(hi) << 32) | UINT32(lo); }
|
||||||
{
|
constexpr UINT32 extract_64hi(UINT64 val) { return UINT32(val >> 32); }
|
||||||
return (UINT64(hi) << 32) | UINT32(lo);
|
constexpr UINT32 extract_64lo(UINT64 val) { return UINT32(val); }
|
||||||
}
|
|
||||||
|
|
||||||
inline UINT32 extract_64hi(UINT64 val)
|
|
||||||
{
|
|
||||||
return UINT32(val >> 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline UINT32 extract_64lo(UINT64 val)
|
|
||||||
{
|
|
||||||
return UINT32(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highly useful template for compile-time knowledge of an array size
|
// Highly useful template for compile-time knowledge of an array size
|
||||||
template <typename T, size_t N> constexpr inline size_t ARRAY_LENGTH(T (&)[N]) { return N;}
|
template <typename T, size_t N> constexpr size_t ARRAY_LENGTH(T (&)[N]) { return N;}
|
||||||
|
|
||||||
// For declaring an array of the same dimensions as another array (including multi-dimensional arrays)
|
// For declaring an array of the same dimensions as another array (including multi-dimensional arrays)
|
||||||
template <typename T, typename U> struct equivalent_array_or_type { typedef T type; };
|
template <typename T, typename U> struct equivalent_array_or_type { typedef T type; };
|
||||||
@ -150,28 +139,19 @@ template <typename T, typename U> using equivalent_array_t = typename equivalent
|
|||||||
#define EQUIVALENT_ARRAY(a, T) equivalent_array_t<T, std::remove_reference_t<decltype(a)> >
|
#define EQUIVALENT_ARRAY(a, T) equivalent_array_t<T, std::remove_reference_t<decltype(a)> >
|
||||||
|
|
||||||
/* Macros for normalizing data into big or little endian formats */
|
/* Macros for normalizing data into big or little endian formats */
|
||||||
inline UINT16 flipendian_int16( UINT16 val )
|
constexpr UINT16 flipendian_int16(UINT16 val) { return (val << 8) | (val >> 8); }
|
||||||
{
|
|
||||||
return (val << 8) | (val >> 8 );
|
|
||||||
}
|
|
||||||
|
|
||||||
inline UINT32 flipendian_int32( UINT32 val )
|
constexpr UINT32 flipendian_int32_partial16(UINT32 val) { return ((val << 8) & 0xFF00FF00U) | ((val >> 8) & 0x00FF00FFU); }
|
||||||
{
|
constexpr UINT32 flipendian_int32(UINT32 val) { return (flipendian_int32_partial16(val) << 16) | (flipendian_int32_partial16(val) >> 16); }
|
||||||
val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF );
|
|
||||||
return (val << 16) | (val >> 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline UINT64 flipendian_int64( UINT64 val )
|
constexpr UINT64 flipendian_int64_partial16(UINT64 val) { return ((val << 8) & U64(0xFF00FF00FF00FF00)) | ((val >> 8) & U64(0x00FF00FF00FF00FF)); }
|
||||||
{
|
constexpr UINT64 flipendian_int64_partial32(UINT64 val) { return ((flipendian_int64_partial16(val) << 16) & U64(0xFFFF0000FFFF0000)) | ((flipendian_int64_partial16(val) >> 16) & U64(0x0000FFFF0000FFFF)); }
|
||||||
val = ((val << 8) & U64(0xFF00FF00FF00FF00) ) | ((val >> 8) & U64(0x00FF00FF00FF00FF) );
|
constexpr UINT64 flipendian_int64(UINT64 val) { return (flipendian_int64_partial32(val) << 32) | (flipendian_int64_partial32(val) >> 32); }
|
||||||
val = ((val << 16) & U64(0xFFFF0000FFFF0000) ) | ((val >> 16) & U64(0x0000FFFF0000FFFF) );
|
|
||||||
return (val << 32) | (val >> 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef LSB_FIRST
|
#ifdef LSB_FIRST
|
||||||
#define BIG_ENDIANIZE_INT16(x) (flipendian_int16(x))
|
constexpr UINT16 BIG_ENDIANIZE_INT16(UINT16 x) { return flipendian_int16(x); }
|
||||||
#define BIG_ENDIANIZE_INT32(x) (flipendian_int32(x))
|
constexpr UINT32 BIG_ENDIANIZE_INT32(UINT32 x) { return flipendian_int32(x); }
|
||||||
#define BIG_ENDIANIZE_INT64(x) (flipendian_int64(x))
|
constexpr UINT64 BIG_ENDIANIZE_INT64(UINT64 x) { return flipendian_int64(x); }
|
||||||
#define LITTLE_ENDIANIZE_INT16(x) (x)
|
#define LITTLE_ENDIANIZE_INT16(x) (x)
|
||||||
#define LITTLE_ENDIANIZE_INT32(x) (x)
|
#define LITTLE_ENDIANIZE_INT32(x) (x)
|
||||||
#define LITTLE_ENDIANIZE_INT64(x) (x)
|
#define LITTLE_ENDIANIZE_INT64(x) (x)
|
||||||
@ -179,14 +159,14 @@ inline UINT64 flipendian_int64( UINT64 val )
|
|||||||
#define BIG_ENDIANIZE_INT16(x) (x)
|
#define BIG_ENDIANIZE_INT16(x) (x)
|
||||||
#define BIG_ENDIANIZE_INT32(x) (x)
|
#define BIG_ENDIANIZE_INT32(x) (x)
|
||||||
#define BIG_ENDIANIZE_INT64(x) (x)
|
#define BIG_ENDIANIZE_INT64(x) (x)
|
||||||
#define LITTLE_ENDIANIZE_INT16(x) (flipendian_int16(x))
|
constexpr UINT16 LITTLE_ENDIANIZE_INT16(UINT16 x) { return flipendian_int16(x); }
|
||||||
#define LITTLE_ENDIANIZE_INT32(x) (flipendian_int32(x))
|
constexpr UINT32 LITTLE_ENDIANIZE_INT32(UINT32 x) { return flipendian_int32(x); }
|
||||||
#define LITTLE_ENDIANIZE_INT64(x) (flipendian_int64(x))
|
constexpr UINT64 LITTLE_ENDIANIZE_INT64(UINT64 x) { return flipendian_int64(x); }
|
||||||
#endif /* LSB_FIRST */
|
#endif /* LSB_FIRST */
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
typedef ptrdiff_t ssize_t;
|
using ssize_t = std::make_signed_t<size_t>;
|
||||||
#if _MSC_VER == 1900 // VS2015
|
#if _MSC_VER == 1900 // VS2015
|
||||||
#define __LINE__Var 0
|
#define __LINE__Var 0
|
||||||
#endif // VS2015
|
#endif // VS2015
|
||||||
|
Loading…
Reference in New Issue
Block a user