[libc-commits] [libc] [libc] implement endian related macros (PR #126368)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Feb 10 11:01:47 PST 2025


================
@@ -9,8 +9,42 @@
 #ifndef LLVM_LIBC_MACROS_ENDIAN_MACROS_H
 #define LLVM_LIBC_MACROS_ENDIAN_MACROS_H
 
+#include "stdint-macros.h"
+
 #define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
 #define BIG_ENDIAN __ORDER_BIG_ENDIAN__
 #define BYTE_ORDER __BYTE_ORDER__
 
+#if BYTE_ORDER == LITTLE_ENDIAN
+
+#define htobe16(x) __builtin_bswap16((x))
+#define htobe32(x) __builtin_bswap32((x))
+#define htobe64(x) __builtin_bswap64((x))
+#define htole16(x) ((uint16_t)(x))
----------------
nickdesaulniers wrote:

> If we do, then we should fully qualify the include path to stdint-macros.h. While it may build with cmake, we do have downstream consumers that aren't using cmake; and they require fully qualified paths for these headers.

Sorry, that's wrong. Nevermind that point.  But the question still stands about the casts.

https://github.com/llvm/llvm-project/pull/126368


More information about the libc-commits mailing list