2017-05-15 02:08:15 +00:00
|
|
|
//
|
|
|
|
// RegisterSizes.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/05/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-05-15 02:08:15 +00:00
|
|
|
//
|
|
|
|
|
2024-01-17 04:34:46 +00:00
|
|
|
#pragma once
|
2017-05-15 02:08:15 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2022-04-29 08:51:02 +00:00
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
|
|
|
// Unions below assume a modern consumer architecture,
|
|
|
|
// and that this compiler offers C-style anonymous structs.
|
|
|
|
|
2017-05-15 02:08:15 +00:00
|
|
|
namespace CPU {
|
|
|
|
|
2022-04-29 08:51:02 +00:00
|
|
|
/// Provides access to all intermediate parts of a larger int.
|
2023-02-01 19:31:40 +00:00
|
|
|
template <typename Full, typename Half> union alignas(Full) alignas(Half) RegisterPair {
|
2019-03-10 02:16:11 +00:00
|
|
|
RegisterPair(Full v) : full(v) {}
|
2024-02-17 02:47:23 +00:00
|
|
|
RegisterPair() = default;
|
2017-05-29 23:25:08 +00:00
|
|
|
|
2019-03-10 02:16:11 +00:00
|
|
|
Full full;
|
|
|
|
#if TARGET_RT_BIG_ENDIAN
|
2017-05-15 02:08:15 +00:00
|
|
|
struct {
|
2019-03-10 02:16:11 +00:00
|
|
|
Half high, low;
|
|
|
|
} halves;
|
|
|
|
#else
|
|
|
|
struct {
|
|
|
|
Half low, high;
|
|
|
|
} halves;
|
|
|
|
#endif
|
2017-05-15 02:08:15 +00:00
|
|
|
};
|
|
|
|
|
2022-04-29 08:51:02 +00:00
|
|
|
using RegisterPair16 = RegisterPair<uint16_t, uint8_t>;
|
|
|
|
using RegisterPair32 = RegisterPair<uint32_t, RegisterPair16>;
|
|
|
|
|
|
|
|
/// Provides access to lower portions of a larger int.
|
|
|
|
template <typename IntT> union SlicedInt {};
|
|
|
|
|
|
|
|
template <> union SlicedInt<uint16_t> {
|
|
|
|
struct {
|
|
|
|
uint16_t w;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct {
|
|
|
|
#if TARGET_RT_BIG_ENDIAN
|
|
|
|
uint8_t __padding[1];
|
|
|
|
#endif
|
|
|
|
uint8_t b;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> union SlicedInt<uint32_t> {
|
|
|
|
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;
|
|
|
|
};
|
2022-05-16 20:56:54 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
#if TARGET_RT_BIG_ENDIAN
|
|
|
|
SlicedInt<uint16_t> high, low;
|
|
|
|
#else
|
|
|
|
SlicedInt<uint16_t> low, high;
|
|
|
|
#endif
|
|
|
|
};
|
2022-04-29 08:51:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using SlicedInt16 = SlicedInt<uint16_t>;
|
|
|
|
using SlicedInt32 = SlicedInt<uint32_t>;
|
2019-03-10 02:16:11 +00:00
|
|
|
|
2017-05-15 02:08:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 08:51:02 +00:00
|
|
|
#pragma pack(pop)
|