1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
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
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.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 %include "sha256_job.asm"
31 %include "sha256_mb_mgr_datastruct.asm"
33 %include "reg_sizes.asm"
35 extern sha256_mb_x4_sse
41 %ifidn __OUTPUT_FORMAT__, elf64
42 ; Linux register definitions
43 %define arg1 rdi ; rcx
44 %define arg2 rsi ; rdx
46 ; idx needs to be other than arg1, arg2, rbx, r12
48 %define last_len rdx ; rsi
50 %define size_offset rcx ; rdi
51 %define tmp2 rcx ; rdi
54 ; WINDOWS register definitions
58 ; idx needs to be other than arg1, arg2, rbx, r12
62 %define size_offset rdi
74 %define start_offset r11
76 %define unused_lanes rbx
85 %define extra_blocks r8
95 ; STACK_SPACE needs to be an odd multiple of 8
96 %define _XMM_SAVE 16*10
98 %define STACK_SPACE _GPR_SAVE + _XMM_SAVE
100 ; SHA256_JOB* sha256_mb_mgr_submit_sse(SHA256_MB_JOB_MGR *state, SHA256_JOB *job)
101 ; arg 1 : rcx : state
103 mk_global sha256_mb_mgr_submit_sse, function
104 sha256_mb_mgr_submit_sse:
108 mov [rsp + _XMM_SAVE + 8*0], rbx
109 mov [rsp + _XMM_SAVE + 8*1], rbp
110 mov [rsp + _XMM_SAVE + 8*2], r12
111 %ifidn __OUTPUT_FORMAT__, win64
112 mov [rsp + _XMM_SAVE + 8*3], rsi
113 mov [rsp + _XMM_SAVE + 8*4], rdi
114 movdqa [rsp + 16*0], xmm6
115 movdqa [rsp + 16*1], xmm7
116 movdqa [rsp + 16*2], xmm8
117 movdqa [rsp + 16*3], xmm9
118 movdqa [rsp + 16*4], xmm10
119 movdqa [rsp + 16*5], xmm11
120 movdqa [rsp + 16*6], xmm12
121 movdqa [rsp + 16*7], xmm13
122 movdqa [rsp + 16*8], xmm14
123 movdqa [rsp + 16*9], xmm15
126 mov unused_lanes, [state + _unused_lanes]
127 movzx lane, BYTE(unused_lanes)
130 imul lane_data, lane, _LANE_DATA_size
131 mov dword [job + _status], STS_BEING_PROCESSED
132 lea lane_data, [state + _ldata + lane_data]
133 mov [state + _unused_lanes], unused_lanes
134 mov DWORD(len), [job + _len]
139 mov [lane_data + _job_in_lane], job
140 mov [state + _lens + 4*lane], DWORD(len)
142 ; Load digest words from result_digest
143 movdqa xmm0, [job + _result_digest + 0*16]
144 movdqa xmm1, [job + _result_digest + 1*16]
145 movd [state + _args_digest + 4*lane + 0*16], xmm0
146 pextrd [state + _args_digest + 4*lane + 1*16], xmm0, 1
147 pextrd [state + _args_digest + 4*lane + 2*16], xmm0, 2
148 pextrd [state + _args_digest + 4*lane + 3*16], xmm0, 3
149 movd [state + _args_digest + 4*lane + 4*16], xmm1
150 pextrd [state + _args_digest + 4*lane + 5*16], xmm1, 1
151 pextrd [state + _args_digest + 4*lane + 6*16], xmm1, 2
152 pextrd [state + _args_digest + 4*lane + 7*16], xmm1, 3
155 mov p, [job + _buffer]
156 mov [state + _args_data_ptr + 8*lane], p
158 add dword [state + _num_lanes_inuse], 1
159 cmp unused_lanes, 0xF
164 mov DWORD(lens0), [state + _lens + 0*4]
166 mov DWORD(lens1), [state + _lens + 1*4]
169 mov DWORD(lens2), [state + _lens + 2*4]
172 mov DWORD(lens3), [state + _lens + 3*4]
185 mov [state + _lens + 0*4], DWORD(lens0)
186 mov [state + _lens + 1*4], DWORD(lens1)
187 mov [state + _lens + 2*4], DWORD(lens2)
188 mov [state + _lens + 3*4], DWORD(lens3)
190 ; "state" and "args" are the same address, arg1
192 call sha256_mb_x4_sse
193 ; state and idx are intact
196 ; process completed job "idx"
197 imul lane_data, idx, _LANE_DATA_size
198 lea lane_data, [state + _ldata + lane_data]
200 mov job_rax, [lane_data + _job_in_lane]
201 mov unused_lanes, [state + _unused_lanes]
202 mov qword [lane_data + _job_in_lane], 0
203 mov dword [job_rax + _status], STS_COMPLETED
206 mov [state + _unused_lanes], unused_lanes
208 sub dword [state + _num_lanes_inuse], 1
210 movd xmm0, [state + _args_digest + 4*idx + 0*16]
211 pinsrd xmm0, [state + _args_digest + 4*idx + 1*16], 1
212 pinsrd xmm0, [state + _args_digest + 4*idx + 2*16], 2
213 pinsrd xmm0, [state + _args_digest + 4*idx + 3*16], 3
214 movd xmm1, [state + _args_digest + 4*idx + 4*16]
215 pinsrd xmm1, [state + _args_digest + 4*idx + 5*16], 1
216 pinsrd xmm1, [state + _args_digest + 4*idx + 6*16], 2
217 pinsrd xmm1, [state + _args_digest + 4*idx + 7*16], 3
219 movdqa [job_rax + _result_digest + 0*16], xmm0
220 movdqa [job_rax + _result_digest + 1*16], xmm1
224 %ifidn __OUTPUT_FORMAT__, win64
225 movdqa xmm6, [rsp + 16*0]
226 movdqa xmm7, [rsp + 16*1]
227 movdqa xmm8, [rsp + 16*2]
228 movdqa xmm9, [rsp + 16*3]
229 movdqa xmm10, [rsp + 16*4]
230 movdqa xmm11, [rsp + 16*5]
231 movdqa xmm12, [rsp + 16*6]
232 movdqa xmm13, [rsp + 16*7]
233 movdqa xmm14, [rsp + 16*8]
234 movdqa xmm15, [rsp + 16*9]
235 mov rsi, [rsp + _XMM_SAVE + 8*3]
236 mov rdi, [rsp + _XMM_SAVE + 8*4]
238 mov rbx, [rsp + _XMM_SAVE + 8*0]
239 mov rbp, [rsp + _XMM_SAVE + 8*1]
240 mov r12, [rsp + _XMM_SAVE + 8*2]
250 section .data align=16