-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: architecture definitions for RISC-V ISA #73437
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsBackground and motivationRISC-V is the fifth generation of RISC architecture, which is currently supported by mono; while the coreclr port is in progress. We should add the relevant identifiers visible for consumers and to the higher-level APIs. API ProposalRef: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types namespace System.Runtime.InteropServices;
public enum Architecture
{
...
+ Riscv64,
}
namespace System.Reflection.PortableExecutable;
public enum Machine : ushort
{
...
+ Riscv32 = 0x5232,
+ Riscv64 = 0x5264
+ Riscv128 = 0x5128,
} API Usageint GetArchMagic(Architecture arch) => arch switch
{
Architecture.Riscv64 => 42,
} Alternative DesignsRISC-V is an open-source and modular architecture. Its support is often expressed in terms of 'extensions'. We should provide Another twist is that the capability of RISC-V may differ by CPU core or hardware thread (ISA term is RisksYes, it literally is RISC-y. Just kidding, it is low risk, high reward! 8-)
|
These numbers do not match the numbers in https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types |
Fixed, thanks. |
Which ISA base does this imply? RV32I or RV32E? Would it make sense to have one for each? If it's only for RV32I (or possibly RV32E) would it make sense to be explicit in the name? Or do we imagine these values covering both base ISAs? |
Unfortunately, it doesn't seem like that was considered when adding these machine types to the PE spec. It would probably be reasonable to assume that they effectively mean RV32I, considering RV32E hasn't been formally ratified yet. If RV32E is ratified, there would likely need to be new machine types added for it, similar to how there are separate machine types for Arm, Arm Thumb, and Arm Thumb-2. But that's all up to whoever is in charge of the PE spec. The .NET
RV32E is (roughly) to RISC-V what T32 is to Arm. It seems unlikely that mainline .NET would ever care about it. .NET nanoFramework might, but they have a completely separate and incompatible BCL API surface anyway.
This would not really make sense since RV32I and RV32E (in its current draft form, anyway) have different calling conventions. There is a new EABI in development that is attempting to unify the calling conventions for the two, though, but who knows how much traction that will gain. |
I will defer to @vargaz and @alexrp for accurate answer, but I think mono's implementation is adaptive to a certain extent that JIT keeps track of hwcaps and adapts to the target ISA extension when emitting the machine code. However, from the configuration viewpoint, the support seems to be represented with general-purpose extension In CoreCLR, we can also implement it in an adaptive manner; the prior art for ARM32 is at:
Since each core can have different capability in RISC-V and as time is passing on, more extensions are being introduced and |
It's been a while since I touched the RISC-V code in Mono, but I think Mono would be able to function with just I + A. Our experience on older Arm versions indicated that it's virtually impossible to make a .NET runtime function properly without atomic instructions, so the A extension is effectively mandatory. M is just for faster multiplication; it can be emulated in a JIT helper. Mono has soft float support so F and D are also optional, but I'm not sure if dotnet/runtime cares about soft float support anymore, so it might be acceptable to require those. I didn't even consider C when writing |
Naming nitpick: Do we want to spell it as |
qemu, llvm and gnu toolchains etc. use the long abbreviations: |
@AaronRobinsonMSFT @lambdageek do we want to get this in for .NET 8? We're running out of runway here if we do. |
I don't think we need this right now. @am11 do you have any concerns moving this to .NET 9? |
No concern. |
We do not have strict requirement to add this to .NET 8 currently, we've just started investigation of libraries and work to be done in them, so this'll probably be done after .NET 8. I'll share more details about our status in #84834 in few days. |
@AaronRobinsonMSFT @am11 is there still time to get this to .NET 8? |
@gbalykov, IMO, targeting riscv64 for .NET 9 is reasonable, since:
With that being said, if the enum member is backported to .NET 8 branch, it wouldn't hurt. 🙂 Do you think having this API in .NET 8 is important? |
I'd say that it'll help users prepare their libraries beforehand which would be useful. |
Yes, I think this would be useful for further porting |
We normally put .NET LTS version on our products. And actually, we should start to check .NET on the products in this year or in the beginning of next year at the latest. .NET 9 is not LTS and it is too late for us. If you don't mind, I also hope this API in the .NET 8 for further porting. |
@AaronRobinsonMSFT, @jkotas, is there a chance to include this in .NET 8 to unblock the porting efforts? |
.NET 8 is done. All changes going into .NET 8 are treated as servicing. I do not think that this API meets the bar for a servicing change. This API is not used very frequently and the few places that need it can use |
I am doubtful, but we can try. We really needed this back in JULY, hence the question at #73437 (comment). Let me see what we can do. |
@am11 Sorry to say, but it really is too late for this sort of API addition. The bar is rather high and since this doesn't block an existing scenario, and there is an ugly, but feasible workaround, the new API will need to wait for .NET 9. |
We changed the casing from namespace System.Runtime.InteropServices;
public enum Architecture
{
...
+ RiscV64,
}
namespace System.Reflection.PortableExecutable;
public enum Machine : ushort
{
...
+ RiscV32 = 0x5032,
+ RiscV64 = 0x5064,
+ RiscV128 = 0x5128,
} |
Resolved by #90203. |
Are our rules quite deterministic? Eg S390x not S390X. Or Armv6 not ArmV6 or ARMV6. |
.NET Framework design guidelines has a whole chapter on Capitalization Conventions. |
I think it is Arm because it has three letters (one or two letters use all upper-case letters), and small |
Background and motivation
RISC-V is the fifth generation of RISC architecture, which is currently supported by mono; while the coreclr port is in progress. We should add the relevant identifiers visible for consumers and to the higher-level APIs.
API Proposal
Ref: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
API Usage
Alternative Designs
RISC-V is an open-source and modular architecture. Its support is often expressed in terms of 'extensions'.
We should provide
System.Runtime.Intrinsics.X86Base.CpuId
-like API to expose which extensions are supported.Another twist is that the capability of RISC-V may differ by CPU core or hardware thread (ISA term is
hart
) on a given system, so knowing which extensions are supported by which hart (e.g. in order make decision on establishing affinity) maybe useful in certain types of multi-threading oriented workloads.Risks
Yes, it literally is RISC-y.
Just kidding, it is low risk, high reward! 8-)
The text was updated successfully, but these errors were encountered: