You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/c-api.adoc
+110-5Lines changed: 110 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -814,9 +814,114 @@ statements, including both RISC-V specific and common operand modifiers.
814
814
[id=function-multi-version]
815
815
== Function Multi-version
816
816
817
-
Function multi-versioning(FMV) provides an approach to selecting the appropriate
818
-
function according to the runtime environment. The final binary may contain all
819
-
versions of the function, with the compiler generating all supported versions
820
-
and the runtime selecting the appropriate one.
817
+
Function multi-versioning (FMV) allows selecting the appropriate function based on the runtime environment. The binary may contain multiple versions of the function, with the compiler generating all supported versions and selecting the appropriate one at runtime.
821
818
822
-
This feature is triggered by `target_version/target_clones` function attribute.
819
+
This feature is activated by the `target_version/target_clones` function attributes.
820
+
821
+
=== Extension Bitmask
822
+
823
+
The Extension Bitmask is used to probe whether features are enabled during runtime. This is achieved through three bitmask structures: `__riscv_feature_bits` for standard extensions, `__riscv_vendor_feature_bits` for vendor-specific extensions and `__riscv_cpu_model` for the CPU model. Additionally, `__init_riscv_feature_bits` is used to update the contents of these structures according to the system configuration.
824
+
825
+
The bitmask structures use the following definitions:
826
+
827
+
```c
828
+
struct {
829
+
unsigned length;
830
+
unsigned long long features[];
831
+
} __riscv_feature_bits;
832
+
833
+
struct {
834
+
unsigned length;
835
+
unsigned long long features[];
836
+
} __riscv_vendor_feature_bits;
837
+
838
+
struct {
839
+
unsigned mvendorid;
840
+
unsigned marchid;
841
+
unsigned mimpid;
842
+
} __riscv_cpu_model;
843
+
```
844
+
845
+
- `length`: Represents the number of elements in the features array.
846
+
- `features`: An `unsigned long long` array where each bit indicates 1 for a specific extension enabled by the system or 0 for the extension's status unknown in system.
847
+
- `mvendorid`: Indicates the value of `mvendorid` CSR.
848
+
- `marchid`: Indicates the value of `marchid` CSR.
849
+
- `mimpid`: Indicates the value of `mimpid` CSR.
850
+
851
+
To initiate these structures based on the system's extension status, the following function is provided:
852
+
853
+
```
854
+
void __init_riscv_feature_bits(void *);
855
+
```
856
+
857
+
The `__init_riscv_feature_bits` function updates `length`, `mvendorid`, `marchid`, `mimpid` and the `features` in `__riscv_feature_bits` and `__riscv_vendor_feature_bits` according to the enabled extensions in the system.
858
+
859
+
The `__init_riscv_feature_bits` function accepts an argument of type `void *`. This argument allows the platform to provide pre-computed data and access it without additional effort. For example, Linux could pass the vDSO object to avoid an extra system call.
860
+
861
+
NOTE: To detect failure of the `__init_riscv_feature_bits` function, it is recommended to check the bitmask for the `I` extension. The `I` extension must be supported in all valid RISC-V implementations.
862
+
863
+
Each queryable extension must have an associated `groupid` and `bitmask` that indicates its position within the features array.
864
+
865
+
> For example, the zba extension is represented by `groupid`: 0 and `bitmask`: `1ULL << 27`. Users can check if the zba extension is enabled using: `__riscv_feature_bits.features[0] & (1ULL << 27)`.
866
+
867
+
==== Extension Bitmask Definitions
868
+
869
+
> The single-letter extension bitmask follows the `misa` bit position inside `__riscv_feature_bits.features[0]`.
0 commit comments