Module Name:    src
Committed By:   rin
Date:           Tue Jul  7 01:47:47 UTC 2020

Modified Files:
        src/crypto/external/bsd/openssl/dist/crypto: ppccap.c

Log Message:
Part of PR port-powerpc/55425
openssl fails on FPU emulation for powerpc

When machdep.fpu_present sysctl variable can be retrieved, and
its value is zero, avoid using FPU arithmetic.

FPU is absent and emulated by kernel in that case, and calculation
results are not correct in bit-to-bit precision.

This behavior should be useful even if we could fix FPU emulation;
it is much faster to skip FPU arithmetic in general, rather than
relying upon emulation by kernel via illegal instruction handler.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
    src/crypto/external/bsd/openssl/dist/crypto/ppccap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/openssl/dist/crypto/ppccap.c
diff -u src/crypto/external/bsd/openssl/dist/crypto/ppccap.c:1.15 src/crypto/external/bsd/openssl/dist/crypto/ppccap.c:1.16
--- src/crypto/external/bsd/openssl/dist/crypto/ppccap.c:1.15	Mon Jun 22 16:25:08 2020
+++ src/crypto/external/bsd/openssl/dist/crypto/ppccap.c	Tue Jul  7 01:47:47 2020
@@ -26,6 +26,10 @@
 # include <sys/types.h>
 # include <sys/sysctl.h>
 #endif
+#if defined(__NetBSD__)
+# include <sys/param.h>
+# include <sys/sysctl.h>
+#endif
 #include <openssl/crypto.h>
 #include <openssl/bn.h>
 #include <internal/cryptlib.h>
@@ -365,6 +369,18 @@ void OPENSSL_cpuid_setup(void)
     sigaction(SIGILL, &ill_act, &ill_oact);
 
 #ifndef OSSL_IMPLEMENT_GETAUXVAL
+# ifdef __NetBSD__
+    int error, val;
+    size_t len = sizeof(val);
+
+    /*
+     * If machdep.fpu_present == 0, FPU is absent and emulated by software.
+     * Avoid using it as calculation results may not be correct in bit-to-bit
+     * precision.
+     */
+    error = sysctlbyname("machdep.fpu_present", &val, &len, NULL, 0);
+    if (error != 0 || (error == 0 && val != 0))
+# endif
     if (sigsetjmp(ill_jmp,1) == 0) {
         OPENSSL_fpu_probe();
         OPENSSL_ppccap_P |= PPC_FPU;

Reply via email to