]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Improve the CPUINFO display for RISC-V
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 6 Oct 2025 06:37:20 +0000 (08:37 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 10 Nov 2025 06:22:07 +0000 (07:22 +0100)
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.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28760)

(cherry picked from commit c05ea2fdb7f7687c2df1b611ece37be1bd03b011)

crypto/info.c
doc/man3/OPENSSL_riscvcap.pod

index e760ec094027999b95db79f19fc84655737ebc73..06723e7a1081e71023c03bd59ff798d73a2e6b22 100644 (file)
@@ -127,27 +127,54 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
                      " env:%s", env);
 # elif defined(__riscv)
     const char *env;
-    char sep = '=';
+    size_t i;
 
     BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
-                 CPUINFO_PREFIX "OPENSSL_riscvcap");
-    for (size_t i = 0; i < kRISCVNumCaps; ++i) {
+                 CPUINFO_PREFIX "OPENSSL_riscvcap=RV"
+#  if __riscv_xlen == 32
+                 "32"
+#  elif __riscv_xlen == 64
+                 "64"
+#  elif __riscv_xlen == 128
+                 "128"
+#  endif
+#  if defined(__riscv_i) && defined(__riscv_m) && defined(__riscv_a) \
+      && defined(__riscv_f) && defined(__riscv_d) \
+      && defined(__riscv_zicsr) && defined(__riscv_zifencei)
+                 "G" /* shorthand for IMAFD_Zicsr_Zifencei */
+#  else
+#   ifdef __riscv_i
+                 "I"
+#   endif
+#   ifdef __riscv_m
+                 "M"
+#   endif
+#   ifdef __riscv_a
+                 "A"
+#   endif
+#   ifdef __riscv_f
+                 "F"
+#   endif
+#   ifdef __riscv_d
+                 "D"
+#   endif
+#  endif
+#  ifdef __riscv_c
+                 "C"
+#  endif
+                 );
+    for (i = 0; i < kRISCVNumCaps; i++) {
         if (OPENSSL_riscvcap_P[RISCV_capabilities[i].index]
-                & (1 << RISCV_capabilities[i].bit_offset)) {
+                & (1 << RISCV_capabilities[i].bit_offset))
             /* Match, display the name */
             BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
                          sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
-                         "%c%s", sep, RISCV_capabilities[i].name);
-            /* Only the first sep is '=' */
-            sep = '_';
-        }
+                         "_%s", RISCV_capabilities[i].name);
     }
-    /* If no capability is found, add back the = */
-    if (sep == '=') {
+    if (RISCV_HAS_V())
         BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
                      sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
-                     "%c", sep);
-    }
+                     " vlen:%lu", riscv_vlen());
     if ((env = getenv("OPENSSL_riscvcap")) != NULL)
         BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
                      sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
index 1ebf20826a7f1196b0451d5e8a6a77f148de6447..3113b98f336fb9fc1eab04e5862f5c7eaf56a92c 100644 (file)
@@ -189,15 +189,21 @@ Not available.
 Check currently detected capabilities
 
  $ openssl info -cpusettings
- OPENSSL_riscvcap=ZBA_ZBB_ZBC_ZBS_V
+ OPENSSL_riscvcap=RV64GC_ZBA_ZBB_ZBC_ZBS_V vlen:256
+
+Note: The first word in the displayed capabilities is the RISC-V base
+architecture value, which is derived from the compiler configuration.
+It is therefore not overridable by the environment variable.
+When the V extension is given the riscv_vlen value is always displayed,
+there is no way to override the riscv_vlen by the environment variable.
 
 Disables all instruction set extensions:
 
- OPENSSL_riscvcap="rv64gc"
export OPENSSL_riscvcap="rv64gc"
 
 Only enable the vector extension:
 
- OPENSSL_riscvcap="rv64gc_v"
export OPENSSL_riscvcap="rv64gc_v"
 
 =head1 COPYRIGHT