Skip to content
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

Intrinsics: Define intrinsics naming guidelines #31

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

cmuellner
Copy link
Collaborator

Let's establish a naming guideline for intrinsics.

Contrary to the previous attempt in #25, this PR does not try to make a guideline that covers all existing formats but defines a single new format.

@cmuellner
Copy link
Collaborator Author

CC @kito-cheng @asb

@cmuellner
Copy link
Collaborator Author

CC @eopXD

riscv-c-api.md Outdated
`gcc/gcc/config/riscv/riscv-builtins.c`...
Intrinsic functions (or intrinsics or built-ins) are functions that are expanded into instruction sequences by compilers.
They typically provide access to functionality that is otherwise not synthesizable by compilers.
Some intrinsics expand to different code sequenzes, depending on the available instructions from the enabled ISA extensions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequenzes -> sequences

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

riscv-c-api.md Outdated
int32_t __rv_orc_b_32(int32_t rs);

vadd.vv vd, vs2, vs1:
vint8m1_t __rv_vadd_vv_i8m1(vint8m1_t vs2, vint8m1_t vs1, size_t vl);
Copy link
Contributor

@eopXD eopXD Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably missing an optional naming rule on "type abbreviation" (e.g. the i here)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add. Thanks!

@cmuellner
Copy link
Collaborator Author

@ptomsich mentioned in today's SIG Toolchain call that he prefers __riscv_ as prefix over __rv_. There were no objections, so I'll update the PR accordingly.

@rjiejie
Copy link

rjiejie commented Nov 23, 2022

Shall we need to consider about customized or vendor's intrinsic name ?
like __riscv_<vendor>_ ?
e.g. __riscv_thead_

@cmuellner
Copy link
Collaborator Author

I've updated the PR according to the feedback so far.

Regarding the vendor-specific intrinsics, I have no opinion yet. But I think the proposal sounds reasonable. Thanks!

@cmuellner
Copy link
Collaborator Author

Regarding the vendor instructions, I don't see why we need a vendor prefix because the instructions are already prefixed (e.g. th.mula -> __riscv_th_mula). Do you think we need more?

@kito-cheng
Copy link
Collaborator

Generally LGTM :)

Regarding the vendor instructions, I don't see why we need a vendor prefix because the instructions are already prefixed (e.g. th.mula -> __riscv_th_mula). Do you think we need more?

__riscv_th or __riscv_thead are both valid on current scheme I think.

@cmuellner
Copy link
Collaborator Author

__riscv_th or __riscv_thead are both valid on current scheme I think.

I think that all vendor-specific intrinsics would only be covering vendor-instructions. In this case, the instruction's name is the preferred choice for the name. Therefore __riscv_th would be used for T-Head-specific intrinsics.

@rjiejie
Copy link

rjiejie commented Dec 8, 2022

Regarding the vendor instructions, I don't see why we need a vendor prefix because the instructions are already prefixed (e.g. th.mula -> __riscv_th_mula). Do you think we need more?

Looks like it's a choice although the prefix 'th' have no obvious meaning about vendor's info in user side :)

@cmuellner
Copy link
Collaborator Author

Regarding the vendor instructions, I don't see why we need a vendor prefix because the instructions are already prefixed (e.g. th.mula -> __riscv_th_mula). Do you think we need more?

Looks like it's a choice although the prefix 'th' have no obvious meaning about vendor's info in user side :)

The vendor prefixes are required for vendor instructions.
Therefore they are standardized in the riscv-toolchain-conventions: https://github.com/riscv-non-isa/riscv-toolchain-conventions/blob/master/README.mkd#list-of-vendor-prefixes

E.g. in Binutils all instructions of the T-Head vendor extensions have the prefix "th" (e.g. "th.ldd" which is part of XTheadMemPair).

I'll add the following sentence:

Note, that intrinsics that are restricted to RISC-V vendor extensions need to include the vendor-prefix (as documented in the RISC-V toolchain conventions).

Providing functionality via architecture-independent intrinsics is the preferred method, as it improves code portability.

Some intrinsics are only available if a particular header file is included.
RISC-V header files that enable intrinsics require the prefix `riscv_` (e.g. `riscv_vector.h` or `riscv_crypto.h`).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any rules about the header file naming if header file required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer: no rules beyond the prefix riscv_.

The reason is that this guide cannot foresee which grouping makes sense.
E.g. vector crypto instructions might be gated by riscv_vector.h, riscv_vector_crypto.h, or riscv_crypto.h. All of them would be valid candidates (maybe even multiple options), so this will have to be decided on a case-by-case basis.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, and it will be good to have same filename naming rule for different toolchains.

Copy link
Collaborator

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Giving my blessing of this PR, hope this could push this forward :)

@cmuellner
Copy link
Collaborator Author

Thanks for the approval!
I'll merge this later today.

Let's establish a naming guideline for intrinsics.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
@cmuellner
Copy link
Collaborator Author

I got the feedback that the CMO examples are confusing. Therefore I dropped them.

@cmuellner
Copy link
Collaborator Author

This was discussed (again) in today's SIG Toolchain call, and there were no objections to this proposal.

@cmuellner cmuellner merged commit dccfa30 into riscv-non-isa:master Jan 30, 2023
eopXD added a commit to llvm/llvm-project that referenced this pull request Jan 31, 2023
…setvl, and vsetvlmax

This commit adds prefix for intrinsics that are defined through
`HeaderCode` under `riscv_vector.td`.

This is the 1st commit of a patch-set to add `__riscv_` for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142016.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142085
eopXD added a commit to llvm/llvm-project that referenced this pull request Jan 31, 2023
This commit adds prefix for the non-overloaded RVV intrinsics.

This is the 2nd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142085.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142644
eopXD added a commit to llvm/llvm-project that referenced this pull request Jan 31, 2023
This commit adds prefix for the non-overloaded RVV intrinsics.

This is the 2nd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142085.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142644
eopXD added a commit to llvm/llvm-project that referenced this pull request Jan 31, 2023
This commit adds prefix for the overloaded RVV intrinsics.

This is the 3rd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142644.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142697
eopXD added a commit to riscv-non-isa/rvv-intrinsic-doc that referenced this pull request Feb 1, 2023
Linking to riscv-non-isa/riscv-c-api-doc#31

Signed-off-by: eop Chen <eop.chen@sifive.com>
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this pull request Feb 1, 2023
…setvl, and vsetvlmax

This commit adds prefix for intrinsics that are defined through
`HeaderCode` under `riscv_vector.td`.

This is the 1st commit of a patch-set to add `__riscv_` for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142016.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142085
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this pull request Feb 1, 2023
This commit adds prefix for the non-overloaded RVV intrinsics.

This is the 2nd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142085.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142644
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this pull request Feb 1, 2023
This commit adds prefix for the non-overloaded RVV intrinsics.

This is the 2nd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142085.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142644
CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this pull request Feb 1, 2023
This commit adds prefix for the overloaded RVV intrinsics.

This is the 3rd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142644.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142697
tru pushed a commit to llvm/llvm-project-release-prs that referenced this pull request Feb 5, 2023
…setvl, and vsetvlmax

This commit adds prefix for intrinsics that are defined through
`HeaderCode` under `riscv_vector.td`.

This is the 1st commit of a patch-set to add `__riscv_` for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142016.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142085
tru pushed a commit to llvm/llvm-project-release-prs that referenced this pull request Feb 5, 2023
This commit adds prefix for the non-overloaded RVV intrinsics.

This is the 2nd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142085.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142644
tru pushed a commit to llvm/llvm-project-release-prs that referenced this pull request Feb 5, 2023
This commit adds prefix for the overloaded RVV intrinsics.

This is the 3rd commit of a patch-set to add __riscv_ for all RVV
intrinsics.

This follows the naming guideline under riscv-c-api-doc to add the
`__riscv_` suffix for all RVV intrinsics.

Pull Request:
riscv-non-isa/riscv-c-api-doc#31
riscv-non-isa/rvv-intrinsic-doc#189

Depends on D142644.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D142697
@nick-knight
Copy link

I'm hesitant to say anything, because adding the __riscv_ prefix to our vector intrinsics across the codebase has been a huge productivity killer this week. And it makes the already-lengthy vector intrinsics even more annoying to type. But I just want to confirm that you aren't also planning to require some kind of prefix for the RVV intrinsics types (vint8m8_t, etc.).

@Firdous24
Copy link

Which version/release/branch of riscv-gnu-toolchain supports the prefix "_riscv" in RVV intrinsic? As I have cloned the latest version of toolchain but it doesn't support the _riscv prefix.

@cmuellner
Copy link
Collaborator Author

I'm hesitant to say anything, because adding the __riscv_ prefix to our vector intrinsics across the codebase has been a huge productivity killer this week. And it makes the already-lengthy vector intrinsics even more annoying to type.

The __riscv_ prefix was agreed upon before merging this PR with the toolchain community.
This was not done to kill productivity but to avoid namespace conflicts in the future.
But I appreciate the required work to change code that uses the intrinsics.
We should have defined this earlier.

But I just want to confirm that you aren't also planning to require some kind of prefix for the RVV intrinsics types (vint8m8_t, etc.).

We explicitly dropped type prefixes, because there was no obvious consensus.
Therefore this has to be worked out by the RVV intrinsics TG as part of the RVV intrinsics spec.

Which version/release/branch of riscv-gnu-toolchain supports the prefix "_riscv" in RVV intrinsic? As I have cloned the latest version of toolchain but it doesn't support the _riscv prefix.

As mentioned by Kito:

GCC 13 will support latest intrinsic, which will release at end of April in general, you can switch gcc to master branch if you want to get a try now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants