James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 1 | From 34f44d312c918b3b5dd69fc689ec0b628dc712f9 Mon Sep 17 00:00:00 2001 |
| 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Thu, 19 May 2022 01:12:41 -0400 |
| 4 | Subject: [PATCH 26/28] constexpr endian byte swap |
| 5 | |
| 6 | --- |
| 7 | llvm/include/llvm/Support/Endian.h | 4 +++- |
| 8 | 1 file changed, 3 insertions(+), 1 deletion(-) |
| 9 | |
| 10 | diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h |
| 11 | index 5e7c1e961..2e883ff05 100644 |
| 12 | --- a/llvm/include/llvm/Support/Endian.h |
| 13 | +++ b/llvm/include/llvm/Support/Endian.h |
| 14 | @@ -55,7 +55,9 @@ inline value_type byte_swap(value_type value, endianness endian) { |
| 15 | /// Swap the bytes of value to match the given endianness. |
| 16 | template<typename value_type, endianness endian> |
| 17 | inline value_type byte_swap(value_type value) { |
| 18 | - return byte_swap(value, endian); |
| 19 | + if constexpr ((endian != native) && (endian != system_endianness())) |
| 20 | + sys::swapByteOrder(value); |
| 21 | + return value; |
| 22 | } |
| 23 | |
| 24 | /// Read a value of a particular endianness from memory. |