[1/3] RISC-V: Add a macro definition file to check whether the compiler supports extensions.

Message ID 20240702134124.74121-1-jz531210@gmail.com
State Superseded
Headers
Series [1/3] RISC-V: Add a macro definition file to check whether the compiler supports extensions. |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Julian Zhu July 2, 2024, 1:41 p.m. UTC
  Some extensions of RISC-V are only available in relatively newer compiler. These macro definition can prevent the use of extensions in unsupported compiler.

Signed-off-by: Julian Zhu <jz531210@gmail.com>
---
 sysdeps/riscv/compiler-ext-avail.h | 53 ++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 sysdeps/riscv/compiler-ext-avail.h
  

Patch

diff --git a/sysdeps/riscv/compiler-ext-avail.h b/sysdeps/riscv/compiler-ext-avail.h
new file mode 100644
index 0000000000..6b2d92e437
--- /dev/null
+++ b/sysdeps/riscv/compiler-ext-avail.h
@@ -0,0 +1,53 @@ 
+/* Copyright (C) 2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This file is used to define whether extensions are available
+   in the compiler.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _COMPILER_EXT_AVAIL_H
+#define _COMPILER_EXT_AVAIL_H 1
+
+/* Zba, Zbb, Zbc, and Zbs are available after gcc 12 or llvm 14 */
+
+#if (defined __GNUC__                                                         \
+     && (__GNUC__ > 12 || (__GNUC__ >= 12 && __GNUC_MINOR__ >= 1)))           \
+    || (defined __clang__ && __clang_major__ >= 14)
+#  define COMPILER_ZBA_AVAIL 1
+#  define COMPILER_ZBB_AVAIL 1
+#  define COMPILER_ZBC_AVAIL 1
+#  define COMPILER_ZBS_AVAIL 1
+#else
+#  define COMPILER_ZBA_AVAIL 0
+#  define COMPILER_ZBB_AVAIL 0
+#  define COMPILER_ZBC_AVAIL 0
+#  define COMPILER_ZBS_AVAIL 0
+#endif
+
+/* XTHeadBa, XTHeadBb, and XTHeadBs are available after gcc 13 or llvm 17 */
+#if (defined __GNUC__                                                         \
+     && (__GNUC__ > 13 || (__GNUC__ >= 13 && __GNUC_MINOR__ >= 1)))           \
+    || (defined __clang__ && __clang_major__ >= 17)
+#  define COMPILER_XTHEADBA_AVAIL 1
+#  define COMPILER_XTHEADBB_AVAIL 1
+#  define COMPILER_XTHEADBS_AVAIL 1
+#else
+#  define COMPILER_XTHEADBA_AVAIL 0
+#  define COMPILER_XTHEADBB_AVAIL 0
+#  define COMPILER_XTHEADBS_AVAIL 0
+#endif
+
+#endif /* compiler-ext-avail.h */