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 void sha256_block_p8(void *ctx,const void *inp,size_t len);
58 void sha256_block_ppc(void *ctx,const void *inp,size_t len);
59 void sha256_block_data_order(void *ctx,const void *inp,size_t len)
61 OPENSSL_ppccap_P&PPC_CRYPTO207? sha256_block_p8(ctx,inp,len):
62 sha256_block_ppc(ctx,inp,len);
65 void sha512_block_p8(void *ctx,const void *inp,size_t len);
66 void sha512_block_ppc(void *ctx,const void *inp,size_t len);
67 void sha512_block_data_order(void *ctx,const void *inp,size_t len)
69 OPENSSL_ppccap_P&PPC_CRYPTO207? sha512_block_p8(ctx,inp,len):
70 sha512_block_ppc(ctx,inp,len);
73 static sigjmp_buf ill_jmp;
74 static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
76 void OPENSSL_ppc64_probe(void);
77 void OPENSSL_altivec_probe(void);
78 void OPENSSL_crypto207_probe(void);
80 void OPENSSL_cpuid_setup(void)
83 struct sigaction ill_oact,ill_act;
90 sigfillset(&all_masked);
91 sigdelset(&all_masked,SIGILL);
92 sigdelset(&all_masked,SIGTRAP);
94 sigdelset(&all_masked,SIGEMT);
96 sigdelset(&all_masked,SIGFPE);
97 sigdelset(&all_masked,SIGBUS);
98 sigdelset(&all_masked,SIGSEGV);
100 if ((e=getenv("OPENSSL_ppccap")))
102 OPENSSL_ppccap_P=strtoul(e,NULL,0);
106 OPENSSL_ppccap_P = 0;
109 if (sizeof(size_t)==4)
112 # if defined(_SC_AIX_KERNEL_BITMODE)
113 if (sysconf(_SC_AIX_KERNEL_BITMODE)!=64) return;
115 if (uname(&uts)!=0 || atoi(uts.version)<6) return;
119 memset(&ill_act,0,sizeof(ill_act));
120 ill_act.sa_handler = ill_handler;
121 ill_act.sa_mask = all_masked;
123 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
124 sigaction(SIGILL,&ill_act,&ill_oact);
126 if (sizeof(size_t)==4)
130 if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0)
132 if (sigsetjmp(ill_jmp,1) == 0)
134 OPENSSL_ppc64_probe();
135 OPENSSL_ppccap_P |= PPC_FPU64;
141 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
145 if (sigsetjmp(ill_jmp,1) == 0)
147 OPENSSL_altivec_probe();
148 OPENSSL_ppccap_P |= PPC_ALTIVEC;
149 if (sigsetjmp(ill_jmp,1) == 0)
151 OPENSSL_crypto207_probe();
152 OPENSSL_ppccap_P |= PPC_CRYPTO207;
156 sigaction (SIGILL,&ill_oact,NULL);
157 sigprocmask(SIG_SETMASK,&oset,NULL);