// // RegisterSizes.hpp // Clock Signal // // Created by Thomas Harte on 14/05/2017. // Copyright 2017 Thomas Harte. All rights reserved. // #pragma once #include #pragma pack(push, 1) // Unions below assume a modern consumer architecture, // and that this compiler offers C-style anonymous structs. namespace CPU { /// Provides access to all intermediate parts of a larger int. template union alignas(Full) alignas(Half) RegisterPair { RegisterPair(Full v) : full(v) {} RegisterPair() = default; Full full; #if TARGET_RT_BIG_ENDIAN struct { Half high, low; } halves; #else struct { Half low, high; } halves; #endif }; using RegisterPair16 = RegisterPair; using RegisterPair32 = RegisterPair; /// Provides access to lower portions of a larger int. template union SlicedInt {}; template <> union SlicedInt { struct { uint16_t w; }; struct { #if TARGET_RT_BIG_ENDIAN uint8_t __padding[1]; #endif uint8_t b; }; }; template <> union SlicedInt { struct { uint32_t l; }; struct { #if TARGET_RT_BIG_ENDIAN uint16_t __padding[1]; #endif uint16_t w; }; struct { #if TARGET_RT_BIG_ENDIAN uint8_t __padding[3]; #endif uint8_t b; }; struct { #if TARGET_RT_BIG_ENDIAN SlicedInt high, low; #else SlicedInt low, high; #endif }; }; using SlicedInt16 = SlicedInt; using SlicedInt32 = SlicedInt; } #pragma pack(pop)