]> git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/sha512_mb/sha512_mb_mgr_flush_avx2.asm
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / sha512_mb / sha512_mb_mgr_flush_avx2.asm
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation 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 ; * Redistributions of source code must retain the above copyright
8 ; notice, this list of conditions and the following disclaimer.
9 ; * Redistributions in binary form must reproduce the above copyright
10 ; notice, this list of conditions and the following disclaimer in
11 ; the documentation and/or other materials provided with the
12 ; distribution.
13 ; * Neither the name of Intel Corporation nor the names of its
14 ; contributors may be used to endorse or promote products derived
15 ; from this software without specific prior written permission.
16 ;
17 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29
30 %include "sha512_job.asm"
31 %include "sha512_mb_mgr_datastruct.asm"
32
33 %include "reg_sizes.asm"
34
35 extern sha512_mb_x4_avx2
36 default rel
37
38 %ifidn __OUTPUT_FORMAT__, elf64
39 ; LINUX register definitions
40 %define arg1 rdi ; rcx
41 %define arg2 rsi ; rdx
42
43 ; idx needs to be other than arg1, arg2, rbx, r12
44 %define idx rdx ; rsi
45 %else
46 ; WINDOWS register definitions
47 %define arg1 rcx
48 %define arg2 rdx
49
50 ; idx needs to be other than arg1, arg2, rbx, r12
51 %define idx rsi
52 %endif
53
54 ; Common definitions
55 %define state arg1
56 %define job arg2
57 %define len2 arg2
58
59 %define unused_lanes rbx
60 %define lane_data rbx
61 %define tmp2 rbx
62
63 %define job_rax rax
64 %define tmp1 rax
65 %define size_offset rax
66 %define tmp rax
67 %define start_offset rax
68
69 %define tmp3 arg1
70
71 %define extra_blocks arg2
72 %define p arg2
73
74 %define tmp4 r8
75 %define lens0 r8
76
77 %define lens1 r9
78 %define lens2 r10
79 %define lens3 r11
80
81 struc stack_frame
82 .xmm: resb 16*10
83 .gpr: resb 8*5
84 .rsp: resb 8
85 endstruc
86
87 ; STACK_SPACE needs to be an odd multiple of 8
88 %define _XMM_SAVE stack_frame.xmm
89 %define _GPR_SAVE stack_frame.gpr
90 %define STACK_SPACE stack_frame_size
91
92 %define APPEND(a,b) a %+ b
93
94 ; SHA512_JOB* sha512_mb_mgr_flush_avx2(SHA512_MB_JOB_MGR *state)
95 ; arg 1 : rcx : state
96 global sha512_mb_mgr_flush_avx2:function
97 sha512_mb_mgr_flush_avx2:
98
99 mov rax, rsp
100
101 sub rsp, STACK_SPACE
102 and rsp, ~31
103
104 mov [rsp + stack_frame.rsp], rax
105
106 mov [rsp + _GPR_SAVE + 8*0], rbx
107 mov [rsp + _GPR_SAVE + 8*1], r12
108 %ifidn __OUTPUT_FORMAT__, win64
109 mov [rsp + _GPR_SAVE + 8*2], rsi
110 vmovdqa [rsp + _XMM_SAVE + 16*0], xmm6
111 vmovdqa [rsp + _XMM_SAVE + 16*1], xmm7
112 vmovdqa [rsp + _XMM_SAVE + 16*2], xmm8
113 vmovdqa [rsp + _XMM_SAVE + 16*3], xmm9
114 vmovdqa [rsp + _XMM_SAVE + 16*4], xmm10
115 vmovdqa [rsp + _XMM_SAVE + 16*5], xmm11
116 vmovdqa [rsp + _XMM_SAVE + 16*6], xmm12
117 vmovdqa [rsp + _XMM_SAVE + 16*7], xmm13
118 vmovdqa [rsp + _XMM_SAVE + 16*8], xmm14
119 vmovdqa [rsp + _XMM_SAVE + 16*9], xmm15
120 %endif
121
122 mov unused_lanes, [state + _unused_lanes]
123 bt unused_lanes, 32+7
124 jc return_null
125
126 ; find a lane with a non-null job
127 xor idx, idx
128 cmp qword [state + _ldata + 1 * _LANE_DATA_size + _job_in_lane], 0
129 cmovne idx, [one]
130 cmp qword [state + _ldata + 2 * _LANE_DATA_size + _job_in_lane], 0
131 cmovne idx, [two]
132 cmp qword [state + _ldata + 3 * _LANE_DATA_size + _job_in_lane], 0
133 cmovne idx, [three]
134
135 ; copy idx to empty lanes
136 copy_lane_data:
137 mov tmp, [state + _args + _data_ptr + 8*idx]
138
139 %assign I 0
140 %rep 4
141 cmp qword [state + _ldata + I * _LANE_DATA_size + _job_in_lane], 0
142 jne APPEND(skip_,I)
143 mov [state + _args + _data_ptr + 8*I], tmp
144 mov dword [state + _lens + 4 + 8*I], 0xFFFFFFFF
145 APPEND(skip_,I):
146 %assign I (I+1)
147 %endrep
148
149 ; Find min length
150 mov lens0, [state + _lens + 0*8]
151 mov idx, lens0
152 mov lens1, [state + _lens + 1*8]
153 cmp lens1, idx
154 cmovb idx, lens1
155 mov lens2, [state + _lens + 2*8]
156 cmp lens2, idx
157 cmovb idx, lens2
158 mov lens3, [state + _lens + 3*8]
159 cmp lens3, idx
160 cmovb idx, lens3
161 mov len2, idx
162 and idx, 0xF
163 and len2, ~0xFF
164 jz len_is_0
165
166 sub lens0, len2
167 sub lens1, len2
168 sub lens2, len2
169 sub lens3, len2
170 shr len2, 32
171 mov [state + _lens + 0*8], lens0
172 mov [state + _lens + 1*8], lens1
173 mov [state + _lens + 2*8], lens2
174 mov [state + _lens + 3*8], lens3
175
176 ; "state" and "args" are the same address, arg1
177 ; len is arg2
178 call sha512_mb_x4_avx2
179 ; state and idx are intact
180
181 len_is_0:
182 ; process completed job "idx"
183 imul lane_data, idx, _LANE_DATA_size
184 lea lane_data, [state + _ldata + lane_data]
185
186 mov job_rax, [lane_data + _job_in_lane]
187 mov qword [lane_data + _job_in_lane], 0
188 mov dword [job_rax + _status], STS_COMPLETED
189 mov unused_lanes, [state + _unused_lanes]
190 shl unused_lanes, 8
191 or unused_lanes, idx
192 mov [state + _unused_lanes], unused_lanes
193
194 vmovq xmm0, [state + _args_digest + 8*idx + 0*32]
195 vpinsrq xmm0, [state + _args_digest + 8*idx + 1*32], 1
196 vmovq xmm1, [state + _args_digest + 8*idx + 2*32]
197 vpinsrq xmm1, [state + _args_digest + 8*idx + 3*32], 1
198 vmovq xmm2, [state + _args_digest + 8*idx + 4*32]
199 vpinsrq xmm2, [state + _args_digest + 8*idx + 5*32], 1
200 vmovq xmm3, [state + _args_digest + 8*idx + 6*32]
201 vpinsrq xmm3, [state + _args_digest + 8*idx + 7*32], 1
202
203 vmovdqa [job_rax + _result_digest + 0*16], xmm0
204 vmovdqa [job_rax + _result_digest + 1*16], xmm1
205 vmovdqa [job_rax + _result_digest + 2*16], xmm2
206 vmovdqa [job_rax + _result_digest + 3*16], xmm3
207
208 return:
209
210 %ifidn __OUTPUT_FORMAT__, win64
211 vmovdqa xmm6, [rsp + _XMM_SAVE + 16*0]
212 vmovdqa xmm7, [rsp + _XMM_SAVE + 16*1]
213 vmovdqa xmm8, [rsp + _XMM_SAVE + 16*2]
214 vmovdqa xmm9, [rsp + _XMM_SAVE + 16*3]
215 vmovdqa xmm10, [rsp + _XMM_SAVE + 16*4]
216 vmovdqa xmm11, [rsp + _XMM_SAVE + 16*5]
217 vmovdqa xmm12, [rsp + _XMM_SAVE + 16*6]
218 vmovdqa xmm13, [rsp + _XMM_SAVE + 16*7]
219 vmovdqa xmm14, [rsp + _XMM_SAVE + 16*8]
220 vmovdqa xmm15, [rsp + _XMM_SAVE + 16*9]
221 mov rsi, [rsp + _GPR_SAVE + 8*2]
222 %endif
223 mov rbx, [rsp + _GPR_SAVE + 8*0]
224 mov r12, [rsp + _GPR_SAVE + 8*1]
225 mov rsp, [rsp + stack_frame.rsp]
226
227 ret
228
229 return_null:
230 xor job_rax, job_rax
231 jmp return
232
233 section .data align=16
234
235 align 16
236 one: dq 1
237 two: dq 2
238 three: dq 3
239