2 * Flush routine for SHA1 multibuffer
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright(c) 2014 Intel Corporation.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * Contact Information:
21 * James Guilford <james.guilford@intel.com>
22 * Tim Chen <tim.c.chen@linux.intel.com>
26 * Copyright(c) 2014 Intel Corporation.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
32 * * Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * * Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in
36 * the documentation and/or other materials provided with the
38 * * Neither the name of Intel Corporation nor the names of its
39 * contributors may be used to endorse or promote products derived
40 * from this software without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #include <linux/linkage.h>
55 #include "sha1_mb_mgr_datastruct.S"
60 # LINUX register definitions
69 # idx must be a register not clobbered by sha1_x8_avx2
71 #define DWORD_idx %r8d
73 #define unused_lanes %rbx
74 #define lane_data %rbx
80 #define size_offset %rax
82 #define start_offset %rax
86 #define extra_blocks %arg2
90 # STACK_SPACE needs to be an odd multiple of 8
91 _XMM_SAVE_SIZE = 10*16
96 _GPR_SAVE = _XMM_SAVE + _XMM_SAVE_SIZE
97 STACK_SPACE = _GPR_SAVE + _GPR_SAVE_SIZE + _ALIGN_SIZE
108 .macro SET_OFFSET _offset
113 # JOB* sha1_mb_mgr_flush_avx2(MB_MGR *state)
114 # arg 1 : rcx : state
115 ENTRY(sha1_mb_mgr_flush_avx2)
117 sub $STACK_SPACE, %rsp
119 mov %rbx, _GPR_SAVE(%rsp)
120 mov %r10, _GPR_SAVE+8*1(%rsp) #save rsp
121 mov %rbp, _GPR_SAVE+8*3(%rsp)
122 mov %r12, _GPR_SAVE+8*4(%rsp)
123 mov %r13, _GPR_SAVE+8*5(%rsp)
124 mov %r14, _GPR_SAVE+8*6(%rsp)
125 mov %r15, _GPR_SAVE+8*7(%rsp)
127 # If bit (32+3) is set, then all lanes are empty
128 mov _unused_lanes(state), unused_lanes
129 bt $32+3, unused_lanes
132 # find a lane with a non-null job
134 offset = (_ldata + 1 * _LANE_DATA_size + _job_in_lane)
135 cmpq $0, offset(state)
136 cmovne one(%rip), idx
137 offset = (_ldata + 2 * _LANE_DATA_size + _job_in_lane)
138 cmpq $0, offset(state)
139 cmovne two(%rip), idx
140 offset = (_ldata + 3 * _LANE_DATA_size + _job_in_lane)
141 cmpq $0, offset(state)
142 cmovne three(%rip), idx
143 offset = (_ldata + 4 * _LANE_DATA_size + _job_in_lane)
144 cmpq $0, offset(state)
145 cmovne four(%rip), idx
146 offset = (_ldata + 5 * _LANE_DATA_size + _job_in_lane)
147 cmpq $0, offset(state)
148 cmovne five(%rip), idx
149 offset = (_ldata + 6 * _LANE_DATA_size + _job_in_lane)
150 cmpq $0, offset(state)
151 cmovne six(%rip), idx
152 offset = (_ldata + 7 * _LANE_DATA_size + _job_in_lane)
153 cmpq $0, offset(state)
154 cmovne seven(%rip), idx
156 # copy idx to empty lanes
158 offset = (_args + _data_ptr)
159 mov offset(state,idx,8), tmp
163 offset = (_ldata + I * _LANE_DATA_size + _job_in_lane)
164 cmpq $0, offset(state)
167 offset = (_args + _data_ptr + 8*I)
168 mov tmp, offset(state)
169 offset = (_lens + 4*I)
170 movl $0xFFFFFFFF, offset(state)
177 vmovdqa _lens+0*16(state), %xmm0
178 vmovdqa _lens+1*16(state), %xmm1
180 vpminud %xmm1, %xmm0, %xmm2 # xmm2 has {D,C,B,A}
181 vpalignr $8, %xmm2, %xmm3, %xmm3 # xmm3 has {x,x,D,C}
182 vpminud %xmm3, %xmm2, %xmm2 # xmm2 has {x,x,E,F}
183 vpalignr $4, %xmm2, %xmm3, %xmm3 # xmm3 has {x,x,x,E}
184 vpminud %xmm3, %xmm2, %xmm2 # xmm2 has min value in low dword
186 vmovd %xmm2, DWORD_idx
192 vpand clear_low_nibble(%rip), %xmm2, %xmm2
193 vpshufd $0, %xmm2, %xmm2
195 vpsubd %xmm2, %xmm0, %xmm0
196 vpsubd %xmm2, %xmm1, %xmm1
198 vmovdqa %xmm0, _lens+0*16(state)
199 vmovdqa %xmm1, _lens+1*16(state)
201 # "state" and "args" are the same address, arg1
204 # state and idx are intact
208 # process completed job "idx"
209 imul $_LANE_DATA_size, idx, lane_data
210 lea _ldata(state, lane_data), lane_data
212 mov _job_in_lane(lane_data), job_rax
213 movq $0, _job_in_lane(lane_data)
214 movl $STS_COMPLETED, _status(job_rax)
215 mov _unused_lanes(state), unused_lanes
218 mov unused_lanes, _unused_lanes(state)
220 movl $0xFFFFFFFF, _lens(state, idx, 4)
222 vmovd _args_digest(state , idx, 4) , %xmm0
223 vpinsrd $1, _args_digest+1*32(state, idx, 4), %xmm0, %xmm0
224 vpinsrd $2, _args_digest+2*32(state, idx, 4), %xmm0, %xmm0
225 vpinsrd $3, _args_digest+3*32(state, idx, 4), %xmm0, %xmm0
226 movl _args_digest+4*32(state, idx, 4), tmp2_w
228 vmovdqu %xmm0, _result_digest(job_rax)
229 offset = (_result_digest + 1*16)
230 mov tmp2_w, offset(job_rax)
234 mov _GPR_SAVE(%rsp), %rbx
235 mov _GPR_SAVE+8*1(%rsp), %r10 #saved rsp
236 mov _GPR_SAVE+8*3(%rsp), %rbp
237 mov _GPR_SAVE+8*4(%rsp), %r12
238 mov _GPR_SAVE+8*5(%rsp), %r13
239 mov _GPR_SAVE+8*6(%rsp), %r14
240 mov _GPR_SAVE+8*7(%rsp), %r15
248 ENDPROC(sha1_mb_mgr_flush_avx2)
251 #################################################################
254 ENTRY(sha1_mb_mgr_get_comp_job_avx2)
257 ## if bit 32+3 is set, then all lanes are empty
258 mov _unused_lanes(state), unused_lanes
259 bt $(32+3), unused_lanes
263 vmovdqa _lens(state), %xmm0
264 vmovdqa _lens+1*16(state), %xmm1
266 vpminud %xmm1, %xmm0, %xmm2 # xmm2 has {D,C,B,A}
267 vpalignr $8, %xmm2, %xmm3, %xmm3 # xmm3 has {x,x,D,C}
268 vpminud %xmm3, %xmm2, %xmm2 # xmm2 has {x,x,E,F}
269 vpalignr $4, %xmm2, %xmm3, %xmm3 # xmm3 has {x,x,x,E}
270 vpminud %xmm3, %xmm2, %xmm2 # xmm2 has min value in low dword
272 vmovd %xmm2, DWORD_idx
276 # process completed job "idx"
277 imul $_LANE_DATA_size, idx, lane_data
278 lea _ldata(state, lane_data), lane_data
280 mov _job_in_lane(lane_data), job_rax
281 movq $0, _job_in_lane(lane_data)
282 movl $STS_COMPLETED, _status(job_rax)
283 mov _unused_lanes(state), unused_lanes
286 mov unused_lanes, _unused_lanes(state)
288 movl $0xFFFFFFFF, _lens(state, idx, 4)
290 vmovd _args_digest(state, idx, 4), %xmm0
291 vpinsrd $1, _args_digest+1*32(state, idx, 4), %xmm0, %xmm0
292 vpinsrd $2, _args_digest+2*32(state, idx, 4), %xmm0, %xmm0
293 vpinsrd $3, _args_digest+3*32(state, idx, 4), %xmm0, %xmm0
294 movl _args_digest+4*32(state, idx, 4), tmp2_w
296 vmovdqu %xmm0, _result_digest(job_rax)
297 movl tmp2_w, _result_digest+1*16(job_rax)
307 ENDPROC(sha1_mb_mgr_get_comp_job_avx2)
313 .octa 0x000000000000000000000000FFFFFFF0