diff options
| author | djm <> | 2012-10-13 21:23:50 +0000 |
|---|---|---|
| committer | djm <> | 2012-10-13 21:23:50 +0000 |
| commit | d56dbc3c72494d4b68c03f5bcc3ae1f9df7b17df (patch) | |
| tree | 10ebe51c3542099b0ab8325d8f322372375dc3b4 /src/lib/libcrypto/ppccap.c | |
| parent | bc685bd401e5657f7fb51b4e1a62a7a5c5ea4098 (diff) | |
| parent | 228cae30b117c2493f69ad3c195341cd6ec8d430 (diff) | |
| download | openbsd-d56dbc3c72494d4b68c03f5bcc3ae1f9df7b17df.tar.gz openbsd-d56dbc3c72494d4b68c03f5bcc3ae1f9df7b17df.tar.bz2 openbsd-d56dbc3c72494d4b68c03f5bcc3ae1f9df7b17df.zip | |
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ppccap.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/lib/libcrypto/ppccap.c b/src/lib/libcrypto/ppccap.c new file mode 100644 index 0000000000..ab89ccaa12 --- /dev/null +++ b/src/lib/libcrypto/ppccap.c | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <setjmp.h> | ||
| 5 | #include <signal.h> | ||
| 6 | #include <crypto.h> | ||
| 7 | #include <openssl/bn.h> | ||
| 8 | |||
| 9 | #define PPC_FPU64 (1<<0) | ||
| 10 | #define PPC_ALTIVEC (1<<1) | ||
| 11 | |||
| 12 | static int OPENSSL_ppccap_P = 0; | ||
| 13 | |||
| 14 | static sigset_t all_masked; | ||
| 15 | |||
| 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) | ||
| 18 | { | ||
| 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); | ||
| 21 | |||
| 22 | if (sizeof(size_t)==4) | ||
| 23 | { | ||
| 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); | ||
| 27 | #else | ||
| 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)) | ||
| 31 | { | ||
| 32 | sigset_t oset; | ||
| 33 | int ret; | ||
| 34 | |||
| 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); | ||
| 38 | |||
| 39 | return ret; | ||
| 40 | } | ||
| 41 | #endif | ||
| 42 | } | ||
| 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); | ||
| 47 | |||
| 48 | return bn_mul_mont_int(rp,ap,bp,np,n0,num); | ||
| 49 | } | ||
| 50 | #endif | ||
| 51 | |||
| 52 | static sigjmp_buf ill_jmp; | ||
| 53 | static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); } | ||
| 54 | |||
| 55 | void OPENSSL_ppc64_probe(void); | ||
| 56 | |||
| 57 | void OPENSSL_cpuid_setup(void) | ||
| 58 | { | ||
| 59 | char *e; | ||
| 60 | struct sigaction ill_oact,ill_act; | ||
| 61 | sigset_t oset; | ||
| 62 | static int trigger=0; | ||
| 63 | |||
| 64 | if (trigger) return; | ||
| 65 | trigger=1; | ||
| 66 | |||
| 67 | sigfillset(&all_masked); | ||
| 68 | sigdelset(&all_masked,SIGILL); | ||
| 69 | sigdelset(&all_masked,SIGTRAP); | ||
| 70 | #ifdef SIGEMT | ||
| 71 | sigdelset(&all_masked,SIGEMT); | ||
| 72 | #endif | ||
| 73 | sigdelset(&all_masked,SIGFPE); | ||
| 74 | sigdelset(&all_masked,SIGBUS); | ||
| 75 | sigdelset(&all_masked,SIGSEGV); | ||
| 76 | |||
| 77 | if ((e=getenv("OPENSSL_ppccap"))) | ||
| 78 | { | ||
| 79 | OPENSSL_ppccap_P=strtoul(e,NULL,0); | ||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | OPENSSL_ppccap_P = 0; | ||
| 84 | |||
| 85 | memset(&ill_act,0,sizeof(ill_act)); | ||
| 86 | ill_act.sa_handler = ill_handler; | ||
| 87 | ill_act.sa_mask = all_masked; | ||
| 88 | |||
| 89 | sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset); | ||
| 90 | sigaction(SIGILL,&ill_act,&ill_oact); | ||
| 91 | |||
| 92 | if (sizeof(size_t)==4) | ||
| 93 | { | ||
| 94 | if (sigsetjmp(ill_jmp,1) == 0) | ||
| 95 | { | ||
| 96 | OPENSSL_ppc64_probe(); | ||
| 97 | OPENSSL_ppccap_P |= PPC_FPU64; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | /* | ||
| 103 | * Wanted code detecting POWER6 CPU and setting PPC_FPU64 | ||
| 104 | */ | ||
| 105 | } | ||
| 106 | |||
| 107 | if (sigsetjmp(ill_jmp,1) == 0) | ||
| 108 | { | ||
| 109 | OPENSSL_altivec_probe(); | ||
| 110 | OPENSSL_ppccap_P |= PPC_ALTIVEC; | ||
| 111 | } | ||
| 112 | |||
| 113 | sigaction (SIGILL,&ill_oact,NULL); | ||
| 114 | sigprocmask(SIG_SETMASK,&oset,NULL); | ||
| 115 | } | ||
