6 #include <openssl/bn.h>
8 #define PPC_FPU64 (1<<0)
10 static int OPENSSL_ppccap_P = 0;
12 static sigset_t all_masked;
14 #ifdef OPENSSL_BN_ASM_MONT
15 int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num)
17 int bn_mul_mont_fpu64(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num);
18 int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num);
20 if (sizeof(size_t)==4)
22 #if (defined(__APPLE__) && defined(__MACH__))
23 if ((OPENSSL_ppccap_P&PPC_FPU64))
24 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
26 /* boundary of 32 was experimentally determined on
27 Linux 2.6.22, might have to be adjusted on AIX... */
28 if ((num>=32) && (OPENSSL_ppccap_P&PPC_FPU64))
33 sigprocmask(SIG_SETMASK,&all_masked,&oset);
34 ret=bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
35 sigprocmask(SIG_SETMASK,&oset,NULL);
41 else if ((OPENSSL_ppccap_P&PPC_FPU64))
42 /* this is a "must" on Power 6, but run-time detection
43 * is not implemented yet... */
44 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
46 return bn_mul_mont_int(rp,ap,bp,np,n0,num);
50 static sigjmp_buf ill_jmp;
51 static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
53 void OPENSSL_cpuid_setup(void)
57 sigfillset(&all_masked);
58 sigdelset(&all_masked,SIGSEGV);
59 sigdelset(&all_masked,SIGILL);
60 sigdelset(&all_masked,SIGBUS);
61 sigdelset(&all_masked,SIGFPE);
63 if ((e=getenv("OPENSSL_ppccap")))
65 OPENSSL_ppccap_P=strtoul(e,NULL,0);
69 if (sizeof(size_t)==4)
71 struct sigaction ill_oact,ill_act;
74 memset(&ill_act,0,sizeof(ill_act));
75 ill_act.sa_handler = ill_handler;
76 ill_act.sa_mask = all_masked;
77 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
78 sigaction (SIGILL,&ill_act,&ill_oact);
79 if (sigsetjmp(ill_jmp,0) == 0)
81 OPENSSL_ppc64_probe();
82 OPENSSL_ppccap_P |= PPC_FPU64;
86 OPENSSL_ppccap_P &= ~PPC_FPU64;
88 sigaction (SIGILL,&ill_oact,NULL);
89 sigprocmask(SIG_SETMASK,&oset,NULL);