mirror of https://github.com/AxioDL/jbus.git
Make stuff constexpr
This commit is contained in:
parent
e61237209d
commit
8d356cb3da
|
@ -23,7 +23,7 @@ using u64 = uint64_t;
|
|||
|
||||
/* Type-sensitive byte swappers */
|
||||
template <typename T>
|
||||
static inline T bswap16(T val) {
|
||||
constexpr T bswap16(T val) {
|
||||
#if __GNUC__
|
||||
return __builtin_bswap16(val);
|
||||
#elif _WIN32
|
||||
|
@ -34,7 +34,7 @@ static inline T bswap16(T val) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static inline T bswap32(T val) {
|
||||
constexpr T bswap32(T val) {
|
||||
#if __GNUC__
|
||||
return __builtin_bswap32(val);
|
||||
#elif _WIN32
|
||||
|
@ -47,7 +47,7 @@ static inline T bswap32(T val) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static inline T bswap64(T val) {
|
||||
constexpr T bswap64(T val) {
|
||||
#if __GNUC__
|
||||
return __builtin_bswap64(val);
|
||||
#elif _WIN32
|
||||
|
@ -61,18 +61,18 @@ static inline T bswap64(T val) {
|
|||
}
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
static inline int16_t SBig(int16_t val) { return bswap16(val); }
|
||||
static inline uint16_t SBig(uint16_t val) { return bswap16(val); }
|
||||
static inline int32_t SBig(int32_t val) { return bswap32(val); }
|
||||
static inline uint32_t SBig(uint32_t val) { return bswap32(val); }
|
||||
static inline int64_t SBig(int64_t val) { return bswap64(val); }
|
||||
static inline uint64_t SBig(uint64_t val) { return bswap64(val); }
|
||||
inline float SBig(float val) {
|
||||
constexpr int16_t SBig(int16_t val) { return bswap16(val); }
|
||||
constexpr uint16_t SBig(uint16_t val) { return bswap16(val); }
|
||||
constexpr int32_t SBig(int32_t val) { return bswap32(val); }
|
||||
constexpr uint32_t SBig(uint32_t val) { return bswap32(val); }
|
||||
constexpr int64_t SBig(int64_t val) { return bswap64(val); }
|
||||
constexpr uint64_t SBig(uint64_t val) { return bswap64(val); }
|
||||
constexpr float SBig(float val) {
|
||||
union { float f; int32_t i; } uval1 = {val};
|
||||
union { int32_t i; float f; } uval2 = {bswap32(uval1.i)};
|
||||
return uval2.f;
|
||||
}
|
||||
inline double SBig(double val) {
|
||||
constexpr double SBig(double val) {
|
||||
union { double f; int64_t i; } uval1 = {val};
|
||||
union { int64_t i; double f; } uval2 = {bswap64(uval1.i)};
|
||||
return uval2.f;
|
||||
|
@ -81,29 +81,29 @@ inline double SBig(double val) {
|
|||
#define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
|
||||
#endif
|
||||
|
||||
static inline int16_t SLittle(int16_t val) { return val; }
|
||||
static inline uint16_t SLittle(uint16_t val) { return val; }
|
||||
static inline int32_t SLittle(int32_t val) { return val; }
|
||||
static inline uint32_t SLittle(uint32_t val) { return val; }
|
||||
static inline int64_t SLittle(int64_t val) { return val; }
|
||||
static inline uint64_t SLittle(uint64_t val) { return val; }
|
||||
static inline float SLittle(float val) { return val; }
|
||||
static inline double SLittle(double val) { return val; }
|
||||
constexpr int16_t SLittle(int16_t val) { return val; }
|
||||
constexpr uint16_t SLittle(uint16_t val) { return val; }
|
||||
constexpr int32_t SLittle(int32_t val) { return val; }
|
||||
constexpr uint32_t SLittle(uint32_t val) { return val; }
|
||||
constexpr int64_t SLittle(int64_t val) { return val; }
|
||||
constexpr uint64_t SLittle(uint64_t val) { return val; }
|
||||
constexpr float SLittle(float val) { return val; }
|
||||
constexpr double SLittle(double val) { return val; }
|
||||
#ifndef SLITTLE
|
||||
#define SLITTLE(q) (q)
|
||||
#endif
|
||||
#else
|
||||
static inline int16_t SLittle(int16_t val) { return bswap16(val); }
|
||||
static inline uint16_t SLittle(uint16_t val) { return bswap16(val); }
|
||||
static inline int32_t SLittle(int32_t val) { return bswap32(val); }
|
||||
static inline uint32_t SLittle(uint32_t val) { return bswap32(val); }
|
||||
static inline int64_t SLittle(int64_t val) { return bswap64(val); }
|
||||
static inline uint64_t SLittle(uint64_t val) { return bswap64(val); }
|
||||
static inline float SLittle(float val) {
|
||||
constexpr int16_t SLittle(int16_t val) { return bswap16(val); }
|
||||
constexpr uint16_t SLittle(uint16_t val) { return bswap16(val); }
|
||||
constexpr int32_t SLittle(int32_t val) { return bswap32(val); }
|
||||
constexpr uint32_t SLittle(uint32_t val) { return bswap32(val); }
|
||||
constexpr int64_t SLittle(int64_t val) { return bswap64(val); }
|
||||
constexpr uint64_t SLittle(uint64_t val) { return bswap64(val); }
|
||||
constexpr float SLittle(float val) {
|
||||
int32_t ival = bswap32(*((int32_t*)(&val)));
|
||||
return *((float*)(&ival));
|
||||
}
|
||||
static inline double SLittle(double val) {
|
||||
constexpr double SLittle(double val) {
|
||||
int64_t ival = bswap64(*((int64_t*)(&val)));
|
||||
return *((double*)(&ival));
|
||||
}
|
||||
|
@ -111,14 +111,14 @@ static inline double SLittle(double val) {
|
|||
#define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
|
||||
#endif
|
||||
|
||||
static inline int16_t SBig(int16_t val) { return val; }
|
||||
static inline uint16_t SBig(uint16_t val) { return val; }
|
||||
static inline int32_t SBig(int32_t val) { return val; }
|
||||
static inline uint32_t SBig(uint32_t val) { return val; }
|
||||
static inline int64_t SBig(int64_t val) { return val; }
|
||||
static inline uint64_t SBig(uint64_t val) { return val; }
|
||||
static inline float SBig(float val) { return val; }
|
||||
static inline double SBig(double val) { return val; }
|
||||
constexpr int16_t SBig(int16_t val) { return val; }
|
||||
constexpr uint16_t SBig(uint16_t val) { return val; }
|
||||
constexpr int32_t SBig(int32_t val) { return val; }
|
||||
constexpr uint32_t SBig(uint32_t val) { return val; }
|
||||
constexpr int64_t SBig(int64_t val) { return val; }
|
||||
constexpr uint64_t SBig(uint64_t val) { return val; }
|
||||
constexpr float SBig(float val) { return val; }
|
||||
constexpr double SBig(double val) { return val; }
|
||||
#ifndef SBIG
|
||||
#define SBIG(q) (q)
|
||||
#endif
|
||||
|
@ -162,7 +162,7 @@ void WaitGCTicks(u64 ticks);
|
|||
|
||||
/** @brief Obtain CPU ticks per second of Dolphin hardware (clock speed).
|
||||
* @return 486Mhz - always. */
|
||||
static constexpr u64 GetGCTicksPerSec() { return 486000000ull; }
|
||||
constexpr u64 GetGCTicksPerSec() { return 486000000ull; }
|
||||
|
||||
/** @brief Initialize platform specifics of JBus library */
|
||||
void Initialize();
|
||||
|
|
Loading…
Reference in New Issue