Skip to content

Compiler Definitions API

Markdown

This file contains commonly used preprocessor definitions used throughout the project: library-wide configuration defines, compiler detection, compiler attributes, the TLS model and conversion utilities. SHZ_TARGET is auto-detected from compiler macros, and SHZ_BACKEND selects the implementation: the SH4 back-end is chosen only when targeting SH4 in single-precision FPU mode, otherwise the portable software back-end is used. SHZ_CONVERT() performs a zero-cost conversion between layout-compatible types and is what the _from() and _to() adapters are built on. Upstream keeps the compiler attribute macros (SHZ_INLINE, SHZ_FORCE_INLINE, SHZ_ALIGNAS, ...) out of its reference; they appear here only when Doxygen exposes them.

  • C header: #include <sh4zam/shz_cdefs.h>
  • C++ header: #include <sh4zam/shz_cdefs.hpp>
  • Symbols: 67

List of architectures which SH4ZAM can auto-detect.

SymbolDescription
SHZ_SH4Back-end for the Dreamcast's SH4.
SHZ_PPCBack-end for the Gamecube/Wii's Gekko PPC.
SHZ_MIPSBack-end for MIPS architectures.
SHZ_ARMBack-end for ARM architectures.
SHZ_X86_64Back-end for x86_64 architectures.
SHZ_SPUBack-end for the Cell B/E SPU architecture.
SHZ_WASMBack-end for WebAssembly.
SHZ_SWGeneric C-based software back-end.

Defines for different mechanisms for thread-local storage.

SymbolDescription
SHZ_TLS_DISABLEDNo thread-local variables.
SHZ_TLS_IMPLICITUse thread_local keyword for TLS.
SHZ_TLS_PTHREADUse pthread unique keys for TLS.
SHZ_TLS_CTHREADUse C11 thread TSS keys for TLS.

Defines for identifying the detected compiler.

SymbolDescription
SHZ_GNUCDefined when building with a GCC-compatible compiler.

Miscellaneous function-like macros

SymbolDescription
SHZ_STRINGIFY_LITERALStringifies a literal expression.
SHZ_STRINGIFYStringifies an expression after preprocessing, supporting macro expansion.
SHZ_COUNT_OFReturns the number of elements within a statically sized array.
SHZ_CONTAINER_OFReturns the containing structure from a pointer to one of its members.
SHZ_SWAPMacro which swaps the two values held by a and b.
SHZ_DECLARE_STRUCTMacro which forward declares a struct and its typedef.
SHZ_DECLARE_STRUCT_ALIGNEDMacro which forward declares a manually aligned struct and its typedef.

Macros for declaring and managing thread-local variables.

SymbolDescription
SHZ_TLS_DECLDeclares a TLS variable with disabled model (so not thread-local).
SHZ_TLS_REFReferences a TLS variable, with disabled model.

Types which may break C/C++'s strict aliasing rules

SymbolDescription
shz_alias_int16_tint16_t type whose value may be aliased as another type.
shz_alias_uint16_tuint16_t type whose value may be aliased as another type.
shz_alias_int32_tint32_t type whose value may be aliased as another type.
shz_alias_uint32_tuint32_t type whose value may be aliased as another type.
shz_alias_float_tfloat type whose value may be aliased as another type.
shz_alias_int64_tint64_t type whose value may be aliased as another type.
shz_alias_uint64_tuint64_t type whose value may be aliased as another type.
shz_alias_double_tdouble type whose value may be aliased as another type.
SymbolDescription
SHZ_TARGETTarget architecture Determines the actual architecture we're building for.
SHZ_BACKENDSH4ZAM back-end Selects which SH4ZAM implementation to use for a given target.
SHZ_TLS_MODELthread_local storage.

Public declarations that upstream keeps out of its Doxygen reference. Listed for completeness; prefer the documented API.

SymbolDescription
SHZ_MSVCDefined when building with Microsoft Visual C++.
SHZ_CLANGDefined when bulding with Clang.
SHZ_MINGW64Defined when bulding with MinGW-w64.
SHZ_MINGW32Defined when building for 32-bit MinGW or other MinGW compiler(s).
SHZ_GCCDefined when building for GCC.
SHZ_ALIGNASForces a function or type to be aligned by N bytes.
SHZ_SIMDTells GCC that a scalar type is to be treated as a vector of size N.
SHZ_HOTTells GCC that a particular function should be optimized for performance.
SHZ_COLDTells GCC that a particular function should be optimized for size.
SHZ_FAST_MATHPut this before a function definition to tell GCC to use fast math optimizations on a specific function.
SHZ_NO_FAST_MATHPut this before a function definition to tell GCC to NOT use fast math optimizations on a specific function.
SHZ_NO_UNROLL_LOOPSPut this before a function definition to tell GCC to NOT unroll loops in a specific function.
SHZ_NO_OPTIMIZATIONTells GCC to disable any optimizations when compiling a function.
SHZ_FUNC_ALIGNASAligns a function within the .text segment by N bytes.
SHZ_FORCE_INLINEForces GCC to inline the given function.
SHZ_NO_INLINEPrevents GCC from inlining the given function.
SHZ_FLATTENForces GCC to inline all calls to other functions made within the tagged function.
SHZ_PACKEDTells GCC not to introduce any extra padding for the given type.
SHZ_PURETells GCC the function has no effects other than returning a value that depends on its arguments and global variables.
SHZ_CONSTTells GCC the function has no effects other than returning a value that depends only on its arguments.
SHZ_ALIASINGTells GCC that the decorated pointer may be breaking strict aliasing rules for C and C++
SHZ_DEPRECATEDEmits a warning that a symbol has been deprecated with a message, upon use.
SHZ_LIKELYTells GCC that the expression is likely to be true (used for conditional and loop optimizations)
SHZ_UNLIKELYTells GCC that the expression is likely to be false (used for conditional and loop optimizations)
SHZ_RESTRICTTells GCC the pointer paraemter is unique and is not aliased by another parameter
SHZ_MEMORY_BARRIER_SOFTCreates a software memory barrier beyond which any loads or stores may not be reordered
SHZ_MEMORY_BARRIER_HARDCreates a hardware memory barrier beyond which any loads or stores may not be reordered
SHZ_INSTR_BARRIERPrevents the compiler from reordering instructions beyond the barrier.
SHZ_DECLS_BEGINDummy define provided for C++ compatibility
SHZ_DECLS_ENDDummy define provided for C++ compatibility
SHZ_INLINERequests a function or member to be inlined (nonforcibly) OR to have static linkage.
SHZ_NOEXCEPTDummy define provided for C++ compatibility
SHZ_INITTemporary struct initialization statement to use within C.
SHZ_CONVERTConversion macro for zero-overhead conversions, taking the given value to a value of the given type.