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

riscv: Add bitmanip instructions to emitter #16832

Merged
merged 2 commits into from
Jan 22, 2023

Conversation

unknownbrackets
Copy link
Collaborator

Like vector, this has also been ratified. Fairly simple, adds a few things that would be useful.

-[Unknown]

@unknownbrackets unknownbrackets added this to the v1.15.0 milestone Jan 22, 2023
@hrydgard
Copy link
Owner

Makes me curious, does RISC-V have some kind of CPUID type instruction that works in user mode, so we can check for the extensions without reading from /proc or something, or not? Always felt it's silly that ARM doesn't have that..

@hrydgard hrydgard merged commit 3bc2450 into hrydgard:master Jan 22, 2023
@hrydgard
Copy link
Owner

Whoops, accidentally squash-merged because github saved tha state, sigh. Oh well.

@unknownbrackets unknownbrackets deleted the riscv-bitmanip branch January 22, 2023 20:40
@unknownbrackets
Copy link
Collaborator Author

unknownbrackets commented Jan 22, 2023

Makes me curious, does RISC-V have some kind of CPUID type instruction that works in user mode, so we can check for the extensions without reading from /proc or something, or not? Always felt it's silly that ARM doesn't have that..

So kinda yes, but I'm confused about how you're supposed to do this.

The extensions that are a single letter (this one's B, the last one's V) set a bit in a CSR that can be read by the letter index (A=0.) However, this bit can indicate if the extension is enabled/supported at machine/hypervisor/etc. level only and is more of a privileged thing. We use getauxval(AT_HWCAP) to get the current state for user-mode. I don't know if there's a better way.

Zmmul, Zicsr, half-floats, and some other things have "Z" extensions. These don't get a bit, so I don't really understand how to detect them. It seems like they're only in /proc or /sys or something, and not sure on BSD. Because of this, I'm not sure how to tell if Zicsr is enabled but it's the only way I know of to set frm (float rounding mode) or read vl (otherwise VLEFF_V is kinda useless.) It's probably gonna be enabled everywhere...

One can use getauxval on ARM as well:
https://community.arm.com/arm-community-blogs/b/operating-systems-blog/posts/runtime-detection-of-cpu-features-on-an-armv8-a-cpu
https://www.kernel.org/doc/html/v5.3/arm64/elf_hwcaps.html

This should be the most platform independent way to do it (FreeBSD on ARM64, etc. too.) Though beware:
microsoft/WSL#3682

-[Unknown]

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.

2 participants