Skip to content

Commit dc4c307

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 bash 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 166e479 commit dc4c307

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
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),

0 commit comments

Comments
 (0)