diff options
author | Christoph Müllner <christoph.muellner@vrull.eu> | 2023-02-14 06:22:03 +0100 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-10-26 15:55:49 +0100 |
commit | cdea67193da8aab0f1a49d2b7ce144ad21bfc51d (patch) | |
tree | 92920e6b2f0163708a406f3a8d78f412da365dcc /crypto/riscv64cpuid.pl | |
parent | 2126ca3dba3907f49b232442c06db1cae8bee0c3 (diff) |
riscv: Add basic vector extension support
The RISC-V vector extension comes with an implementation-defined
number of bits per vector register (VLEN), which can be read out at
run-time using the CSR 'vlenb' (which returns VLEN/8) followed by a
multiplication by 8 (to convert bytes to bits).
This patch introduces a RISC-V capability 'V' to specify the
availability of the vector extension. If this extension is found at
run-time, then we read out VLEN as described above and cache it.
Caching ensures that we only read the CSR once at startup.
This is necessary because reading out CSR can be expensive
(e.g. if CSR readout is implemented using trap-and-emulate).
Follow-up patches can make use of VLEN and chose the best strategy
based on the available length of the vector registers.
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21923)
Diffstat (limited to 'crypto/riscv64cpuid.pl')
-rw-r--r-- | crypto/riscv64cpuid.pl | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/crypto/riscv64cpuid.pl b/crypto/riscv64cpuid.pl index 675e9b6111..5dcdc5c584 100644 --- a/crypto/riscv64cpuid.pl +++ b/crypto/riscv64cpuid.pl @@ -84,6 +84,22 @@ OPENSSL_cleanse: ___ } +{ +my ($ret) = ('a0'); +$code .= <<___; +################################################################################ +# size_t riscv_vlen_asm(void) +# Return VLEN (i.e. the length of a vector register in bits). +.p2align 3 +.globl riscv_vlen_asm +.type riscv_vlen_asm,\@function +riscv_vlen_asm: + csrr $ret, vlenb + slli $ret, $ret, 3 + ret +.size riscv_vlen_asm,.-riscv_vlen_asm +___ +} print $code; close STDOUT or die "error closing STDOUT: $!"; |