13#ifndef LLVM_SUPPORT_ENDIAN_H
14#define LLVM_SUPPORT_ENDIAN_H
34template<
class T,
int alignment>
36 enum {
value = alignment == 0 ?
alignof(
T) : alignment };
43template <
typename value_type>
51template <
typename value_type, endianness endian>
57template <
typename value_type, std::
size_t alignment = unaligned>
65 return byte_swap<value_type>(ret,
endian);
68template <
typename value_type, endianness endian, std::
size_t alignment>
69[[nodiscard]]
inline value_type
read(
const void *memory) {
70 return read<value_type, alignment>(memory,
endian);
75template <
typename value_type, std::
size_t alignment,
typename CharT>
76[[nodiscard]]
inline value_type
readNext(
const CharT *&memory,
78 value_type ret = read<value_type, alignment>(memory,
endian);
79 memory +=
sizeof(value_type);
85[[nodiscard]]
inline value_type
readNext(
const CharT *&memory) {
86 return readNext<value_type, alignment, CharT>(memory,
endian);
90template <
typename value_type, std::
size_t alignment = unaligned>
95 &
value,
sizeof(value_type));
98template<
typename value_type,
100 std::size_t alignment>
102 write<value_type, alignment>(memory,
value,
endian);
105template <
typename value_type>
110template <
typename value_type, endianness endian, std::
size_t alignment>
115 return read<value_type, endian, alignment>(memory);
122 sizeof(value_type) * 2);
123 val[0] = byte_swap<value_type, endian>(val[0]);
124 val[1] = byte_swap<value_type, endian>(val[1]);
130 (
sizeof(value_type) * 8) - startBit;
137 upperVal <<= numBitsFirstVal;
139 return lowerVal | upperVal;
145template <
typename value_type, endianness endian, std::
size_t alignment>
150 write<value_type, endian, alignment>(memory,
value);
157 sizeof(value_type) * 2);
158 val[0] = byte_swap<value_type, endian>(val[0]);
159 val[1] = byte_swap<value_type, endian>(val[1]);
165 (
sizeof(value_type) * 8) - startBit;
173 lowerVal <<= startBit;
187 val[0] = byte_swap<value_type, endian>(val[0]);
188 val[1] = byte_swap<value_type, endian>(val[1]);
191 &val[0],
sizeof(value_type) * 2);
211 return endian::read<value_type, endian, alignment>(
212 (
const void*)
Value.buffer);
216 endian::write<value_type, endian, alignment>(
217 (
void*)
Value.buffer, newValue);
221 *
this = *
this + newValue;
226 *
this = *
this - newValue;
231 *
this = *
this | newValue;
236 *
this = *
this & newValue;
250 return endian::read<value_type, endian, alignment>(Ptr);
254 endian::write<value_type, endian, alignment>(Ptr, NewValue);
382template <
typename T, endianness E> [[nodiscard]]
inline T read(
const void *
P) {
387 return read<uint16_t>(
P,
E);
390 return read<uint32_t>(
P,
E);
393 return read<uint64_t>(
P,
E);
397 return read<uint16_t, E>(
P);
400 return read<uint32_t, E>(
P);
403 return read<uint64_t, E>(
P);
407 return read16<llvm::endianness::little>(
P);
410 return read32<llvm::endianness::little>(
P);
413 return read64<llvm::endianness::little>(
P);
416 return read16<llvm::endianness::big>(
P);
419 return read32<llvm::endianness::big>(
P);
422 return read64<llvm::endianness::big>(
P);
425template <
typename T, endianness E>
inline void write(
void *
P,
T V) {
430 write<uint16_t>(
P, V,
E);
433 write<uint32_t>(
P, V,
E);
436 write<uint64_t>(
P, V,
E);
440 write<uint16_t, E>(
P, V);
443 write<uint32_t, E>(
P, V);
446 write<uint64_t, E>(
P, V);
450 write16<llvm::endianness::little>(
P, V);
453 write32<llvm::endianness::little>(
P, V);
456 write64<llvm::endianness::little>(
P, V);
459 write16<llvm::endianness::big>(
P, V);
462 write32<llvm::endianness::big>(
P, V);
465 write64<llvm::endianness::big>(
P, V);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ASSUME_ALIGNED(p, a)
\macro LLVM_ASSUME_ALIGNED Returns a pointer with an assumed alignment.
Given that RA is a live value
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements the C++20 <bit> header.
LLVM Value Representation.
uint64_t read64le(const void *P)
value_type byte_swap(value_type value, endianness endian)
uint16_t read16le(const void *P)
uint32_t read32(const void *P, endianness E)
void write16be(void *P, uint16_t V)
void write64le(void *P, uint64_t V)
uint64_t read64be(const void *P)
void write32le(void *P, uint32_t V)
void write32(void *P, uint32_t V, endianness E)
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...
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 write32be(void *P, uint32_t V)
uint64_t read64(const void *P, endianness E)
uint32_t read32be(const void *P)
void write16(void *P, uint16_t V, endianness E)
void write16le(void *P, uint16_t V)
void write64be(void *P, uint64_t V)
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
void write64(void *P, uint64_t V, endianness E)
uint16_t read16be(const void *P)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
value_type readNext(const CharT *&memory, endianness endian)
Read a value of a particular endianness from a buffer, and increment the buffer past that value.
uint32_t read32le(const void *P)
uint16_t read16(const void *P, endianness E)
std::make_unsigned_t< value_type > make_unsigned_t
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
value is either alignment, or alignof(T) if alignment is 0.
void operator=(value_type NewValue)
packed_endian_specific_integral(value_type val)
packed_endian_specific_integral()=default
packed_endian_specific_integral & operator+=(value_type newValue)
packed_endian_specific_integral & operator&=(value_type newValue)
char buffer[sizeof(value_type)]
void operator=(value_type newValue)
static constexpr std::size_t alignment
packed_endian_specific_integral & operator|=(value_type newValue)
packed_endian_specific_integral & operator-=(value_type newValue)