mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-12 13:00:32 +00:00
Add EndianSwap function using platform intrinsics
This commit is contained in:
@@ -422,6 +422,7 @@ inline uint64_t CountLeadingZeroes(uint64_t value);
|
||||
// std::string
|
||||
// OS_DEBUG_BREAK() - instruction that debugbreaks the debugger - define instead of function to
|
||||
// preserve callstacks
|
||||
// EndianSwapXX() for XX = 16, 32, 64
|
||||
|
||||
#if ENABLED(RDOC_WIN32)
|
||||
#include "win32/win32_specific.h"
|
||||
@@ -430,3 +431,66 @@ inline uint64_t CountLeadingZeroes(uint64_t value);
|
||||
#else
|
||||
#error Undefined Platform!
|
||||
#endif
|
||||
|
||||
inline uint64_t EndianSwap(uint64_t t)
|
||||
{
|
||||
return EndianSwap64(t);
|
||||
}
|
||||
|
||||
inline uint32_t EndianSwap(uint32_t t)
|
||||
{
|
||||
return EndianSwap32(t);
|
||||
}
|
||||
|
||||
inline uint16_t EndianSwap(uint16_t t)
|
||||
{
|
||||
return EndianSwap16(t);
|
||||
}
|
||||
|
||||
inline int64_t EndianSwap(int64_t t)
|
||||
{
|
||||
return (int64_t)EndianSwap(uint64_t(t));
|
||||
}
|
||||
|
||||
inline int32_t EndianSwap(int32_t t)
|
||||
{
|
||||
return (int32_t)EndianSwap(uint32_t(t));
|
||||
}
|
||||
|
||||
inline int16_t EndianSwap(int16_t t)
|
||||
{
|
||||
return (int16_t)EndianSwap(uint16_t(t));
|
||||
}
|
||||
|
||||
inline double EndianSwap(double t)
|
||||
{
|
||||
uint64_t u;
|
||||
memcpy(&u, &t, sizeof(t));
|
||||
u = EndianSwap(u);
|
||||
memcpy(&t, &u, sizeof(t));
|
||||
return t;
|
||||
}
|
||||
|
||||
inline float EndianSwap(float t)
|
||||
{
|
||||
uint32_t u;
|
||||
memcpy(&u, &t, sizeof(t));
|
||||
u = EndianSwap(u);
|
||||
memcpy(&t, &u, sizeof(t));
|
||||
return t;
|
||||
}
|
||||
|
||||
inline char EndianSwap(char t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
inline byte EndianSwap(byte t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
inline bool EndianSwap(bool t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,21 @@
|
||||
|
||||
#define OS_DEBUG_BREAK() raise(SIGTRAP)
|
||||
|
||||
#if ENABLED(RDOC_APPLE)
|
||||
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define EndianSwap16(x) OSSwapInt16(x)
|
||||
#define EndianSwap32(x) OSSwapInt32(x)
|
||||
#define EndianSwap64(x) OSSwapInt64(x)
|
||||
|
||||
#else
|
||||
|
||||
#define EndianSwap16(x) __builtin_bswap16(x)
|
||||
#define EndianSwap32(x) __builtin_bswap32(x)
|
||||
#define EndianSwap64(x) __builtin_bswap64(x)
|
||||
|
||||
#endif
|
||||
|
||||
struct EmbeddedResourceType
|
||||
{
|
||||
EmbeddedResourceType(const unsigned char *b, int l) : base(b), len(l) {}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#define NOMINMAX
|
||||
|
||||
#include <intrin.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include "data/resource.h"
|
||||
|
||||
@@ -36,6 +37,10 @@
|
||||
|
||||
#define OS_DEBUG_BREAK() __debugbreak()
|
||||
|
||||
#define EndianSwap16(x) _byteswap_ushort(x)
|
||||
#define EndianSwap32(x) _byteswap_ulong(x)
|
||||
#define EndianSwap64(x) _byteswap_uint64(x)
|
||||
|
||||
#define EmbeddedResourceType int
|
||||
#define EmbeddedResource(filename) CONCAT(RESOURCE_, filename)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user