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 && (num&3)==0 && (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_ppc64_probe(void);
55 void OPENSSL_cpuid_setup(void)
59 sigfillset(&all_masked);
60 sigdelset(&all_masked,SIGILL);
61 sigdelset(&all_masked,SIGTRAP);
62 sigdelset(&all_masked,SIGEMT);
63 sigdelset(&all_masked,SIGFPE);
64 sigdelset(&all_masked,SIGBUS);
65 sigdelset(&all_masked,SIGSEGV);
67 if ((e=getenv("OPENSSL_ppccap")))
69 OPENSSL_ppccap_P=strtoul(e,NULL,0);
73 if (sizeof(size_t)==4)
75 struct sigaction ill_oact,ill_act;
78 memset(&ill_act,0,sizeof(ill_act));
79 ill_act.sa_handler = ill_handler;
80 ill_act.sa_mask = all_masked;
81 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
82 sigaction (SIGILL,&ill_act,&ill_oact);
83 if (sigsetjmp(ill_jmp,0) == 0)
85 OPENSSL_ppc64_probe();
86 OPENSSL_ppccap_P |= PPC_FPU64;
90 OPENSSL_ppccap_P &= ~PPC_FPU64;
92 sigaction (SIGILL,&ill_oact,NULL);
93 sigprocmask(SIG_SETMASK,&oset,NULL);