13 #ifndef LLVM_SUPPORT_ENDIAN_H 14 #define LLVM_SUPPORT_ENDIAN_H 24 #include <type_traits> 37 template<
class T,
int alignment>
39 enum {
value = alignment == 0 ?
alignof(
T) : alignment };
50 template <
typename value_type>
58 template<
typename value_type, endianness endian>
64 template <
typename value_type, std::
size_t alignment>
72 return byte_swap<value_type>(ret, endian);
75 template<
typename value_type,
77 std::size_t alignment>
78 inline value_type
read(
const void *memory) {
79 return read<value_type, alignment>(memory, endian);
84 template <
typename value_type, std::
size_t alignment,
typename CharT>
86 value_type ret = read<value_type, alignment>(memory, endian);
87 memory +=
sizeof(value_type);
91 template<
typename value_type,
endianness endian, std::size_t alignment,
93 inline value_type
readNext(
const CharT *&memory) {
94 return readNext<value_type, alignment, CharT>(memory, endian);
98 template <
typename value_type, std::
size_t alignment>
100 value = byte_swap<value_type>(
value, endian);
103 &value,
sizeof(value_type));
106 template<
typename value_type,
108 std::size_t alignment>
110 write<value_type, alignment>(memory,
value, endian);
113 template <
typename value_type>
118 template <
typename value_type, endianness endian, std::
size_t alignment>
122 return read<value_type, endian, alignment>(memory);
129 sizeof(value_type) * 2);
130 val[0] = byte_swap<value_type, endian>(val[0]);
131 val[1] = byte_swap<value_type, endian>(val[1]);
137 (
sizeof(value_type) * 8) - startBit;
144 upperVal <<= numBitsFirstVal;
146 return lowerVal | upperVal;
152 template <
typename value_type, endianness endian, std::
size_t alignment>
157 write<value_type, endian, alignment>(memory,
value);
164 sizeof(value_type) * 2);
165 val[0] = byte_swap<value_type, endian>(val[0]);
166 val[1] = byte_swap<value_type, endian>(val[1]);
172 (
sizeof(value_type) * 8) - startBit;
180 lowerVal <<= startBit;
194 val[0] = byte_swap<value_type, endian>(val[0]);
195 val[1] = byte_swap<value_type, endian>(val[1]);
198 &val[0],
sizeof(value_type) * 2);
211 static constexpr std::size_t alignment = Alignment;
218 return endian::read<value_type, endian, alignment>(
219 (
const void*)
Value.buffer);
223 endian::write<value_type, endian, alignment>(
224 (
void*)
Value.buffer, newValue);
228 *
this = *
this + newValue;
233 *
this = *
this - newValue;
238 *
this = *
this | newValue;
243 *
this = *
this & newValue;
254 explicit ref(
void *Ptr) : Ptr(Ptr) {}
257 return endian::read<value_type, endian, alignment>(Ptr);
261 endian::write<value_type, endian, alignment>(Ptr, NewValue);
341 template <
typename T>
343 template <
typename T>
346 template <
typename T>
349 template <
typename T>
355 return read<T, unaligned>(
P,
E);
358 template <
typename T, endianness E>
inline T read(
const void *
P) {
363 return read<uint16_t>(
P,
E);
366 return read<uint32_t>(
P,
E);
369 return read<uint64_t>(
P,
E);
373 return read<uint16_t, E>(
P);
376 return read<uint32_t, E>(
P);
378 template <endianness E>
inline uint64_t
read64(
const void *
P) {
379 return read<uint64_t, E>(
P);
384 inline uint64_t
read64le(
const void *
P) {
return read64<little>(
P); }
387 inline uint64_t
read64be(
const void *
P) {
return read64<big>(
P); }
390 write<T, unaligned>(
P, V,
E);
393 template <
typename T, endianness E>
inline void write(
void *
P,
T V) {
398 write<uint16_t>(
P, V,
E);
401 write<uint32_t>(
P, V,
E);
404 write<uint64_t>(
P, V,
E);
408 write<uint16_t, E>(
P, V);
411 write<uint32_t, E>(
P, V);
413 template <endianness E>
inline void write64(
void *
P, uint64_t V) {
414 write<uint64_t, E>(
P, V);
419 inline void write64le(
void *
P, uint64_t V) { write64<little>(
P, V); }
422 inline void write64be(
void *
P, uint64_t V) { write64<big>(
P, V); }
429 #endif // LLVM_SUPPORT_ENDIAN_H packed_endian_specific_integral & operator-=(value_type newValue)
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
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...
#define LLVM_ASSUME_ALIGNED(p, a)
LLVM_ASSUME_ALIGNED Returns a pointer with an assumed alignment.
void swapByteOrder(T &Value)
This class represents lattice values for constants.
void write32le(void *P, uint32_t V)
uint16_t read16le(const void *P)
packed_endian_specific_integral & operator|=(value_type newValue)
uint64_t read64be(const void *P)
constexpr bool IsBigEndianHost
uint32_t read32be(const void *P)
void write16le(void *P, uint16_t V)
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.
ProcessorArchitecture value_type
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)
void operator=(value_type newValue)
value_type readNext(const CharT *&memory)
uint32_t read32(const void *P)
void operator=(value_type NewValue)
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)
packed_endian_specific_integral(value_type val)
typename std::make_unsigned< value_type >::type make_unsigned_t
void write64be(void *P, uint64_t V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
packed_endian_specific_integral & operator &=(value_type newValue)
::value is either alignment, or alignof(T) if alignment is 0.
uint16_t read16be(const void *P)
uint16_t read16(const void *P)
packed_endian_specific_integral & operator+=(value_type newValue)
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...