-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add misc macro for vector extensions. #21
Conversation
@rdolbeau @nick-knight @HanKuanChen @topperc @Hsiangkai @zakk0610 @JerryShih @rjiejie @rofirrim you might interested on this. @jrtc27 @asb @luismarques you might not so interested, but we need LLVM folks :p |
Because these macros belong to v extension, should not we add |
Will there be some mechanism so that when compiling for zvl512b, the binary won't be able to run on a zvl256b-or-smaller machine? |
We will encode [1] https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#list-of-attributes |
Sounds good to me, let me update :) |
549e7e1
to
b60c3fd
Compare
Changes:
|
Changes:
|
riscv-c-api.md
Outdated
|
||
- `__riscv_v_max_eew_fp` is 64 if `V` or `Zve64d` extension is available. | ||
- `__riscv_v_max_eew_fp` is 32 if `Zve32f` or `Zve64f` extension is available. | ||
- `__riscv_v_max_eew_fp` is 0 if `Zve64x` or `Zve32x` extension is available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it define as 0, instead of undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention is make sure this marco is always defined if vector extension is available, so we only need to check __riscv_v_max_eew_fp
is larger than our requirement once we ensure the vector extension is available.
e.g.
#ifdef __riscv_v_max_eew
#error "NO vector extension supported"
#endif
#if __riscv_v_max_eew_fp > 64
...
#endif
Rather than
#ifdef __riscv_v_max_eew
#error "NO vector extension supported"
#endif
#if defined(__riscv_v_max_eew_fp) && __riscv_v_max_eew_fp >= 64
...
#endif
+1 |
Is |
There are other wrinkles related to ELEN and |
My intention is to simplify the marco feature checking by Checking ELEN / EEW support 64 require checking There is a list of instruction with EEW=64 are excluded from So I would prefer to keep those marco. |
I agree that it might be cumbersome for the user to check multiple of the six extant I guess my concerns are really just the two special cases I mentioned:
Users of these instructions will need to be aware of these details and check other macros besides |
Changes:
|
@aswaterman @kasanovic @nick-knight do you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kito-cheng I have some suggestions for the wording and formatting. I don't think I've changed any of the semantics.
I still think we should have __riscv_zve*
macros, but that can be a separate PR.
I got mail but not saw the message on github, anyway I'll merge those stuffs, thanks for your review comment! |
0efd343
to
e2a9803
Compare
Changes:
|
`zvl` is the new standard vector extension that specifies the minimum vector length of the vector extension. The `zvl` extension is related to the `zve` extension and other updates that are added in v1.0. According to riscv-non-isa/riscv-c-api-doc#21, Clang defines macro `__riscv_v_min_vlen` for `zvl` and it can be used for applications that uses the vector extension. LLVM checks whether the option `riscv-v-vector-bits-min` (if specified) matches the `zvl*` extension specified. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D108694
Did we reach consensus on whether The spec defines ELEN as Section 3.4.2 includes these sentences I take "standard vector extensions with ELEN=32" to mean Zve32x, Zve32f. And "standard vector extensions with ELEN=64" to mean Zve64x, Zve64f, Zve64d, and V. So to me it feels like |
ELEN works for the purpose of knowing the largest size individual element. Some instructions, like SiFive matrix ops, effectively operate on larger units (e.g., 256b) but they are treated as vectors/aggregates of smaller elements, with the aggregate delimited by using larger vl rather than a larger SEW/EEW. There will be some debate as we add vector crypto on how to handle this for long crypto blocks, and not sure how that will land yet. |
Sounds like ELEN is more right term here, let me update that. |
Changes:
|
@aswaterman @kasanovic @nick-knight let me know if look good to you :) |
@kito-cheng I don't see any harm in the current proposal, as long as we still plan to add |
@nick-knight Sure, macro for |
@asb @frasercrmck @topperc @rdolbeau would you mind give an explicit LGTM if that's OK to you? thanks :) |
`zve` is the new standard vector extension to specify varying degrees of vector support for embedding processors. The `zve` extension is related to the `zvl` extension and other updates that are added in v1.0. According to riscv-non-isa/riscv-c-api-doc#21, Clang defines macro `__riscv_v_max_elen`, `__riscv_v_max_elen_fp` for `zve` and it can be used by applications that uses the vector extension. Authored by: Zakk Chen <zakk.chen@sifive.com> @khchen Co-Authored by: Eop Chen <eop.chen@sifive.com> @eopXD Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D112408
Looks good other than minor clarifications |
@@ -39,6 +39,59 @@ https://creativecommons.org/licenses/by/4.0/. | |||
| __riscv_xlen | <ul><li>32 for rv32</li><li>64 for rv64</li><li>128 for rv128</ul> | Always defined. | | |||
| __riscv_flen | <ul><li>32 if the F extension is available **or**</li><li>64 if `D` extension available **or**</li><li>128 if `Q` extension available</li></ul> | `F` extension is available. | | |||
| __riscv_32e | 1 | `E` extension is available. | | |||
| __riscv_v_min_vlen | <N> (see [__riscv_v_min_vlen](#__riscv_v_min_vlen)) | The `V` extension or one of the `Zve*` extensions is available. | | |||
| __riscv_v_elen | <N> (see [__riscv_v_elen](#__riscv_v_elen)) | The `V` extension or one of the `Zve*` extensions is available. | | |||
| __riscv_v_elen_fp | <N> (see [__riscv_v_elen_fp](#__riscv_v_elen_fp)) | The `V` extension or one of the `Zve*` extensions is available. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The when defined for __riscv_v_elen_fp
isn't quite right. zve32x/zve64x don't define this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zve32x
and zve64x
still define that but defined as 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops I missed that. Thanks.
Craig and Fraser have done much more with the vector spec than I have, so I'm happy if they're happy. |
LGTM |
Introduce `__riscv_min_vlen`, `__riscv_v_elen` and `__riscv_v_elen_fp` macro, for let programer easier to get vector related information, like: - What's the minimal VLEN value is guaranteed current architecture extension? - What's the maximal available ELEN is guaranteed current architecture extension? - What's the maximal available ELEN for floating-point operation is guaranteed current architecture extension? It's possible to get the information by testing serveral architecture extension test macro, but the life can be simpler if toolchain can help, for example, if you want to check the minimal VLEN value via those macro: ```c #if defined(__riscv_zvl512b) #define __riscv_min_vlen 512 #elif defined(__riscv_zvl256b) #define __riscv_min_vlen 256 #elif defined(__riscv_zvl128b) || defined(__riscv_v) #define __riscv_min_vlen 128 #elif defined(__riscv_zvl64b) || defined(__riscv_zve64x) || \ defined(__riscv_zve64f) || defined(__riscv_zve64d) #define __riscv_min_vlen 64 #elif defined(__riscv_zvl32b) || defined(__riscv_zve32x) || \ defined(__riscv_zve32f) #define __riscv_min_vlen 32 #endif ``` And it's not scalable solution since in theory we can have up to zvl32768b.
2b59115
to
2a3b3a8
Compare
Gonna merge this, we got approval from GNU and LLVM community and vector ext. are ratified ext. |
See also: riscv-non-isa/riscv-c-api-doc#21 gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_ext_flag_table): Update flag name and mask name. * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Define misc macro for vector extensions. * config/riscv/riscv-opts.h (MASK_VECTOR_EEW_32): Rename to ... (MASK_VECTOR_ELEN_32): ... this. (MASK_VECTOR_EEW_64): Rename to ... (MASK_VECTOR_ELEN_64): ... this. (MASK_VECTOR_EEW_FP_32): Rename to ... (MASK_VECTOR_ELEN_FP_32): ... this. (MASK_VECTOR_EEW_FP_64): Rename to ... (MASK_VECTOR_ELEN_FP_64): ... this. (TARGET_VECTOR_ELEN_32): New. (TARGET_VECTOR_ELEN_64): Ditto. (TARGET_VECTOR_ELEN_FP_32): Ditto. (TARGET_VECTOR_ELEN_FP_64): Ditto. (TARGET_MIN_VLEN): Ditto. * config/riscv/riscv.opt (riscv_vector_eew_flags): Rename to ... (riscv_vector_elen_flags): ... this. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-13.c: New. * gcc.target/riscv/arch-14.c: Ditto. * gcc.target/riscv/arch-15.c: Ditto. * gcc.target/riscv/predef-18.c: Ditto. * gcc.target/riscv/predef-19.c: Ditto. * gcc.target/riscv/predef-20.c: Ditto.
See also: riscv-non-isa/riscv-c-api-doc#21 gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_ext_flag_table): Update flag name and mask name. * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Define misc macro for vector extensions. * config/riscv/riscv-opts.h (MASK_VECTOR_EEW_32): Rename to ... (MASK_VECTOR_ELEN_32): ... this. (MASK_VECTOR_EEW_64): Rename to ... (MASK_VECTOR_ELEN_64): ... this. (MASK_VECTOR_EEW_FP_32): Rename to ... (MASK_VECTOR_ELEN_FP_32): ... this. (MASK_VECTOR_EEW_FP_64): Rename to ... (MASK_VECTOR_ELEN_FP_64): ... this. (TARGET_VECTOR_ELEN_32): New. (TARGET_VECTOR_ELEN_64): Ditto. (TARGET_VECTOR_ELEN_FP_32): Ditto. (TARGET_VECTOR_ELEN_FP_64): Ditto. (TARGET_MIN_VLEN): Ditto. * config/riscv/riscv.opt (riscv_vector_eew_flags): Rename to ... (riscv_vector_elen_flags): ... this. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-13.c: New. * gcc.target/riscv/arch-14.c: Ditto. * gcc.target/riscv/arch-15.c: Ditto. * gcc.target/riscv/predef-18.c: Ditto. * gcc.target/riscv/predef-19.c: Ditto. * gcc.target/riscv/predef-20.c: Ditto.
`zvl` is the new standard vector extension that specifies the minimum vector length of the vector extension. The `zvl` extension is related to the `zve` extension and other updates that are added in v1.0. According to riscv-non-isa/riscv-c-api-doc#21, Clang defines macro `__riscv_v_min_vlen` for `zvl` and it can be used for applications that uses the vector extension. LLVM checks whether the option `riscv-v-vector-bits-min` (if specified) matches the `zvl*` extension specified. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D108694
`zve` is the new standard vector extension to specify varying degrees of vector support for embedding processors. The `zve` extension is related to the `zvl` extension and other updates that are added in v1.0. According to riscv-non-isa/riscv-c-api-doc#21, Clang defines macro `__riscv_v_max_elen`, `__riscv_v_max_elen_fp` for `zve` and it can be used by applications that uses the vector extension. Authored by: Zakk Chen <zakk.chen@sifive.com> @khchen Co-Authored by: Eop Chen <eop.chen@sifive.com> @eopXD Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D112408
See also: riscv-non-isa/riscv-c-api-doc#21 gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_ext_flag_table): Update flag name and mask name. * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Define misc macro for vector extensions. * config/riscv/riscv-opts.h (MASK_VECTOR_EEW_32): Rename to ... (MASK_VECTOR_ELEN_32): ... this. (MASK_VECTOR_EEW_64): Rename to ... (MASK_VECTOR_ELEN_64): ... this. (MASK_VECTOR_EEW_FP_32): Rename to ... (MASK_VECTOR_ELEN_FP_32): ... this. (MASK_VECTOR_EEW_FP_64): Rename to ... (MASK_VECTOR_ELEN_FP_64): ... this. (TARGET_VECTOR_ELEN_32): New. (TARGET_VECTOR_ELEN_64): Ditto. (TARGET_VECTOR_ELEN_FP_32): Ditto. (TARGET_VECTOR_ELEN_FP_64): Ditto. (TARGET_MIN_VLEN): Ditto. * config/riscv/riscv.opt (riscv_vector_eew_flags): Rename to ... (riscv_vector_elen_flags): ... this. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-13.c: New. * gcc.target/riscv/arch-14.c: Ditto. * gcc.target/riscv/arch-15.c: Ditto. * gcc.target/riscv/predef-18.c: Ditto. * gcc.target/riscv/predef-19.c: Ditto. * gcc.target/riscv/predef-20.c: Ditto.
See also: riscv-non-isa/riscv-c-api-doc#21 gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_ext_flag_table): Update flag name and mask name. * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Define misc macro for vector extensions. * config/riscv/riscv-opts.h (MASK_VECTOR_EEW_32): Rename to ... (MASK_VECTOR_ELEN_32): ... this. (MASK_VECTOR_EEW_64): Rename to ... (MASK_VECTOR_ELEN_64): ... this. (MASK_VECTOR_EEW_FP_32): Rename to ... (MASK_VECTOR_ELEN_FP_32): ... this. (MASK_VECTOR_EEW_FP_64): Rename to ... (MASK_VECTOR_ELEN_FP_64): ... this. (TARGET_VECTOR_ELEN_32): New. (TARGET_VECTOR_ELEN_64): Ditto. (TARGET_VECTOR_ELEN_FP_32): Ditto. (TARGET_VECTOR_ELEN_FP_64): Ditto. (TARGET_MIN_VLEN): Ditto. * config/riscv/riscv.opt (riscv_vector_eew_flags): Rename to ... (riscv_vector_elen_flags): ... this. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-13.c: New. * gcc.target/riscv/arch-14.c: Ditto. * gcc.target/riscv/arch-15.c: Ditto. * gcc.target/riscv/predef-18.c: Ditto. * gcc.target/riscv/predef-19.c: Ditto. * gcc.target/riscv/predef-20.c: Ditto.
Changes:
2021/08/19: Apply Fraser's fix.
2021/08/19: Change prefix to
__riscv_v_
Background
RVV 1.0 has add few more extension (
zvl*b
andzve*
) to give the promise about the EEW and VLEN, and this PR intend to expose those info by predefined marco.https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#sec-vector-extensions
Introduce
__riscv_v_min_vlen
,__riscv_v_max_eew
and__riscv_v_max_eew_fp
macro, for let programer easier to get vector related information, like:
extension?
architecture extension?
guaranteed current architecture extension?
It's possible to get the information by testing serveral architecture extension
test macro, but the life can be simpler if toolchain can help, for
example, if you want to check the minimal VLEN value via those macro:
And it's not scalable solution since in theory we can have up to zvl32768b...