]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/isa/isa-l/erasure_code/gf_2vect_mad_avx2.asm.s
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / erasure-code / isa / isa-l / erasure_code / gf_2vect_mad_avx2.asm.s
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2015 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 ;;;
31 ;;; gf_2vect_mad_avx2(len, vec, vec_i, mul_array, src, dest);
32 ;;;
33
34 %include "reg_sizes.asm"
35
36 %define PS 8
37
38 %ifidn __OUTPUT_FORMAT__, win64
39 %define arg0 rcx
40 %define arg0.w ecx
41 %define arg1 rdx
42 %define arg2 r8
43 %define arg3 r9
44 %define arg4 r12
45 %define arg5 r15
46
47 %define tmp r11
48 %define tmp.w r11d
49 %define tmp.b r11b
50 %define tmp2 r10
51 %define return rax
52 %define return.w eax
53 %define stack_size 16*9 + 3*8 ; must be an odd multiple of 8
54 %define arg(x) [rsp + stack_size + PS + PS*x]
55
56 %define func(x) proc_frame x
57 %macro FUNC_SAVE 0
58 sub rsp, stack_size
59 vmovdqa [rsp+16*0],xmm6
60 vmovdqa [rsp+16*1],xmm7
61 vmovdqa [rsp+16*2],xmm8
62 vmovdqa [rsp+16*3],xmm9
63 vmovdqa [rsp+16*4],xmm10
64 vmovdqa [rsp+16*5],xmm11
65 vmovdqa [rsp+16*6],xmm12
66 vmovdqa [rsp+16*7],xmm13
67 vmovdqa [rsp+16*8],xmm14
68 save_reg r12, 9*16 + 0*8
69 save_reg r15, 9*16 + 1*8
70 end_prolog
71 mov arg4, arg(4)
72 mov arg5, arg(5)
73 %endmacro
74
75 %macro FUNC_RESTORE 0
76 vmovdqa xmm6, [rsp+16*0]
77 vmovdqa xmm7, [rsp+16*1]
78 vmovdqa xmm8, [rsp+16*2]
79 vmovdqa xmm9, [rsp+16*3]
80 vmovdqa xmm10, [rsp+16*4]
81 vmovdqa xmm11, [rsp+16*5]
82 vmovdqa xmm12, [rsp+16*6]
83 vmovdqa xmm13, [rsp+16*7]
84 vmovdqa xmm14, [rsp+16*8]
85 mov r12, [rsp + 9*16 + 0*8]
86 mov r15, [rsp + 9*16 + 1*8]
87 add rsp, stack_size
88 %endmacro
89 %endif
90
91 %ifidn __OUTPUT_FORMAT__, elf64
92 %define arg0 rdi
93 %define arg0.w edi
94 %define arg1 rsi
95 %define arg2 rdx
96 %define arg3 rcx
97 %define arg4 r8
98 %define arg5 r9
99
100 %define tmp r11
101 %define tmp.w r11d
102 %define tmp.b r11b
103 %define tmp2 r10
104 %define return rax
105 %define return.w eax
106
107 %define func(x) x:
108 %define FUNC_SAVE
109 %define FUNC_RESTORE
110 %endif
111
112 ;;; gf_2vect_mad_avx2(len, vec, vec_i, mul_array, src, dest)
113 %define len arg0
114 %define len.w arg0.w
115 %define vec arg1
116 %define vec_i arg2
117 %define mul_array arg3
118 %define src arg4
119 %define dest1 arg5
120 %define pos return
121 %define pos.w return.w
122
123 %define dest2 tmp2
124
125 %ifndef EC_ALIGNED_ADDR
126 ;;; Use Un-aligned load/store
127 %define XLDR vmovdqu
128 %define XSTR vmovdqu
129 %else
130
131 ;;; Use Non-temporal load/stor
132 %ifdef NO_NT_LDST
133 %define XLDR vmovdqa
134 %define XSTR vmovdqa
135 %else
136 %define XLDR vmovntdqa
137 %define XSTR vmovntdq
138 %endif
139 %endif
140
141
142 default rel
143
144 [bits 64]
145 section .text
146
147 %define xmask0f ymm14
148 %define xmask0fx xmm14
149 %define xgft1_lo ymm13
150 %define xgft1_hi ymm12
151 %define xgft2_lo ymm11
152 %define xgft2_hi ymm10
153
154 %define x0 ymm0
155 %define xtmpa ymm1
156 %define xtmph1 ymm2
157 %define xtmpl1 ymm3
158 %define xtmph2 ymm4
159 %define xtmpl2 ymm5
160 %define xd1 ymm6
161 %define xd2 ymm7
162 %define xtmpd1 ymm8
163 %define xtmpd2 ymm9
164
165 align 16
166 global gf_2vect_mad_avx2:function
167
168 func(gf_2vect_mad_avx2)
169 FUNC_SAVE
170 sub len, 32
171 jl .return_fail
172 xor pos, pos
173 mov tmp.b, 0x0f
174 vpinsrb xmask0fx, xmask0fx, tmp.w, 0
175 vpbroadcastb xmask0f, xmask0fx ;Construct mask 0x0f0f0f...
176
177 sal vec_i, 5 ;Multiply by 32
178 sal vec, 5
179 lea tmp, [mul_array + vec_i]
180 vmovdqu xgft1_lo, [tmp] ;Load array Ax{00}, Ax{01}, ..., Ax{0f}
181 ; " Ax{00}, Ax{10}, ..., Ax{f0}
182 vmovdqu xgft2_lo, [tmp+vec] ;Load array Bx{00}, Bx{01}, ..., Bx{0f}
183 ; " Bx{00}, Bx{10}, ..., Bx{f0}
184
185 vperm2i128 xgft1_hi, xgft1_lo, xgft1_lo, 0x11 ; swapped to hi | hi
186 vperm2i128 xgft1_lo, xgft1_lo, xgft1_lo, 0x00 ; swapped to lo | lo
187 vperm2i128 xgft2_hi, xgft2_lo, xgft2_lo, 0x11 ; swapped to hi | hi
188 vperm2i128 xgft2_lo, xgft2_lo, xgft2_lo, 0x00 ; swapped to lo | lo
189 mov dest2, [dest1+PS] ; reuse mul_array
190 mov dest1, [dest1]
191
192 XLDR xtmpd1, [dest1+len] ;backup the last 16 bytes in dest
193 XLDR xtmpd2, [dest2+len] ;backup the last 16 bytes in dest
194
195 .loop32
196 XLDR xd1, [dest1+pos] ;Get next dest vector
197 XLDR xd2, [dest2+pos] ;Get next dest vector
198 .loop32_overlap:
199 XLDR x0, [src+pos] ;Get next source vector
200
201 vpand xtmpa, x0, xmask0f ;Mask low src nibble in bits 4-0
202 vpsraw x0, x0, 4 ;Shift to put high nibble into bits 4-0
203 vpand x0, x0, xmask0f ;Mask high src nibble in bits 4-0
204
205 vpshufb xtmph1, xgft1_hi, x0 ;Lookup mul table of high nibble
206 vpshufb xtmpl1, xgft1_lo, xtmpa ;Lookup mul table of low nibble
207 vpxor xtmph1, xtmph1, xtmpl1 ;GF add high and low partials
208 vpxor xd1, xd1, xtmph1 ;xd1 += partial
209
210 vpshufb xtmph2, xgft2_hi, x0 ;Lookup mul table of high nibble
211 vpshufb xtmpl2, xgft2_lo, xtmpa ;Lookup mul table of low nibble
212 vpxor xtmph2, xtmph2, xtmpl2 ;GF add high and low partials
213 vpxor xd2, xd2, xtmph2 ;xd2 += partial
214
215 XSTR [dest1+pos], xd1
216 XSTR [dest2+pos], xd2
217
218 add pos, 32 ;Loop on 32 bytes at a time
219 cmp pos, len
220 jle .loop32
221
222 lea tmp, [len + 32]
223 cmp pos, tmp
224 je .return_pass
225
226 ;; Tail len
227 mov pos, len ;Overlapped offset length-32
228 vmovdqa xd1, xtmpd1 ;Restore xd1
229 vmovdqa xd2, xtmpd2 ;Restore xd2
230 jmp .loop32_overlap ;Do one more overlap pass
231
232 .return_pass:
233 mov return, 0
234 FUNC_RESTORE
235 ret
236
237 .return_fail:
238 mov return, 1
239 FUNC_RESTORE
240 ret
241
242 endproc_frame
243
244 section .data
245
246 ;;; func core, ver, snum
247 slversion gf_2vect_mad_avx2, 04, 01, 0205