8 #include <openssl/bn.h>
10 #define PPC_FPU64 (1<<0)
11 #define PPC_ALTIVEC (1<<1)
13 static int OPENSSL_ppccap_P = 0;
15 static sigset_t all_masked;
17 #ifdef OPENSSL_BN_ASM_MONT
18 int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
19 const BN_ULONG *np, const BN_ULONG *n0, int num)
21 int bn_mul_mont_fpu64(BN_ULONG *rp, const BN_ULONG *ap,
22 const BN_ULONG *bp, const BN_ULONG *np,
23 const BN_ULONG *n0, int num);
24 int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
25 const BN_ULONG *np, const BN_ULONG *n0, int num);
27 if (sizeof(size_t) == 4) {
28 # if (defined(__APPLE__) && defined(__MACH__))
29 if (num >= 8 && (num & 3) == 0 && (OPENSSL_ppccap_P & PPC_FPU64))
30 return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
33 * boundary of 32 was experimentally determined on Linux 2.6.22,
34 * might have to be adjusted on AIX...
36 if (num >= 32 && (num & 3) == 0 && (OPENSSL_ppccap_P & PPC_FPU64)) {
40 sigprocmask(SIG_SETMASK, &all_masked, &oset);
41 ret = bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
42 sigprocmask(SIG_SETMASK, &oset, NULL);
47 } else if ((OPENSSL_ppccap_P & PPC_FPU64))
49 * this is a "must" on POWER6, but run-time detection is not
52 return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
54 return bn_mul_mont_int(rp, ap, bp, np, n0, num);
58 static sigjmp_buf ill_jmp;
59 static void ill_handler(int sig)
61 siglongjmp(ill_jmp, sig);
64 void OPENSSL_ppc64_probe(void);
65 void OPENSSL_altivec_probe(void);
67 void OPENSSL_cpuid_setup(void)
70 struct sigaction ill_oact, ill_act;
72 static int trigger = 0;
78 sigfillset(&all_masked);
79 sigdelset(&all_masked, SIGILL);
80 sigdelset(&all_masked, SIGTRAP);
82 sigdelset(&all_masked, SIGEMT);
84 sigdelset(&all_masked, SIGFPE);
85 sigdelset(&all_masked, SIGBUS);
86 sigdelset(&all_masked, SIGSEGV);
88 if ((e = getenv("OPENSSL_ppccap"))) {
89 OPENSSL_ppccap_P = strtoul(e, NULL, 0);
96 if (sizeof(size_t) == 4
97 # if defined(_SC_AIX_KERNEL_BITMODE)
98 && sysconf(_SC_AIX_KERNEL_BITMODE) != 64
104 memset(&ill_act, 0, sizeof(ill_act));
105 ill_act.sa_handler = ill_handler;
106 ill_act.sa_mask = all_masked;
108 sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
109 sigaction(SIGILL, &ill_act, &ill_oact);
111 if (sizeof(size_t) == 4) {
112 if (sigsetjmp(ill_jmp, 1) == 0) {
113 OPENSSL_ppc64_probe();
114 OPENSSL_ppccap_P |= PPC_FPU64;
118 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
122 if (sigsetjmp(ill_jmp, 1) == 0) {
123 OPENSSL_altivec_probe();
124 OPENSSL_ppccap_P |= PPC_ALTIVEC;
127 sigaction(SIGILL, &ill_oact, NULL);
128 sigprocmask(SIG_SETMASK, &oset, NULL);