Add basic RISC-V cpuid and OPENSSL_riscvcap
RISC-V cpuid implementation allows bitmanip extensions Zb[abcs] to
be enabled at runtime using OPENSSL_riscvcap environment variable.
For example, to specify 64-bit RISC-V with the G,C,Zba,Zbb,Zbc
extensions, one could write: OPENSSL_riscvcap="rv64gc_zba_zbb_zbc"
Architecture string parsing is still very primitive, but can be
expanded in the future. Currently, only bitmanip extensions Zba, Zbb,
Zbc and Zbs are supported.
Includes implementation of constant-time CRYPTO_memcmp in riscv64 asm,
as well as OPENSSL_cleanse. Assembly implementations are written using
perlasm.
Reviewed-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Henry Brausen <henry.brausen@vrull.eu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17640)
2022-01-28 16:28:52 +08:00
|
|
|
/*
|
2023-09-07 16:59:15 +08:00
|
|
|
* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
|
Add basic RISC-V cpuid and OPENSSL_riscvcap
RISC-V cpuid implementation allows bitmanip extensions Zb[abcs] to
be enabled at runtime using OPENSSL_riscvcap environment variable.
For example, to specify 64-bit RISC-V with the G,C,Zba,Zbb,Zbc
extensions, one could write: OPENSSL_riscvcap="rv64gc_zba_zbb_zbc"
Architecture string parsing is still very primitive, but can be
expanded in the future. Currently, only bitmanip extensions Zba, Zbb,
Zbc and Zbs are supported.
Includes implementation of constant-time CRYPTO_memcmp in riscv64 asm,
as well as OPENSSL_cleanse. Assembly implementations are written using
perlasm.
Reviewed-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Henry Brausen <henry.brausen@vrull.eu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17640)
2022-01-28 16:28:52 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSSL_CRYPTO_RISCV_ARCH_H
|
|
|
|
# define OSSL_CRYPTO_RISCV_ARCH_H
|
|
|
|
|
|
|
|
# include <ctype.h>
|
|
|
|
# include <stdint.h>
|
|
|
|
|
|
|
|
# define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
|
|
|
|
extern uint32_t OPENSSL_riscvcap_P[ ((
|
|
|
|
# include "riscv_arch.def"
|
|
|
|
) + sizeof(uint32_t) - 1) / sizeof(uint32_t) ];
|
|
|
|
|
|
|
|
# ifdef OPENSSL_RISCVCAP_IMPL
|
|
|
|
# define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
|
|
|
|
uint32_t OPENSSL_riscvcap_P[ ((
|
|
|
|
# include "riscv_arch.def"
|
|
|
|
) + sizeof(uint32_t) - 1) / sizeof(uint32_t) ];
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) \
|
|
|
|
static inline int RISCV_HAS_##NAME(void) \
|
|
|
|
{ \
|
|
|
|
return (OPENSSL_riscvcap_P[INDEX] & (1 << BIT_INDEX)) != 0; \
|
|
|
|
}
|
|
|
|
# include "riscv_arch.def"
|
|
|
|
|
|
|
|
struct RISCV_capability_s {
|
|
|
|
const char *name;
|
|
|
|
size_t index;
|
|
|
|
size_t bit_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
# define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
|
|
|
|
extern const struct RISCV_capability_s RISCV_capabilities[
|
|
|
|
# include "riscv_arch.def"
|
|
|
|
];
|
|
|
|
|
|
|
|
# ifdef OPENSSL_RISCVCAP_IMPL
|
|
|
|
# define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) \
|
|
|
|
{ #NAME, INDEX, BIT_INDEX },
|
|
|
|
const struct RISCV_capability_s RISCV_capabilities[] = {
|
|
|
|
# include "riscv_arch.def"
|
|
|
|
};
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# define RISCV_DEFINE_CAP(NAME, INDEX, BIT_INDEX) +1
|
|
|
|
static const size_t kRISCVNumCaps =
|
|
|
|
# include "riscv_arch.def"
|
|
|
|
;
|
|
|
|
|
2023-01-18 02:31:58 +08:00
|
|
|
/* Extension combination tests. */
|
|
|
|
#define RISCV_HAS_ZBB_AND_ZBC() (RISCV_HAS_ZBB() && RISCV_HAS_ZBC())
|
|
|
|
#define RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE() (RISCV_HAS_ZBKB() && RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
|
|
|
|
#define RISCV_HAS_ZKND_AND_ZKNE() (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
|
2023-09-28 13:51:17 +08:00
|
|
|
/*
|
|
|
|
* The ZVBB is the superset of ZVKB extension. We use macro here to replace the
|
|
|
|
* `RISCV_HAS_ZVKB()` with `RISCV_HAS_ZVBB() || RISCV_HAS_ZVKB()`.
|
|
|
|
*/
|
|
|
|
#define RISCV_HAS_ZVKB() (RISCV_HAS_ZVBB() || RISCV_HAS_ZVKB())
|
|
|
|
#define RISCV_HAS_ZVKB_AND_ZVKNHA() (RISCV_HAS_ZVKB() && RISCV_HAS_ZVKNHA())
|
|
|
|
#define RISCV_HAS_ZVKB_AND_ZVKNHB() (RISCV_HAS_ZVKB() && RISCV_HAS_ZVKNHB())
|
|
|
|
#define RISCV_HAS_ZVKB_AND_ZVKSED() (RISCV_HAS_ZVKB() && RISCV_HAS_ZVKSED())
|
|
|
|
#define RISCV_HAS_ZVKB_AND_ZVKSH() (RISCV_HAS_ZVKB() && RISCV_HAS_ZVKSH())
|
2023-01-18 02:31:58 +08:00
|
|
|
|
2023-02-14 13:22:03 +08:00
|
|
|
/*
|
|
|
|
* Get the size of a vector register in bits (VLEN).
|
|
|
|
* If RISCV_HAS_V() is false, then this returns 0.
|
|
|
|
*/
|
|
|
|
size_t riscv_vlen(void);
|
|
|
|
|
Add basic RISC-V cpuid and OPENSSL_riscvcap
RISC-V cpuid implementation allows bitmanip extensions Zb[abcs] to
be enabled at runtime using OPENSSL_riscvcap environment variable.
For example, to specify 64-bit RISC-V with the G,C,Zba,Zbb,Zbc
extensions, one could write: OPENSSL_riscvcap="rv64gc_zba_zbb_zbc"
Architecture string parsing is still very primitive, but can be
expanded in the future. Currently, only bitmanip extensions Zba, Zbb,
Zbc and Zbs are supported.
Includes implementation of constant-time CRYPTO_memcmp in riscv64 asm,
as well as OPENSSL_cleanse. Assembly implementations are written using
perlasm.
Reviewed-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Henry Brausen <henry.brausen@vrull.eu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17640)
2022-01-28 16:28:52 +08:00
|
|
|
#endif
|