diff options
Diffstat (limited to 'src/lib/libcrypto/ppccap.c')
| -rw-r--r-- | src/lib/libcrypto/ppccap.c | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/src/lib/libcrypto/ppccap.c b/src/lib/libcrypto/ppccap.c index f71ba66aa3..16cc9c445e 100644 --- a/src/lib/libcrypto/ppccap.c +++ b/src/lib/libcrypto/ppccap.c | |||
| @@ -15,112 +15,110 @@ static int OPENSSL_ppccap_P = 0; | |||
| 15 | static sigset_t all_masked; | 15 | static sigset_t all_masked; |
| 16 | 16 | ||
| 17 | #ifdef OPENSSL_BN_ASM_MONT | 17 | #ifdef OPENSSL_BN_ASM_MONT |
| 18 | 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) | 18 | int |
| 19 | { | 19 | bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, |
| 20 | const BN_ULONG *np, const BN_ULONG *n0, int num) | ||
| 21 | { | ||
| 20 | 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); | 22 | 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); |
| 21 | 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); | 23 | 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 | 24 | ||
| 23 | if (sizeof(size_t)==4) | 25 | if (sizeof(size_t) == 4) { |
| 24 | { | ||
| 25 | #if (defined(__APPLE__) && defined(__MACH__)) | 26 | #if (defined(__APPLE__) && defined(__MACH__)) |
| 26 | if (num>=8 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64)) | 27 | if (num >= 8 && (num&3) == 0 && (OPENSSL_ppccap_P&PPC_FPU64)) |
| 27 | return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num); | 28 | return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num); |
| 28 | #else | 29 | #else |
| 29 | /* boundary of 32 was experimentally determined on | 30 | /* boundary of 32 was experimentally determined on |
| 30 | Linux 2.6.22, might have to be adjusted on AIX... */ | 31 | Linux 2.6.22, might have to be adjusted on AIX... */ |
| 31 | if (num>=32 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64)) | 32 | if (num >= 32 && (num&3) == 0 && (OPENSSL_ppccap_P&PPC_FPU64)) { |
| 32 | { | ||
| 33 | sigset_t oset; | 33 | sigset_t oset; |
| 34 | int ret; | 34 | int ret; |
| 35 | 35 | ||
| 36 | sigprocmask(SIG_SETMASK,&all_masked,&oset); | 36 | sigprocmask(SIG_SETMASK, &all_masked, &oset); |
| 37 | ret=bn_mul_mont_fpu64(rp,ap,bp,np,n0,num); | 37 | ret = bn_mul_mont_fpu64(rp, ap, bp, np, n0, num); |
| 38 | sigprocmask(SIG_SETMASK,&oset,NULL); | 38 | sigprocmask(SIG_SETMASK, &oset, NULL); |
| 39 | 39 | ||
| 40 | return ret; | 40 | return ret; |
| 41 | } | ||
| 42 | #endif | ||
| 43 | } | 41 | } |
| 44 | else if ((OPENSSL_ppccap_P&PPC_FPU64)) | 42 | #endif |
| 43 | } else if ((OPENSSL_ppccap_P&PPC_FPU64)) | ||
| 45 | /* this is a "must" on POWER6, but run-time detection | 44 | /* this is a "must" on POWER6, but run-time detection |
| 46 | * is not implemented yet... */ | 45 | * is not implemented yet... */ |
| 47 | return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num); | 46 | return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num); |
| 48 | 47 | ||
| 49 | return bn_mul_mont_int(rp,ap,bp,np,n0,num); | 48 | return bn_mul_mont_int(rp, ap, bp, np, n0, num); |
| 50 | } | 49 | } |
| 51 | #endif | 50 | #endif |
| 52 | 51 | ||
| 53 | static sigjmp_buf ill_jmp; | 52 | static sigjmp_buf ill_jmp; |
| 54 | static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); } | 53 | static void ill_handler (int sig) |
| 54 | { | ||
| 55 | siglongjmp(ill_jmp, sig); | ||
| 56 | } | ||
| 55 | 57 | ||
| 56 | void OPENSSL_ppc64_probe(void); | 58 | void OPENSSL_ppc64_probe(void); |
| 57 | void OPENSSL_altivec_probe(void); | 59 | void OPENSSL_altivec_probe(void); |
| 58 | 60 | ||
| 59 | void OPENSSL_cpuid_setup(void) | 61 | void |
| 60 | { | 62 | OPENSSL_cpuid_setup(void) |
| 63 | { | ||
| 61 | char *e; | 64 | char *e; |
| 62 | struct sigaction ill_oact,ill_act; | 65 | struct sigaction ill_oact, ill_act; |
| 63 | sigset_t oset; | 66 | sigset_t oset; |
| 64 | static int trigger=0; | 67 | static int trigger = 0; |
| 68 | |||
| 69 | if (trigger) | ||
| 70 | return; | ||
| 71 | trigger = 1; | ||
| 65 | 72 | ||
| 66 | if (trigger) return; | ||
| 67 | trigger=1; | ||
| 68 | |||
| 69 | sigfillset(&all_masked); | 73 | sigfillset(&all_masked); |
| 70 | sigdelset(&all_masked,SIGILL); | 74 | sigdelset(&all_masked, SIGILL); |
| 71 | sigdelset(&all_masked,SIGTRAP); | 75 | sigdelset(&all_masked, SIGTRAP); |
| 72 | #ifdef SIGEMT | 76 | #ifdef SIGEMT |
| 73 | sigdelset(&all_masked,SIGEMT); | 77 | sigdelset(&all_masked, SIGEMT); |
| 74 | #endif | 78 | #endif |
| 75 | sigdelset(&all_masked,SIGFPE); | 79 | sigdelset(&all_masked, SIGFPE); |
| 76 | sigdelset(&all_masked,SIGBUS); | 80 | sigdelset(&all_masked, SIGBUS); |
| 77 | sigdelset(&all_masked,SIGSEGV); | 81 | sigdelset(&all_masked, SIGSEGV); |
| 78 | 82 | ||
| 79 | if ((e=getenv("OPENSSL_ppccap"))) | 83 | if ((e = getenv("OPENSSL_ppccap"))) { |
| 80 | { | 84 | OPENSSL_ppccap_P = strtoul(e, NULL, 0); |
| 81 | OPENSSL_ppccap_P=strtoul(e,NULL,0); | ||
| 82 | return; | 85 | return; |
| 83 | } | 86 | } |
| 84 | 87 | ||
| 85 | OPENSSL_ppccap_P = 0; | 88 | OPENSSL_ppccap_P = 0; |
| 86 | 89 | ||
| 87 | #if defined(_AIX) | 90 | #if defined(_AIX) |
| 88 | if (sizeof(size_t)==4 | 91 | if (sizeof(size_t) == 4 |
| 89 | # if defined(_SC_AIX_KERNEL_BITMODE) | 92 | # if defined(_SC_AIX_KERNEL_BITMODE) |
| 90 | && sysconf(_SC_AIX_KERNEL_BITMODE)!=64 | 93 | && sysconf(_SC_AIX_KERNEL_BITMODE) != 64 |
| 91 | # endif | 94 | # endif |
| 92 | ) | 95 | ) |
| 93 | return; | 96 | return; |
| 94 | #endif | 97 | #endif |
| 95 | 98 | ||
| 96 | memset(&ill_act,0,sizeof(ill_act)); | 99 | memset(&ill_act, 0, sizeof(ill_act)); |
| 97 | ill_act.sa_handler = ill_handler; | 100 | ill_act.sa_handler = ill_handler; |
| 98 | ill_act.sa_mask = all_masked; | 101 | ill_act.sa_mask = all_masked; |
| 99 | 102 | ||
| 100 | sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset); | 103 | sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset); |
| 101 | sigaction(SIGILL,&ill_act,&ill_oact); | 104 | sigaction(SIGILL, &ill_act, &ill_oact); |
| 102 | 105 | ||
| 103 | if (sizeof(size_t)==4) | 106 | if (sizeof(size_t) == 4) { |
| 104 | { | 107 | if (sigsetjmp(ill_jmp, 1) == 0) { |
| 105 | if (sigsetjmp(ill_jmp,1) == 0) | ||
| 106 | { | ||
| 107 | OPENSSL_ppc64_probe(); | 108 | OPENSSL_ppc64_probe(); |
| 108 | OPENSSL_ppccap_P |= PPC_FPU64; | 109 | OPENSSL_ppccap_P |= PPC_FPU64; |
| 109 | } | ||
| 110 | } | 110 | } |
| 111 | else | 111 | } else { |
| 112 | { | ||
| 113 | /* | 112 | /* |
| 114 | * Wanted code detecting POWER6 CPU and setting PPC_FPU64 | 113 | * Wanted code detecting POWER6 CPU and setting PPC_FPU64 |
| 115 | */ | 114 | */ |
| 116 | } | 115 | } |
| 117 | 116 | ||
| 118 | if (sigsetjmp(ill_jmp,1) == 0) | 117 | if (sigsetjmp(ill_jmp, 1) == 0) { |
| 119 | { | ||
| 120 | OPENSSL_altivec_probe(); | 118 | OPENSSL_altivec_probe(); |
| 121 | OPENSSL_ppccap_P |= PPC_ALTIVEC; | 119 | OPENSSL_ppccap_P |= PPC_ALTIVEC; |
| 122 | } | ||
| 123 | |||
| 124 | sigaction (SIGILL,&ill_oact,NULL); | ||
| 125 | sigprocmask(SIG_SETMASK,&oset,NULL); | ||
| 126 | } | 120 | } |
| 121 | |||
| 122 | sigaction (SIGILL, &ill_oact, NULL); | ||
| 123 | sigprocmask(SIG_SETMASK, &oset, NULL); | ||
| 124 | } | ||
