libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
endianness.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __cplusplus
4namespace Ship {
12enum class Endianness {
13 Little = 0,
14 Big = 1,
15
16#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || defined(__BIG_ENDIAN__)
17 Native = Big,
18#else
19 Native = Little,
20#endif
21};
22} // namespace Ship
23#endif
24
25#ifdef _MSC_VER
26#include <stdlib.h>
27
28#define BSWAP16 _byteswap_ushort
29#define BSWAP32 _byteswap_ulong
30#define BSWAP64 _byteswap_uint64
31
32#define BOMSWAP16 _byteswap_ushort
33#define BOMSWAP32 _byteswap_ulong
34#define BOMSWAP64 _byteswap_uint64
35
36#define BOMSWAP16_CONST(x) ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))
37#define BOMSWAP32_CONST(x) \
38 ((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000))
39#define BOMSWAP64_CONST(x) \
40 ((((x) >> 56) & 0x00000000000000FF) | (((x) >> 40) & 0x000000000000FF00) | (((x) >> 24) & 0x0000000000FF0000) | \
41 (((x) >> 8) & 0x00000000FF000000) | (((x) << 8) & 0x000000FF00000000) | (((x) << 24) & 0x0000FF0000000000) | \
42 (((x) << 40) & 0x00FF000000000000) | (((x) << 56) & 0xFF00000000000000))
43#else
44
45#define BSWAP16 __builtin_bswap16
46#define BSWAP32 __builtin_bswap32
47#define BSWAP64 __builtin_bswap64
48
49#define BOMSWAP16 __builtin_bswap16
50#define BOMSWAP32 __builtin_bswap32
51#define BOMSWAP64 __builtin_bswap64
52
53#define BOMSWAP16_CONST __builtin_bswap16
54#define BOMSWAP32_CONST __builtin_bswap32
55#define BOMSWAP64_CONST __builtin_bswap64
56#endif
57
58#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || defined(__BIG_ENDIAN__)
59#ifndef IS_BIGENDIAN
60#define IS_BIGENDIAN
61#endif
62#endif
63
64#ifdef IS_BIGENDIAN
65#define BE16SWAP(x) (x)
66#define BE32SWAP(x) (x)
67#define BE64SWAP(x) (x)
68#define LE16SWAP(x) BOMSWAP16(x)
69#define LE32SWAP(x) BOMSWAP32(x)
70#define LE64SWAP(x) BOMSWAP64(x)
71
72#define BE16SWAP_CONST(x) (x)
73#define BE32SWAP_CONST(x) (x)
74#define BE64SWAP_CONST(x) (x)
75#define LE16SWAP_CONST(x) BOMSWAP16_CONST(x)
76#define LE32SWAP_CONST(x) BOMSWAP32_CONST(x)
77#define LE64SWAP_CONST(x) BOMSWAP64_CONST(x)
78#else
79#define BE16SWAP(x) BOMSWAP16(x)
80#define BE32SWAP(x) BOMSWAP32(x)
81#define BE64SWAP(x) BOMSWAP64(x)
82#define LE16SWAP(x) (x)
83#define LE32SWAP(x) (x)
84#define LE64SWAP(x) (x)
85
86#define BE16SWAP_CONST(x) BOMSWAP16_CONST(x)
87#define BE32SWAP_CONST(x) BOMSWAP32_CONST(x)
88#define BE64SWAP_CONST(x) BOMSWAP64_CONST(x)
89#define LE16SWAP_CONST(x) (x)
90#define LE32SWAP_CONST(x) (x)
91#define LE64SWAP_CONST(x) (x)
92#endif
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
@ Little
Least-significant byte stored first.
@ Native
Platform is little-endian; Native resolves to Little.
@ Big
Most-significant byte stored first.