[v2,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-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
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
Comments
Ping.
在 2024/7/7 22:58, Julian Zhu 写道:
> 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
>
> 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 */
I don't think this is a good idea. It would be hard to maintain all the supported extensions for different compilers and different versions.
If you need to check whether an RISC-V extension (and version) is supported by a compiler, there are predefined macros based on the given -march.
For example:
$ echo "" | riscv64-unknown-elf-gcc -march=rv64gc_zba -dM -E - | grep zba
#define __riscv_zba 1000000
Best,
Hau Hsu
> On Jul 30, 2024, at 5:13 PM, Julian Zhu <jz531210@gmail.com> wrote:
>
> Ping.
>
> 在 2024/7/7 22:58, Julian Zhu 写道:
>> 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
>>
>> 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 */
new file mode 100644
@@ -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 */