[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.
GitOrigin-RevId: 7554007c806e5fdcfd4b034c2a462089428890da
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index 0a91351..800894c 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -42,6 +42,7 @@
       aio
       arpa/inet
       assert
+      byteswap
       cpio
       ctype
       dirent
diff --git a/docs/headers/index.rst b/docs/headers/index.rst
index 528f995..a10f2b6 100644
--- a/docs/headers/index.rst
+++ b/docs/headers/index.rst
@@ -7,6 +7,7 @@
    aio
    arpa/inet
    assert
+   byteswap
    complex
    cpio
    ctype
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index aa3791b..fac2b40 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -230,6 +230,15 @@
 )
 
 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
   complex.h
diff --git a/include/byteswap.yaml b/include/byteswap.yaml
new file mode 100644
index 0000000..3b47c3b
--- /dev/null
+++ b/include/byteswap.yaml
@@ -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: []
diff --git a/include/llvm-libc-macros/CMakeLists.txt b/include/llvm-libc-macros/CMakeLists.txt
index 86085b5..af74d48 100644
--- a/include/llvm-libc-macros/CMakeLists.txt
+++ b/include/llvm-libc-macros/CMakeLists.txt
@@ -49,6 +49,12 @@
 )
 
 add_macro_header(
+  byteswap_macros
+  HDR
+    byteswap-macros.h
+)
+
+add_macro_header(
   error_number_macros
   HDR
     error-number-macros.h
diff --git a/include/llvm-libc-macros/byteswap-macros.h b/include/llvm-libc-macros/byteswap-macros.h
new file mode 100644
index 0000000..aa8d047
--- /dev/null
+++ b/include/llvm-libc-macros/byteswap-macros.h
@@ -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
diff --git a/utils/docgen/byteswap.yaml b/utils/docgen/byteswap.yaml
new file mode 100644
index 0000000..202946f
--- /dev/null
+++ b/utils/docgen/byteswap.yaml
@@ -0,0 +1,8 @@
+macros:
+  bswap_16:
+    c-definition: ''
+  bswap_32:
+    c-definition: ''
+  bswap_64:
+    c-definition: ''
+