7 #include <openssl/bn.h>
9 #define PPC_FPU64 (1<<0)
10 #define PPC_ALTIVEC (1<<1)
12 static int OPENSSL_ppccap_P
= 0;
14 static sigset_t all_masked
;
16 #ifdef OPENSSL_BN_ASM_MONT
17 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
)
19 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
);
20 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
);
22 if (sizeof(size_t)==4)
24 #if (defined(__APPLE__) && defined(__MACH__))
25 if (num
>=8 && (num
&3)==0 && (OPENSSL_ppccap_P
&PPC_FPU64
))
26 return bn_mul_mont_fpu64(rp
,ap
,bp
,np
,n0
,num
);
28 /* boundary of 32 was experimentally determined on
29 Linux 2.6.22, might have to be adjusted on AIX... */
30 if (num
>=32 && (num
&3)==0 && (OPENSSL_ppccap_P
&PPC_FPU64
))
35 sigprocmask(SIG_SETMASK
,&all_masked
,&oset
);
36 ret
=bn_mul_mont_fpu64(rp
,ap
,bp
,np
,n0
,num
);
37 sigprocmask(SIG_SETMASK
,&oset
,NULL
);
43 else if ((OPENSSL_ppccap_P
&PPC_FPU64
))
44 /* this is a "must" on POWER6, but run-time detection
45 * is not implemented yet... */
46 return bn_mul_mont_fpu64(rp
,ap
,bp
,np
,n0
,num
);
48 return bn_mul_mont_int(rp
,ap
,bp
,np
,n0
,num
);
52 static sigjmp_buf ill_jmp
;
53 static void ill_handler (int sig
) { siglongjmp(ill_jmp
,sig
); }
55 void OPENSSL_ppc64_probe(void);
57 void OPENSSL_cpuid_setup(void)
60 struct sigaction ill_oact
,ill_act
;
67 sigfillset(&all_masked
);
68 sigdelset(&all_masked
,SIGILL
);
69 sigdelset(&all_masked
,SIGTRAP
);
71 sigdelset(&all_masked
,SIGEMT
);
73 sigdelset(&all_masked
,SIGFPE
);
74 sigdelset(&all_masked
,SIGBUS
);
75 sigdelset(&all_masked
,SIGSEGV
);
77 if ((e
=getenv("OPENSSL_ppccap")))
79 OPENSSL_ppccap_P
=strtoul(e
,NULL
,0);
85 memset(&ill_act
,0,sizeof(ill_act
));
86 ill_act
.sa_handler
= ill_handler
;
87 ill_act
.sa_mask
= all_masked
;
89 sigprocmask(SIG_SETMASK
,&ill_act
.sa_mask
,&oset
);
90 sigaction(SIGILL
,&ill_act
,&ill_oact
);
92 if (sizeof(size_t)==4)
94 if (sigsetjmp(ill_jmp
,1) == 0)
96 OPENSSL_ppc64_probe();
97 OPENSSL_ppccap_P
|= PPC_FPU64
;
103 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
107 if (sigsetjmp(ill_jmp
,1) == 0)
109 OPENSSL_altivec_probe();
110 OPENSSL_ppccap_P
|= PPC_ALTIVEC
;
113 sigaction (SIGILL
,&ill_oact
,NULL
);
114 sigprocmask(SIG_SETMASK
,&oset
,NULL
);