8 #include <sys/utsname.h>
11 #include <openssl/bn.h>
13 #define PPC_FPU64 (1<<0)
14 #define PPC_ALTIVEC (1<<1)
16 static int OPENSSL_ppccap_P = 0;
18 static sigset_t all_masked;
20 #ifdef OPENSSL_BN_ASM_MONT
21 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)
23 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);
24 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);
26 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);
32 /* boundary of 32 was experimentally determined on
33 Linux 2.6.22, might have to be adjusted on AIX... */
34 if (num>=32 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64))
39 sigprocmask(SIG_SETMASK,&all_masked,&oset);
40 ret=bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
41 sigprocmask(SIG_SETMASK,&oset,NULL);
47 else if ((OPENSSL_ppccap_P&PPC_FPU64))
48 /* this is a "must" on POWER6, but run-time detection
49 * is not implemented yet... */
50 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
52 return bn_mul_mont_int(rp,ap,bp,np,n0,num);
56 static sigjmp_buf ill_jmp;
57 static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
59 void OPENSSL_ppc64_probe(void);
60 void OPENSSL_altivec_probe(void);
62 void OPENSSL_cpuid_setup(void)
65 struct sigaction ill_oact,ill_act;
72 sigfillset(&all_masked);
73 sigdelset(&all_masked,SIGILL);
74 sigdelset(&all_masked,SIGTRAP);
76 sigdelset(&all_masked,SIGEMT);
78 sigdelset(&all_masked,SIGFPE);
79 sigdelset(&all_masked,SIGBUS);
80 sigdelset(&all_masked,SIGSEGV);
82 if ((e=getenv("OPENSSL_ppccap")))
84 OPENSSL_ppccap_P=strtoul(e,NULL,0);
92 # if defined(_SC_AIX_KERNEL_BITMODE)
93 && sysconf(_SC_AIX_KERNEL_BITMODE)!=64
99 memset(&ill_act,0,sizeof(ill_act));
100 ill_act.sa_handler = ill_handler;
101 ill_act.sa_mask = all_masked;
103 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
104 sigaction(SIGILL,&ill_act,&ill_oact);
106 if (sizeof(size_t)==4)
110 if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0)
112 if (sigsetjmp(ill_jmp,1) == 0)
114 OPENSSL_ppc64_probe();
115 OPENSSL_ppccap_P |= PPC_FPU64;
121 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
125 if (sigsetjmp(ill_jmp,1) == 0)
127 OPENSSL_altivec_probe();
128 OPENSSL_ppccap_P |= PPC_ALTIVEC;
131 sigaction (SIGILL,&ill_oact,NULL);
132 sigprocmask(SIG_SETMASK,&oset,NULL);