Polyphase Game Engine
Loading...
Searching...
No Matches
SystemConstants.h
Go to the documentation of this file.
1#pragma once
2
3// ENDIAN_SWAP — file format (asset .oct) is little-endian per editor-host
4// convention. Big-endian platforms (GameCube/Wii via libogc, N64, PS3/Cell
5// PPU) need to swap on read/write through Stream<T>. Enable for any platform
6// whose CPU is big-endian: the explicit platform list PLUS a compiler-detected
7// big-endian check (covers PS3, which is a POLYPHASE_PLATFORM_ADDON with no
8// Platform enum value). The `defined(__BYTE_ORDER__)` guard keeps MSVC (which
9// doesn't define it) on the little-endian default.
10#if PLATFORM_DOLPHIN || PLATFORM_N64 || \
11 (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
12#define ENDIAN_SWAP 1
13#else
14#define ENDIAN_SWAP 0
15#endif
16
17// POLYPHASE_THREAD_LOCAL — `thread_local`, except on targets with no threads.
18//
19// `thread_local` is not free: it requires the C runtime to establish a thread
20// pointer (r2 on PowerPC32, r13 on PPC64, %fs on x86-64) and an initialised
21// TLS block. A bare-metal SDK that never spawns threads generally does not
22// bother, and then the FIRST access to any thread_local dereferences an
23// uninitialised thread pointer.
24//
25// That is not hypothetical. On Xbox 360 (libxenon) there is no TLS setup
26// anywhere in the SDK -- its `_start` never touches r2 -- yet the ELF still
27// carries a PT_TLS segment for the engine's own thread_locals. Boot died
28// inside Widget::MarkDirty, whose depth guard is a `static thread_local`, on
29// the very first widget constructed. It cost a long bisect because the failure
30// is a silent memory fault with no diagnostic, and it affects real hardware
31// exactly as much as the emulator.
32//
33// On a platform where SYS_CreateThread cannot create a thread, a plain static
34// is semantically identical to a thread_local -- there is only ever one
35// thread -- so this degrades cleanly rather than disabling a safety check.
36//
37// Keep this list in sync with platforms whose SYS_CreateThread returns null.
38#if PLATFORM_XBOX360 || PLATFORM_WEB
39#define POLYPHASE_THREAD_LOCAL
40#else
41#define POLYPHASE_THREAD_LOCAL thread_local
42#endif