14 #ifndef LLVM_SUPPORT_ENDIAN_H 15 #define LLVM_SUPPORT_ENDIAN_H 25 #include <type_traits> 38 template<
class T,
int alignment>
40 enum {
value = alignment == 0 ?
alignof(
T) : alignment };
51 template <
typename value_type>
59 template<
typename value_type, endianness endian>
65 template <
typename value_type, std::
size_t alignment>
73 return byte_swap<value_type>(ret, endian);
76 template<
typename value_type,
78 std::size_t alignment>
79 inline value_type
read(
const void *memory) {
80 return read<value_type, alignment>(memory, endian);
85 template <
typename value_type, std::
size_t alignment,
typename CharT>
87 value_type ret = read<value_type, alignment>(memory, endian);
88 memory +=
sizeof(value_type);
92 template<
typename value_type,
endianness endian, std::size_t alignment,
94 inline value_type
readNext(
const CharT *&memory) {
95 return readNext<value_type, alignment, CharT>(memory, endian);
99 template <
typename value_type, std::
size_t alignment>
101 value = byte_swap<value_type>(
value, endian);
104 &value,
sizeof(value_type));
107 template<
typename value_type,
109 std::size_t alignment>
111 write<value_type, alignment>(memory,
value, endian);
114 template <
typename value_type>
119 template <
typename value_type, endianness endian, std::
size_t alignment>
123 return read<value_type, endian, alignment>(memory);
130 sizeof(value_type) * 2);
131 val[0] = byte_swap<value_type, endian>(val[0]);
132 val[1] = byte_swap<value_type, endian>(val[1]);
138 (
sizeof(value_type) * 8) - startBit;
145 upperVal <<= numBitsFirstVal;
147 return lowerVal | upperVal;
153 template <
typename value_type, endianness endian, std::
size_t alignment>
158 write<value_type, endian, alignment>(memory,
value);
165 sizeof(value_type) * 2);
166 val[0] = byte_swap<value_type, endian>(val[0]);
167 val[1] = byte_swap<value_type, endian>(val[1]);
173 (
sizeof(value_type) * 8) - startBit;
181 lowerVal <<= startBit;
195 val[0] = byte_swap<value_type, endian>(val[0]);
196 val[1] = byte_swap<value_type, endian>(val[1]);
199 &val[0],
sizeof(value_type) * 2);
207 template<
typename value_type,
209 std::size_t alignment>
215 operator value_type()
const {
216 return endian::read<value_type, endian, alignment>(
217 (
const void*)
Value.buffer);
221 endian::write<value_type, endian, alignment>(
222 (
void*)
Value.buffer, newValue);
226 *
this = *
this + newValue;
231 *
this = *
this - newValue;
236 *
this = *
this | newValue;
241 *
this = *
this & newValue;
247 sizeof(value_type)>
Value;
251 explicit ref(
void *Ptr) : Ptr(Ptr) {}
253 operator value_type()
const {
254 return endian::read<value_type, endian, alignment>(Ptr);
258 endian::write<value_type, endian, alignment>(Ptr, NewValue);
341 return read<T, unaligned>(
P,
E);
344 template <
typename T, endianness E>
inline T read(
const void *
P) {
349 return read<uint16_t>(
P,
E);
352 return read<uint32_t>(
P,
E);
355 return read<uint64_t>(
P,
E);
358 template <endianness E>
inline uint16_t
read16(
const void *
P) {
359 return read<uint16_t, E>(
P);
362 return read<uint32_t, E>(
P);
364 template <endianness E>
inline uint64_t
read64(
const void *
P) {
365 return read<uint64_t, E>(
P);
368 inline uint16_t
read16le(
const void *
P) {
return read16<little>(
P); }
370 inline uint64_t
read64le(
const void *
P) {
return read64<little>(
P); }
371 inline uint16_t
read16be(
const void *
P) {
return read16<big>(
P); }
373 inline uint64_t
read64be(
const void *
P) {
return read64<big>(
P); }
376 write<T, unaligned>(
P, V,
E);
379 template <
typename T, endianness E>
inline void write(
void *
P,
T V) {
384 write<uint16_t>(
P, V,
E);
387 write<uint32_t>(
P, V,
E);
390 write<uint64_t>(
P, V,
E);
393 template <endianness E>
inline void write16(
void *
P, uint16_t V) {
394 write<uint16_t, E>(
P, V);
397 write<uint32_t, E>(
P, V);
399 template <endianness E>
inline void write64(
void *
P, uint64_t V) {
400 write<uint64_t, E>(
P, V);
403 inline void write16le(
void *
P, uint16_t V) { write16<little>(
P, V); }
405 inline void write64le(
void *
P, uint64_t V) { write64<little>(
P, V); }
406 inline void write16be(
void *
P, uint16_t V) { write16<big>(
P, V); }
408 inline void write64be(
void *
P, uint64_t V) { write64<big>(
P, V); }
415 #endif // LLVM_SUPPORT_ENDIAN_H packed_endian_specific_integral & operator+=(value_type newValue)
void write32be(void *P, uint32_t V)
value_type readAtBitAlignment(const void *memory, uint64_t startBit)
Read a value of a particular endianness from memory, for a location that starts at the given bit offs...
void swapByteOrder(T &Value)
This class represents lattice values for constants.
void write32le(void *P, uint32_t V)
uint16_t read16le(const void *P)
uint64_t read64be(const void *P)
constexpr bool IsBigEndianHost
uint32_t read32be(const void *P)
void write16le(void *P, uint16_t V)
#define LLVM_ASSUME_ALIGNED(p, a)
LLVM_ASSUME_ALIGNED Returns a pointer with an assumed alignment.
void operator=(value_type NewValue)
uint64_t read64(const void *P)
void write32(void *P, uint32_t V)
value_type byte_swap(value_type value)
Swap the bytes of value to match the given endianness.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void write64(void *P, uint64_t V)
void writeAtBitAlignment(void *memory, value_type value, uint64_t startBit)
Write a value to memory with a particular endianness, for a location that starts at the given bit off...
void write16(void *P, uint16_t V)
static void write(bool isBE, void *P, T V)
packed_endian_specific_integral & operator|=(value_type newValue)
value_type readNext(const CharT *&memory)
packed_endian_specific_integral & operator-=(value_type newValue)
uint32_t read32(const void *P)
constexpr endianness system_endianness()
void write16be(void *P, uint16_t V)
uint64_t read64le(const void *P)
void write64le(void *P, uint64_t V)
uint32_t read32le(const void *P)
void operator=(value_type newValue)
typename std::make_unsigned< value_type >::type make_unsigned_t
void write64be(void *P, uint64_t V)
packed_endian_specific_integral(value_type val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
E & operator &=(E &LHS, E RHS)
::value is either alignment, or alignof(T) if alignment is 0.
uint16_t read16be(const void *P)
Helper for building an aligned character array type.
uint16_t read16(const void *P)