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)
15 #define PPC_CRYPTO207 (1<<2)
17 unsigned int OPENSSL_ppccap_P = 0;
19 static sigset_t all_masked;
21 #ifdef OPENSSL_BN_ASM_MONT
22 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)
24 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);
25 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);
27 if (sizeof(size_t)==4)
29 #if 1 || (defined(__APPLE__) && defined(__MACH__))
30 if (num>=8 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64))
31 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
33 /* boundary of 32 was experimentally determined on
34 Linux 2.6.22, might have to be adjusted on AIX... */
35 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);
48 else if ((OPENSSL_ppccap_P&PPC_FPU64))
49 /* this is a "must" on POWER6, but run-time detection
50 * is not implemented yet... */
51 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
53 return bn_mul_mont_int(rp,ap,bp,np,n0,num);
57 static sigjmp_buf ill_jmp;
58 static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
60 void OPENSSL_ppc64_probe(void);
61 void OPENSSL_altivec_probe(void);
62 void OPENSSL_crypto207_probe(void);
64 void OPENSSL_cpuid_setup(void)
67 struct sigaction ill_oact,ill_act;
74 sigfillset(&all_masked);
75 sigdelset(&all_masked,SIGILL);
76 sigdelset(&all_masked,SIGTRAP);
78 sigdelset(&all_masked,SIGEMT);
80 sigdelset(&all_masked,SIGFPE);
81 sigdelset(&all_masked,SIGBUS);
82 sigdelset(&all_masked,SIGSEGV);
84 if ((e=getenv("OPENSSL_ppccap")))
86 OPENSSL_ppccap_P=strtoul(e,NULL,0);
93 if (sizeof(size_t)==4)
96 # if defined(_SC_AIX_KERNEL_BITMODE)
97 if (sysconf(_SC_AIX_KERNEL_BITMODE)!=64) return;
99 if (uname(&uts)!=0 || atoi(uts.version)<6) return;
103 memset(&ill_act,0,sizeof(ill_act));
104 ill_act.sa_handler = ill_handler;
105 ill_act.sa_mask = all_masked;
107 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
108 sigaction(SIGILL,&ill_act,&ill_oact);
110 if (sizeof(size_t)==4)
114 if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0)
116 if (sigsetjmp(ill_jmp,1) == 0)
118 OPENSSL_ppc64_probe();
119 OPENSSL_ppccap_P |= PPC_FPU64;
125 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
129 if (sigsetjmp(ill_jmp,1) == 0)
131 OPENSSL_altivec_probe();
132 OPENSSL_ppccap_P |= PPC_ALTIVEC;
133 if (sigsetjmp(ill_jmp,1) == 0)
135 OPENSSL_crypto207_probe();
136 OPENSSL_ppccap_P |= PPC_CRYPTO207;
140 sigaction (SIGILL,&ill_oact,NULL);
141 sigprocmask(SIG_SETMASK,&oset,NULL);