~ubuntu-branches/ubuntu/wily/openssl/wily

« back to all changes in this revision

Viewing changes to crypto/ppccap.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2014-09-26 11:32:32 UTC
  • Revision ID: package-import@ubuntu.com-20140926113232-ds6gavd9wl43wft5
Tags: 1.0.1f-1ubuntu8
Backport collected POWER8 optimisations from upstream (LP: #1290579).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <setjmp.h>
5
5
#include <signal.h>
6
6
#include <unistd.h>
 
7
#if defined(__linux) || defined(_AIX)
 
8
#include <sys/utsname.h>
 
9
#endif
7
10
#include <crypto.h>
8
11
#include <openssl/bn.h>
9
12
 
10
 
#define PPC_FPU64       (1<<0)
11
 
#define PPC_ALTIVEC     (1<<1)
 
13
#include "ppc_arch.h"
12
14
 
13
 
static int OPENSSL_ppccap_P = 0;
 
15
unsigned int OPENSSL_ppccap_P = 0;
14
16
 
15
17
static sigset_t all_masked;
16
18
 
22
24
 
23
25
        if (sizeof(size_t)==4)
24
26
                {
25
 
#if (defined(__APPLE__) && defined(__MACH__))
 
27
#if 1 || (defined(__APPLE__) && defined(__MACH__))
26
28
                if (num>=8 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64))
27
29
                        return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
28
30
#else
50
52
        }
51
53
#endif
52
54
 
 
55
void sha256_block_p8(void *ctx,const void *inp,size_t len);
 
56
void sha256_block_ppc(void *ctx,const void *inp,size_t len);
 
57
void sha256_block_data_order(void *ctx,const void *inp,size_t len)
 
58
        {
 
59
        OPENSSL_ppccap_P&PPC_CRYPTO207? sha256_block_p8(ctx,inp,len):
 
60
                                        sha256_block_ppc(ctx,inp,len);
 
61
        }
 
62
 
 
63
void sha512_block_p8(void *ctx,const void *inp,size_t len);
 
64
void sha512_block_ppc(void *ctx,const void *inp,size_t len);
 
65
void sha512_block_data_order(void *ctx,const void *inp,size_t len)
 
66
        {
 
67
        OPENSSL_ppccap_P&PPC_CRYPTO207? sha512_block_p8(ctx,inp,len):
 
68
                                        sha512_block_ppc(ctx,inp,len);
 
69
        }
 
70
 
53
71
static sigjmp_buf ill_jmp;
54
72
static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
55
73
 
56
74
void OPENSSL_ppc64_probe(void);
57
75
void OPENSSL_altivec_probe(void);
 
76
void OPENSSL_crypto207_probe(void);
58
77
 
59
78
void OPENSSL_cpuid_setup(void)
60
79
        {
85
104
        OPENSSL_ppccap_P = 0;
86
105
 
87
106
#if defined(_AIX)
88
 
        if (sizeof(size_t)==4
 
107
        if (sizeof(size_t)==4)
 
108
                {
 
109
                struct utsname uts;
89
110
# if defined(_SC_AIX_KERNEL_BITMODE)
90
 
            && sysconf(_SC_AIX_KERNEL_BITMODE)!=64
 
111
                if (sysconf(_SC_AIX_KERNEL_BITMODE)!=64)        return;
91
112
# endif
92
 
           )
93
 
                return;
 
113
                if (uname(&uts)!=0 || atoi(uts.version)<6)      return;
 
114
                }
94
115
#endif
95
116
 
96
117
        memset(&ill_act,0,sizeof(ill_act));
102
123
 
103
124
        if (sizeof(size_t)==4)
104
125
                {
 
126
#ifdef __linux
 
127
                struct utsname uts;
 
128
                if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0)
 
129
#endif
105
130
                if (sigsetjmp(ill_jmp,1) == 0)
106
131
                        {
107
132
                        OPENSSL_ppc64_probe();
119
144
                {
120
145
                OPENSSL_altivec_probe();
121
146
                OPENSSL_ppccap_P |= PPC_ALTIVEC;
 
147
                if (sigsetjmp(ill_jmp,1) == 0)
 
148
                        {
 
149
                        OPENSSL_crypto207_probe();
 
150
                        OPENSSL_ppccap_P |= PPC_CRYPTO207;
 
151
                        }
122
152
                }
123
153
 
124
154
        sigaction (SIGILL,&ill_oact,NULL);