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 =
unaligned,
77[[nodiscard]]
inline value_type
readNext(
const CharT *&memory,
79 value_type ret = read<value_type, alignment>(memory,
endian);
80 memory +=
sizeof(value_type);
85 std::size_t alignment =
unaligned,
typename CharT>
86[[nodiscard]]
inline value_type
readNext(
const CharT *&memory) {
87 return readNext<value_type, alignment, CharT>(memory,
endian);
91template <
typename value_type, std::
size_t alignment = unaligned>
96 &
value,
sizeof(value_type));
99template<
typename value_type,
101 std::size_t alignment>
103 write<value_type, alignment>(memory,
value,
endian);
108template <
typename value_type, std::size_t alignment =
unaligned,
112 memory +=
sizeof(value_type);
116 std::size_t alignment =
unaligned,
typename CharT>
118 writeNext<value_type, alignment, CharT>(memory,
value,
endian);
121template <
typename value_type>
126template <
typename value_type, endianness endian, std::
size_t alignment>
131 return read<value_type, endian, alignment>(memory);
138 sizeof(value_type) * 2);
139 val[0] = byte_swap<value_type, endian>(val[0]);
140 val[1] = byte_swap<value_type, endian>(val[1]);
146 (
sizeof(value_type) * 8) - startBit;
153 upperVal <<= numBitsFirstVal;
155 return lowerVal | upperVal;
161template <
typename value_type, endianness endian, std::
size_t alignment>
166 write<value_type, endian, alignment>(memory,
value);
173 sizeof(value_type) * 2);
174 val[0] = byte_swap<value_type, endian>(val[0]);
175 val[1] = byte_swap<value_type, endian>(val[1]);
181 (
sizeof(value_type) * 8) - startBit;
189 lowerVal <<= startBit;
203 val[0] = byte_swap<value_type, endian>(val[0]);
204 val[1] = byte_swap<value_type, endian>(val[1]);
207 &val[0],
sizeof(value_type) * 2);
227 return endian::read<value_type, endian, alignment>(
228 (
const void*)
Value.buffer);
232 endian::write<value_type, endian, alignment>(
233 (
void*)
Value.buffer, newValue);
237 *
this = *
this + newValue;
242 *
this = *
this - newValue;
247 *
this = *
this | newValue;
252 *
this = *
this & newValue;
266 return endian::read<value_type, endian, alignment>(Ptr);
270 endian::write<value_type, endian, alignment>(Ptr, NewValue);
398template <
typename T, endianness E> [[nodiscard]]
inline T read(
const void *
P) {
403 return read<uint16_t>(
P,
E);
406 return read<uint32_t>(
P,
E);
409 return read<uint64_t>(
P,
E);
413 return read<uint16_t, E>(
P);
416 return read<uint32_t, E>(
P);
419 return read<uint64_t, E>(
P);
423 return read16<llvm::endianness::little>(
P);
426 return read32<llvm::endianness::little>(
P);
429 return read64<llvm::endianness::little>(
P);
432 return read16<llvm::endianness::big>(
P);
435 return read32<llvm::endianness::big>(
P);
438 return read64<llvm::endianness::big>(
P);
441template <
typename T, endianness E>
inline void write(
void *
P,
T V) {
446 write<uint16_t>(
P, V,
E);
449 write<uint32_t>(
P, V,
E);
452 write<uint64_t>(
P, V,
E);
456 write<uint16_t, E>(
P, V);
459 write<uint32_t, E>(
P, V);
462 write<uint64_t, E>(
P, V);
466 write16<llvm::endianness::little>(
P, V);
469 write32<llvm::endianness::little>(
P, V);
472 write64<llvm::endianness::little>(
P, V);
475 write16<llvm::endianness::big>(
P, V);
478 write32<llvm::endianness::big>(
P, V);
481 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 writeNext(CharT *&memory, value_type value, endianness endian)
Write a value of a particular endianness, and increment the buffer past that value.
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)