Skip to content

[API Proposal]: architecture definitions for RISC-V ISA #73437

Closed
@am11

Description

@am11

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

namespace System.Runtime.InteropServices;

public enum Architecture
{
    ...
+   Riscv64,
}

namespace System.Reflection.PortableExecutable;

public enum Machine : ushort
{
    ...
+   Riscv32 = 0x5032,
+   Riscv64 = 0x5064,
+   Riscv128 = 0x5128,
}

API Usage

int GetArchMagic(Architecture arch) => arch switch
{
    Architecture.Riscv64 => 42,
}

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-)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions