7 #if defined(__linux) || defined(_AIX)
8 #include <sys/utsname.h>
11 #include <openssl/bn.h>
13 #define PPC_FPU64 (1<<0)
14 #define PPC_ALTIVEC (1<<1)
16 unsigned 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 1 || (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);
91 if (sizeof(size_t)==4)
94 # if defined(_SC_AIX_KERNEL_BITMODE)
95 if (sysconf(_SC_AIX_KERNEL_BITMODE)!=64) return;
97 if (uname(&uts)!=0 || atoi(uts.version)<6) return;
101 memset(&ill_act,0,sizeof(ill_act));
102 ill_act.sa_handler = ill_handler;
103 ill_act.sa_mask = all_masked;
105 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
106 sigaction(SIGILL,&ill_act,&ill_oact);
108 if (sizeof(size_t)==4)
112 if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0)
114 if (sigsetjmp(ill_jmp,1) == 0)
116 OPENSSL_ppc64_probe();
117 OPENSSL_ppccap_P |= PPC_FPU64;
123 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
127 if (sigsetjmp(ill_jmp,1) == 0)
129 OPENSSL_altivec_probe();
130 OPENSSL_ppccap_P |= PPC_ALTIVEC;
133 sigaction (SIGILL,&ill_oact,NULL);
134 sigprocmask(SIG_SETMASK,&oset,NULL);