Skip to content

Commit aa1f444

Browse files
Improve the CPUINFO display for RISC-V
Prefix the base architecture to the displayed RISC-V architecture string, so the displayed OPENSSL_riscvcap environment value can be used as is, since otherwise the OPENSSL_cpuid_setup would ignore the first extension, as it is expected to be the base architecture, usually "RV64GC" or similar. See the comment at parse_env in crypto/riscvcap.c Furthermore also print the VLEN value, if the V-extension is given, since that makes a significant difference which assembler modules are activated by the V-extension.
1 parent 18120f9 commit aa1f444

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

crypto/info.c

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,54 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
127127
" env:%s", env);
128128
# elif defined(__riscv)
129129
const char *env;
130-
char sep = '=';
130+
size_t i;
131131

132132
BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
133-
CPUINFO_PREFIX "OPENSSL_riscvcap");
134-
for (size_t i = 0; i < kRISCVNumCaps; ++i) {
133+
CPUINFO_PREFIX "OPENSSL_riscvcap=RV"
134+
# if __riscv_xlen == 32
135+
"32"
136+
# elif __riscv_xlen == 64
137+
"64"
138+
# elif __riscv_xlen == 128
139+
"128"
140+
# endif
141+
# if defined(__riscv_i) && defined(__riscv_m) && defined(__riscv_a) \
142+
&& defined(__riscv_f) && defined(__riscv_d) \
143+
&& defined(__riscv_zicsr) && defined(__riscv_zifencei)
144+
"G" /* shorthand for IMAFD_Zicsr_Zifencei */
145+
# else
146+
# ifdef __riscv_i
147+
"I"
148+
# endif
149+
# ifdef __riscv_m
150+
"M"
151+
# endif
152+
# ifdef __riscv_a
153+
"A"
154+
# endif
155+
# ifdef __riscv_f
156+
"F"
157+
# endif
158+
# ifdef __riscv_d
159+
"D"
160+
# endif
161+
# endif
162+
# ifdef __riscv_c
163+
"C"
164+
# endif
165+
);
166+
for (i = 0; i < kRISCVNumCaps; i++) {
135167
if (OPENSSL_riscvcap_P[RISCV_capabilities[i].index]
136-
& (1 << RISCV_capabilities[i].bit_offset)) {
168+
& (1 << RISCV_capabilities[i].bit_offset))
137169
/* Match, display the name */
138170
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
139171
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
140-
"%c%s", sep, RISCV_capabilities[i].name);
141-
/* Only the first sep is '=' */
142-
sep = '_';
143-
}
172+
"_%s", RISCV_capabilities[i].name);
144173
}
145-
/* If no capability is found, add back the = */
146-
if (sep == '=') {
174+
if (RISCV_HAS_V())
147175
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
148176
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
149-
"%c", sep);
150-
}
177+
" vlen:%lu", riscv_vlen());
151178
if ((env = getenv("OPENSSL_riscvcap")) != NULL)
152179
BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
153180
sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),

doc/man3/OPENSSL_riscvcap.pod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,21 @@ Not available.
189189
Check currently detected capabilities
190190

191191
$ openssl info -cpusettings
192-
OPENSSL_riscvcap=ZBA_ZBB_ZBC_ZBS_V
192+
OPENSSL_riscvcap=RV64GC_ZBA_ZBB_ZBC_ZBS_V vlen:256
193+
194+
Note: The first word in the displayed capabilities is the RISC-V base
195+
architecture value, which is derived from the compiler configuration.
196+
It is therefore not overridable by the environment variable.
197+
When the V extension is given the riscv_vlen value is always displayed,
198+
there is no way to override the riscv_vlen by the environment variable.
193199

194200
Disables all instruction set extensions:
195201

196-
OPENSSL_riscvcap="rv64gc"
202+
export OPENSSL_riscvcap="rv64gc"
197203

198204
Only enable the vector extension:
199205

200-
OPENSSL_riscvcap="rv64gc_v"
206+
export OPENSSL_riscvcap="rv64gc_v"
201207

202208
=head1 COPYRIGHT
203209

0 commit comments

Comments
 (0)