[libc] Add byteswap.h header with bswap_16/bswap_32/bswap_64 (#196278)

Added the Linux byteswap.h header providing bswap_16, bswap_32, and
bswap_64 as macros expanding to __builtin_bswap{16,32,64}. These are
always inlined by the compiler to single instructions.

Follows the existing endian.h / endian-macros.h pattern.

Assisted-by: Automated tooling, human reviewed.
This commit is contained in:
Jeff Bailey authored and GitHub committed 2026-05-07 14:33:33 +01:00
1 parent 37f826aa9e
commit 7554007c80
7 files changed
+60

No files matched your search

+1
View File
@@ -42,6 +42,7 @@ if (SPHINX_FOUND)
aio
arpa/inet
assert
byteswap
cpio
ctype
dirent
+1
View File
@@ -7,6 +7,7 @@ Implementation Status
aio
arpa/inet
assert
byteswap
complex
cpio
ctype
+9
View File
@@ -229,6 +229,15 @@ add_header_macro(
.llvm-libc-macros.assert_macros
)
add_header_macro(
byteswap
../libc/include/byteswap.yaml
byteswap.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-macros.byteswap_macros
)
add_header_macro(
complex
../libc/include/complex.yaml
+14
View File
@@ -0,0 +1,14 @@
header: byteswap.h
standards:
- linux
macros:
- macro_name: bswap_16
macro_header: byteswap-macros.h
- macro_name: bswap_32
macro_header: byteswap-macros.h
- macro_name: bswap_64
macro_header: byteswap-macros.h
types: []
enums: []
objects: []
functions: []
@@ -48,6 +48,12 @@ add_macro_header(
assert-macros.h
)
add_macro_header(
byteswap_macros
HDR
byteswap-macros.h
)
add_macro_header(
error_number_macros
HDR
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Definition of macros from byteswap.h.
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIBC_MACROS_BYTESWAP_MACROS_H
#define LLVM_LIBC_MACROS_BYTESWAP_MACROS_H
#define bswap_16(x) __builtin_bswap16((x))
#define bswap_32(x) __builtin_bswap32((x))
#define bswap_64(x) __builtin_bswap64((x))
#endif // LLVM_LIBC_MACROS_BYTESWAP_MACROS_H
+8
View File
@@ -0,0 +1,8 @@
macros:
bswap_16:
c-definition: ''
bswap_32:
c-definition: ''
bswap_64:
c-definition: ''