Added Appro's SSSE3 SHA implementations
[gnutls:gnutls.git] / lib / accelerated / x86 / macosx / openssl-cpuid-x86_64.s
1 # Copyright (c) 2011-2012, Andy Polyakov <appro@openssl.org>
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7
8 #     * Redistributions of source code must retain copyright notices,
9 #      this list of conditions and the following disclaimer.
10 #
11 #     * Redistributions in binary form must reproduce the above
12 #      copyright notice, this list of conditions and the following
13 #      disclaimer in the documentation and/or other materials
14 #      provided with the distribution.
15 #
16 #     * Neither the name of the Andy Polyakov nor the names of its
17 #      copyright holder and contributors may be used to endorse or
18 #      promote products derived from this software without specific
19 #      prior written permission.
20 #
21 # ALTERNATIVELY, provided that this notice is retained in full, this
22 # product may be distributed under the terms of the GNU General Public
23 # License (GPL), in which case the provisions of the GPL apply INSTEAD OF
24 # those given above.
25 #
26 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
27 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #
38 # *** This file is auto-generated ***
39 #
40
41 .private_extern _OPENSSL_cpuid_setup
42 .mod_init_func
43         .p2align        3
44         .quad   _OPENSSL_cpuid_setup
45
46 .private_extern __gnutls_x86_cpuid_s
47 .comm   __gnutls_x86_cpuid_s,16,2
48
49 .text   
50
51 .globl  _OPENSSL_atomic_add
52
53 .p2align        4
54 _OPENSSL_atomic_add:
55         movl    (%rdi),%eax
56 L$spin: leaq    (%rsi,%rax,1),%r8
57 .byte   0xf0            
58         cmpxchgl        %r8d,(%rdi)
59         jne     L$spin
60         movl    %r8d,%eax
61 .byte   0x48,0x98       
62         .byte   0xf3,0xc3
63
64
65 .globl  _OPENSSL_rdtsc
66
67 .p2align        4
68 _OPENSSL_rdtsc:
69         rdtsc
70         shlq    $32,%rdx
71         orq     %rdx,%rax
72         .byte   0xf3,0xc3
73
74
75 .globl  _OPENSSL_ia32_cpuid
76
77 .p2align        4
78 _OPENSSL_ia32_cpuid:
79         movq    %rbx,%r8
80
81         xorl    %eax,%eax
82         movl    %eax,8(%rdi)
83         cpuid
84         movl    %eax,%r11d
85
86         xorl    %eax,%eax
87         cmpl    $1970169159,%ebx
88         setne   %al
89         movl    %eax,%r9d
90         cmpl    $1231384169,%edx
91         setne   %al
92         orl     %eax,%r9d
93         cmpl    $1818588270,%ecx
94         setne   %al
95         orl     %eax,%r9d
96         jz      L$intel
97
98         cmpl    $1752462657,%ebx
99         setne   %al
100         movl    %eax,%r10d
101         cmpl    $1769238117,%edx
102         setne   %al
103         orl     %eax,%r10d
104         cmpl    $1145913699,%ecx
105         setne   %al
106         orl     %eax,%r10d
107         jnz     L$intel
108
109
110         movl    $2147483648,%eax
111         cpuid
112         cmpl    $2147483649,%eax
113         jb      L$intel
114         movl    %eax,%r10d
115         movl    $2147483649,%eax
116         cpuid
117         orl     %ecx,%r9d
118         andl    $2049,%r9d
119
120         cmpl    $2147483656,%r10d
121         jb      L$intel
122
123         movl    $2147483656,%eax
124         cpuid
125         movzbq  %cl,%r10
126         incq    %r10
127
128         movl    $1,%eax
129         cpuid
130         btl     $28,%edx
131         jnc     L$generic
132         shrl    $16,%ebx
133         cmpb    %r10b,%bl
134         ja      L$generic
135         andl    $4026531839,%edx
136         jmp     L$generic
137
138 L$intel:
139         cmpl    $4,%r11d
140         movl    $-1,%r10d
141         jb      L$nocacheinfo
142
143         movl    $4,%eax
144         movl    $0,%ecx
145         cpuid
146         movl    %eax,%r10d
147         shrl    $14,%r10d
148         andl    $4095,%r10d
149
150         cmpl    $7,%r11d
151         jb      L$nocacheinfo
152
153         movl    $7,%eax
154         xorl    %ecx,%ecx
155         cpuid
156         movl    %ebx,8(%rdi)
157
158 L$nocacheinfo:
159         movl    $1,%eax
160         cpuid
161         andl    $3220176895,%edx
162         cmpl    $0,%r9d
163         jne     L$notintel
164         orl     $1073741824,%edx
165         andb    $15,%ah
166         cmpb    $15,%ah
167         jne     L$notintel
168         orl     $1048576,%edx
169 L$notintel:
170         btl     $28,%edx
171         jnc     L$generic
172         andl    $4026531839,%edx
173         cmpl    $0,%r10d
174         je      L$generic
175
176         orl     $268435456,%edx
177         shrl    $16,%ebx
178         cmpb    $1,%bl
179         ja      L$generic
180         andl    $4026531839,%edx
181 L$generic:
182         andl    $2048,%r9d
183         andl    $4294965247,%ecx
184         orl     %ecx,%r9d
185
186         movl    %edx,%r10d
187         btl     $27,%r9d
188         jnc     L$clear_avx
189         xorl    %ecx,%ecx
190 .byte   0x0f,0x01,0xd0          
191         andl    $6,%eax
192         cmpl    $6,%eax
193         je      L$done
194 L$clear_avx:
195         movl    $4026525695,%eax
196         andl    %eax,%r9d
197         andl    $4294967263,8(%rdi)
198 L$done:
199         shlq    $32,%r9
200         movl    %r10d,%eax
201         movq    %r8,%rbx
202         orq     %r9,%rax
203         .byte   0xf3,0xc3
204
205
206 .globl  _OPENSSL_cleanse
207
208 .p2align        4
209 _OPENSSL_cleanse:
210         xorq    %rax,%rax
211         cmpq    $15,%rsi
212         jae     L$ot
213         cmpq    $0,%rsi
214         je      L$ret
215 L$ittle:
216         movb    %al,(%rdi)
217         subq    $1,%rsi
218         leaq    1(%rdi),%rdi
219         jnz     L$ittle
220 L$ret:
221         .byte   0xf3,0xc3
222 .p2align        4
223 L$ot:
224         testq   $7,%rdi
225         jz      L$aligned
226         movb    %al,(%rdi)
227         leaq    -1(%rsi),%rsi
228         leaq    1(%rdi),%rdi
229         jmp     L$ot
230 L$aligned:
231         movq    %rax,(%rdi)
232         leaq    -8(%rsi),%rsi
233         testq   $-8,%rsi
234         leaq    8(%rdi),%rdi
235         jnz     L$aligned
236         cmpq    $0,%rsi
237         jne     L$ittle
238         .byte   0xf3,0xc3
239
240 .globl  _OPENSSL_wipe_cpu
241
242 .p2align        4
243 _OPENSSL_wipe_cpu:
244         pxor    %xmm0,%xmm0
245         pxor    %xmm1,%xmm1
246         pxor    %xmm2,%xmm2
247         pxor    %xmm3,%xmm3
248         pxor    %xmm4,%xmm4
249         pxor    %xmm5,%xmm5
250         pxor    %xmm6,%xmm6
251         pxor    %xmm7,%xmm7
252         pxor    %xmm8,%xmm8
253         pxor    %xmm9,%xmm9
254         pxor    %xmm10,%xmm10
255         pxor    %xmm11,%xmm11
256         pxor    %xmm12,%xmm12
257         pxor    %xmm13,%xmm13
258         pxor    %xmm14,%xmm14
259         pxor    %xmm15,%xmm15
260         xorq    %rcx,%rcx
261         xorq    %rdx,%rdx
262         xorq    %rsi,%rsi
263         xorq    %rdi,%rdi
264         xorq    %r8,%r8
265         xorq    %r9,%r9
266         xorq    %r10,%r10
267         xorq    %r11,%r11
268         leaq    8(%rsp),%rax
269         .byte   0xf3,0xc3
270
271 .globl  _OPENSSL_instrument_bus
272
273 .p2align        4
274 _OPENSSL_instrument_bus:
275         movq    %rdi,%r10
276         movq    %rsi,%rcx
277         movq    %rsi,%r11
278
279         rdtsc
280         movl    %eax,%r8d
281         movl    $0,%r9d
282         clflush (%r10)
283 .byte   0xf0            
284         addl    %r9d,(%r10)
285         jmp     L$oop
286 .p2align        4
287 L$oop:  rdtsc
288         movl    %eax,%edx
289         subl    %r8d,%eax
290         movl    %edx,%r8d
291         movl    %eax,%r9d
292         clflush (%r10)
293 .byte   0xf0            
294         addl    %eax,(%r10)
295         leaq    4(%r10),%r10
296         subq    $1,%rcx
297         jnz     L$oop
298
299         movq    %r11,%rax
300         .byte   0xf3,0xc3
301
302
303 .globl  _OPENSSL_instrument_bus2
304
305 .p2align        4
306 _OPENSSL_instrument_bus2:
307         movq    %rdi,%r10
308         movq    %rsi,%rcx
309         movq    %rdx,%r11
310         movq    %rcx,8(%rsp)
311
312         rdtsc
313         movl    %eax,%r8d
314         movl    $0,%r9d
315
316         clflush (%r10)
317 .byte   0xf0            
318         addl    %r9d,(%r10)
319
320         rdtsc
321         movl    %eax,%edx
322         subl    %r8d,%eax
323         movl    %edx,%r8d
324         movl    %eax,%r9d
325 L$oop2:
326         clflush (%r10)
327 .byte   0xf0            
328         addl    %eax,(%r10)
329
330         subq    $1,%r11
331         jz      L$done2
332
333         rdtsc
334         movl    %eax,%edx
335         subl    %r8d,%eax
336         movl    %edx,%r8d
337         cmpl    %r9d,%eax
338         movl    %eax,%r9d
339         movl    $0,%edx
340         setne   %dl
341         subq    %rdx,%rcx
342         leaq    (%r10,%rdx,4),%r10
343         jnz     L$oop2
344
345 L$done2:
346         movq    8(%rsp),%rax
347         subq    %rcx,%rax
348         .byte   0xf3,0xc3
349
350 .globl  _OPENSSL_ia32_rdrand
351
352 .p2align        4
353 _OPENSSL_ia32_rdrand:
354         movl    $8,%ecx
355 L$oop_rdrand:
356 .byte   72,15,199,240
357         jc      L$break_rdrand
358         loop    L$oop_rdrand
359 L$break_rdrand:
360         cmpq    $0,%rax
361         cmoveq  %rcx,%rax
362         .byte   0xf3,0xc3
363
364
365 .section .note.GNU-stack,"",%progbits