llvm.org GIT mirror llvm / 955419e
Support: Add {read,write}{16,32,64}{le,be} functions. Add convenient functions for endian-aware reads/writes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231002 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 5 years ago
1 changed file(s) with 17 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
194194 unaligned_int32_t;
195195 typedef detail::packed_endian_specific_integral
196196 unaligned_int64_t;
197
198 namespace endian {
199 inline uint16_t read16le(const void *p) { return *(ulittle16_t *)p; }
200 inline uint32_t read32le(const void *p) { return *(ulittle32_t *)p; }
201 inline uint64_t read64le(const void *p) { return *(ulittle64_t *)p; }
202 inline uint16_t read16be(const void *p) { return *(ubig16_t *)p; }
203 inline uint32_t read32be(const void *p) { return *(ubig32_t *)p; }
204 inline uint64_t read64be(const void *p) { return *(ubig64_t *)p; }
205
206 inline void write16le(void *p, uint16_t v) { *(ulittle16_t *)p = v; }
207 inline void write32le(void *p, uint32_t v) { *(ulittle32_t *)p = v; }
208 inline void write64le(void *p, uint64_t v) { *(ulittle64_t *)p = v; }
209 inline void write16be(void *p, uint16_t v) { *(ubig16_t *)p = v; }
210 inline void write32be(void *p, uint32_t v) { *(ubig32_t *)p = v; }
211 inline void write64be(void *p, uint64_t v) { *(ubig64_t *)p = v; }
212 } // end namespace endian
213 } // end namespace support
197214 } // end namespace llvm
198 } // end namespace support
199215
200216 #endif