0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===- Endian.h - Utilities for IO with endian specific data ----*- C++ -*-===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // This file declares generic functions to read and write endian specific data.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 #ifndef LLVM_SUPPORT_ENDIAN_H
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 #define LLVM_SUPPORT_ENDIAN_H
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 #include "llvm/Support/AlignOf.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 #include "llvm/Support/Host.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 #include "llvm/Support/SwapByteOrder.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 namespace llvm {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 namespace support {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 enum endianness {big, little, native};
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 // These are named values for common alignments.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 enum {aligned = 0, unaligned = 1};
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 namespace detail {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 /// \brief ::value is either alignment, or alignof(T) if alignment is 0.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 template<class T, int alignment>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 struct PickAlignment {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 enum {value = alignment == 0 ? AlignOf<T>::Alignment : alignment};
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 } // end namespace detail
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 namespace endian {
|
77
|
37 /// Swap the bytes of value to match the given endianness.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 template<typename value_type, endianness endian>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 inline value_type byte_swap(value_type value) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 if (endian != native && sys::IsBigEndianHost != (endian == big))
|
77
|
41 sys::swapByteOrder(value);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 return value;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44
|
77
|
45 /// Read a value of a particular endianness from memory.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 template<typename value_type,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 endianness endian,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 std::size_t alignment>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 inline value_type read(const void *memory) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 value_type ret;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 memcpy(&ret,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 LLVM_ASSUME_ALIGNED(memory,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 (detail::PickAlignment<value_type, alignment>::value)),
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 sizeof(value_type));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 return byte_swap<value_type, endian>(ret);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58
|
77
|
59 /// Read a value of a particular endianness from a buffer, and increment the
|
|
60 /// buffer past that value.
|
95
|
61 template<typename value_type, endianness endian, std::size_t alignment,
|
|
62 typename CharT>
|
|
63 inline value_type readNext(const CharT *&memory) {
|
77
|
64 value_type ret = read<value_type, endian, alignment>(memory);
|
|
65 memory += sizeof(value_type);
|
|
66 return ret;
|
|
67 }
|
|
68
|
|
69 /// Write a value to memory with a particular endianness.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 template<typename value_type,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 endianness endian,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 std::size_t alignment>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 inline void write(void *memory, value_type value) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 value = byte_swap<value_type, endian>(value);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 memcpy(LLVM_ASSUME_ALIGNED(memory,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 (detail::PickAlignment<value_type, alignment>::value)),
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 &value,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 sizeof(value_type));
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 }
|
95
|
80
|
|
81 template <typename value_type>
|
|
82 using make_unsigned_t = typename std::make_unsigned<value_type>::type;
|
|
83
|
|
84 /// Read a value of a particular endianness from memory, for a location
|
|
85 /// that starts at the given bit offset within the first byte.
|
|
86 template <typename value_type, endianness endian, std::size_t alignment>
|
|
87 inline value_type readAtBitAlignment(const void *memory, uint64_t startBit) {
|
|
88 assert(startBit < 8);
|
|
89 if (startBit == 0)
|
|
90 return read<value_type, endian, alignment>(memory);
|
|
91 else {
|
|
92 // Read two values and compose the result from them.
|
|
93 value_type val[2];
|
|
94 memcpy(&val[0],
|
|
95 LLVM_ASSUME_ALIGNED(
|
|
96 memory, (detail::PickAlignment<value_type, alignment>::value)),
|
|
97 sizeof(value_type) * 2);
|
|
98 val[0] = byte_swap<value_type, endian>(val[0]);
|
|
99 val[1] = byte_swap<value_type, endian>(val[1]);
|
|
100
|
|
101 // Shift bits from the lower value into place.
|
|
102 make_unsigned_t<value_type> lowerVal = val[0] >> startBit;
|
|
103 // Mask off upper bits after right shift in case of signed type.
|
|
104 make_unsigned_t<value_type> numBitsFirstVal =
|
|
105 (sizeof(value_type) * 8) - startBit;
|
|
106 lowerVal &= ((make_unsigned_t<value_type>)1 << numBitsFirstVal) - 1;
|
|
107
|
|
108 // Get the bits from the upper value.
|
|
109 make_unsigned_t<value_type> upperVal =
|
|
110 val[1] & (((make_unsigned_t<value_type>)1 << startBit) - 1);
|
|
111 // Shift them in to place.
|
|
112 upperVal <<= numBitsFirstVal;
|
|
113
|
|
114 return lowerVal | upperVal;
|
|
115 }
|
|
116 }
|
|
117
|
|
118 /// Write a value to memory with a particular endianness, for a location
|
|
119 /// that starts at the given bit offset within the first byte.
|
|
120 template <typename value_type, endianness endian, std::size_t alignment>
|
|
121 inline void writeAtBitAlignment(void *memory, value_type value,
|
|
122 uint64_t startBit) {
|
|
123 assert(startBit < 8);
|
|
124 if (startBit == 0)
|
|
125 write<value_type, endian, alignment>(memory, value);
|
|
126 else {
|
|
127 // Read two values and shift the result into them.
|
|
128 value_type val[2];
|
|
129 memcpy(&val[0],
|
|
130 LLVM_ASSUME_ALIGNED(
|
|
131 memory, (detail::PickAlignment<value_type, alignment>::value)),
|
|
132 sizeof(value_type) * 2);
|
|
133 val[0] = byte_swap<value_type, endian>(val[0]);
|
|
134 val[1] = byte_swap<value_type, endian>(val[1]);
|
|
135
|
|
136 // Mask off any existing bits in the upper part of the lower value that
|
|
137 // we want to replace.
|
|
138 val[0] &= ((make_unsigned_t<value_type>)1 << startBit) - 1;
|
|
139 make_unsigned_t<value_type> numBitsFirstVal =
|
|
140 (sizeof(value_type) * 8) - startBit;
|
|
141 make_unsigned_t<value_type> lowerVal = value;
|
|
142 if (startBit > 0) {
|
|
143 // Mask off the upper bits in the new value that are not going to go into
|
|
144 // the lower value. This avoids a left shift of a negative value, which
|
|
145 // is undefined behavior.
|
|
146 lowerVal &= (((make_unsigned_t<value_type>)1 << numBitsFirstVal) - 1);
|
|
147 // Now shift the new bits into place
|
|
148 lowerVal <<= startBit;
|
|
149 }
|
|
150 val[0] |= lowerVal;
|
|
151
|
|
152 // Mask off any existing bits in the lower part of the upper value that
|
|
153 // we want to replace.
|
|
154 val[1] &= ~(((make_unsigned_t<value_type>)1 << startBit) - 1);
|
|
155 // Next shift the bits that go into the upper value into position.
|
|
156 make_unsigned_t<value_type> upperVal = value >> numBitsFirstVal;
|
|
157 // Mask off upper bits after right shift in case of signed type.
|
|
158 upperVal &= ((make_unsigned_t<value_type>)1 << startBit) - 1;
|
|
159 val[1] |= upperVal;
|
|
160
|
|
161 // Finally, rewrite values.
|
|
162 val[0] = byte_swap<value_type, endian>(val[0]);
|
|
163 val[1] = byte_swap<value_type, endian>(val[1]);
|
|
164 memcpy(LLVM_ASSUME_ALIGNED(
|
|
165 memory, (detail::PickAlignment<value_type, alignment>::value)),
|
|
166 &val[0], sizeof(value_type) * 2);
|
|
167 }
|
|
168 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 } // end namespace endian
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 namespace detail {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 template<typename value_type,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 endianness endian,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 std::size_t alignment>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 struct packed_endian_specific_integral {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 operator value_type() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 return endian::read<value_type, endian, alignment>(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 (const void*)Value.buffer);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 void operator=(value_type newValue) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 endian::write<value_type, endian, alignment>(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 (void*)Value.buffer, newValue);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185
|
83
|
186 packed_endian_specific_integral &operator+=(value_type newValue) {
|
|
187 *this = *this + newValue;
|
|
188 return *this;
|
|
189 }
|
|
190
|
|
191 packed_endian_specific_integral &operator-=(value_type newValue) {
|
|
192 *this = *this - newValue;
|
|
193 return *this;
|
|
194 }
|
|
195
|
95
|
196 packed_endian_specific_integral &operator|=(value_type newValue) {
|
|
197 *this = *this | newValue;
|
|
198 return *this;
|
|
199 }
|
|
200
|
|
201 packed_endian_specific_integral &operator&=(value_type newValue) {
|
|
202 *this = *this & newValue;
|
|
203 return *this;
|
|
204 }
|
|
205
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 private:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 AlignedCharArray<PickAlignment<value_type, alignment>::value,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 sizeof(value_type)> Value;
|
77
|
209
|
|
210 public:
|
|
211 struct ref {
|
|
212 explicit ref(void *Ptr) : Ptr(Ptr) {}
|
|
213
|
|
214 operator value_type() const {
|
|
215 return endian::read<value_type, endian, alignment>(Ptr);
|
|
216 }
|
|
217
|
|
218 void operator=(value_type NewValue) {
|
|
219 endian::write<value_type, endian, alignment>(Ptr, NewValue);
|
|
220 }
|
|
221
|
|
222 private:
|
|
223 void *Ptr;
|
|
224 };
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225 };
|
77
|
226
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 } // end namespace detail
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 <uint16_t, little, unaligned> ulittle16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 <uint32_t, little, unaligned> ulittle32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234 <uint64_t, little, unaligned> ulittle64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237 <int16_t, little, unaligned> little16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 <int32_t, little, unaligned> little32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 <int64_t, little, unaligned> little64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
244 <uint16_t, little, aligned> aligned_ulittle16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246 <uint32_t, little, aligned> aligned_ulittle32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
247 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248 <uint64_t, little, aligned> aligned_ulittle64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251 <int16_t, little, aligned> aligned_little16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 <int32_t, little, aligned> aligned_little32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 <int64_t, little, aligned> aligned_little64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
256
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
257 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
258 <uint16_t, big, unaligned> ubig16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
259 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
260 <uint32_t, big, unaligned> ubig32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
261 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
262 <uint64_t, big, unaligned> ubig64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 <int16_t, big, unaligned> big16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267 <int32_t, big, unaligned> big32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 <int64_t, big, unaligned> big64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 <uint16_t, big, aligned> aligned_ubig16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 <uint32_t, big, aligned> aligned_ubig32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 <uint64_t, big, aligned> aligned_ubig64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279 <int16_t, big, aligned> aligned_big16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
280 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 <int32_t, big, aligned> aligned_big32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 <int64_t, big, aligned> aligned_big64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
286 <uint16_t, native, unaligned> unaligned_uint16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
287 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288 <uint32_t, native, unaligned> unaligned_uint32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
289 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 <uint64_t, native, unaligned> unaligned_uint64_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 <int16_t, native, unaligned> unaligned_int16_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 <int32_t, native, unaligned> unaligned_int32_t;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296 typedef detail::packed_endian_specific_integral
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 <int64_t, native, unaligned> unaligned_int64_t;
|
95
|
298
|
|
299 namespace endian {
|
|
300 inline uint16_t read16le(const void *p) { return *(const ulittle16_t *)p; }
|
|
301 inline uint32_t read32le(const void *p) { return *(const ulittle32_t *)p; }
|
|
302 inline uint64_t read64le(const void *p) { return *(const ulittle64_t *)p; }
|
|
303 inline uint16_t read16be(const void *p) { return *(const ubig16_t *)p; }
|
|
304 inline uint32_t read32be(const void *p) { return *(const ubig32_t *)p; }
|
|
305 inline uint64_t read64be(const void *p) { return *(const ubig64_t *)p; }
|
|
306
|
|
307 inline void write16le(void *p, uint16_t v) { *(ulittle16_t *)p = v; }
|
|
308 inline void write32le(void *p, uint32_t v) { *(ulittle32_t *)p = v; }
|
|
309 inline void write64le(void *p, uint64_t v) { *(ulittle64_t *)p = v; }
|
|
310 inline void write16be(void *p, uint16_t v) { *(ubig16_t *)p = v; }
|
|
311 inline void write32be(void *p, uint32_t v) { *(ubig32_t *)p = v; }
|
|
312 inline void write64be(void *p, uint64_t v) { *(ubig64_t *)p = v; }
|
|
313 } // end namespace endian
|
|
314 } // end namespace support
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
315 } // end namespace llvm
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
316
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
317 #endif
|