llvm.org GIT mirror llvm / ab22d95
Using llvm::sys::swapByteOrder() for the common case of byte-swapping a value in place git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210978 91177308-0d34-0410-b5e6-96231b3b80d8 Artyom Skrobov 5 years ago
5 changed file(s) with 8 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
151151 uint64_t result;
152152 memcpy(&result, p, sizeof(result));
153153 if (sys::IsBigEndianHost)
154 return sys::getSwappedBytes(result);
154 sys::swapByteOrder(result);
155155 return result;
156156 }
157157
159159 uint32_t result;
160160 memcpy(&result, p, sizeof(result));
161161 if (sys::IsBigEndianHost)
162 return sys::getSwappedBytes(result);
162 sys::swapByteOrder(result);
163163 return result;
164164 }
165165
3737 template
3838 inline value_type byte_swap(value_type value) {
3939 if (endian != native && sys::IsBigEndianHost != (endian == big))
40 return sys::getSwappedBytes(value);
40 sys::swapByteOrder(value);
4141 return value;
4242 }
4343
244244
245245 void writeInt16BE(uint8_t *Addr, uint16_t Value) {
246246 if (IsTargetLittleEndian)
247 Value = sys::getSwappedBytes(Value);
247 sys::swapByteOrder(Value);
248248 *Addr = (Value >> 8) & 0xFF;
249249 *(Addr + 1) = Value & 0xFF;
250250 }
251251
252252 void writeInt32BE(uint8_t *Addr, uint32_t Value) {
253253 if (IsTargetLittleEndian)
254 Value = sys::getSwappedBytes(Value);
254 sys::swapByteOrder(Value);
255255 *Addr = (Value >> 24) & 0xFF;
256256 *(Addr + 1) = (Value >> 16) & 0xFF;
257257 *(Addr + 2) = (Value >> 8) & 0xFF;
260260
261261 void writeInt64BE(uint8_t *Addr, uint64_t Value) {
262262 if (IsTargetLittleEndian)
263 Value = sys::getSwappedBytes(Value);
263 sys::swapByteOrder(Value);
264264 *Addr = (Value >> 56) & 0xFF;
265265 *(Addr + 1) = (Value >> 48) & 0xFF;
266266 *(Addr + 2) = (Value >> 40) & 0xFF;
11781178 if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
11791179 return false;
11801180 if (sys::IsLittleEndianHost)
1181 Size = sys::getSwappedBytes(Size);
1181 sys::swapByteOrder(Size);
11821182 CompressedContents.insert(CompressedContents.begin(),
11831183 Magic.size() + sizeof(Size), 0);
11841184 std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
2020 if (de->isValidOffsetForDataOfSize(offset, sizeof(val))) {
2121 std::memcpy(&val, &Data[offset], sizeof(val));
2222 if (sys::IsLittleEndianHost != isLittleEndian)
23 val = sys::getSwappedBytes(val);
23 sys::swapByteOrder(val);
2424
2525 // Advance the offset
2626 *offset_ptr += sizeof(val);