Skip to content

Commit 8401831

Browse files
pablodelaramdcornu
authored andcommitted
raid: add AVX2+GFNI implementation for P+Q gen
Signed-off-by: Pablo de Lara <[email protected]>
1 parent 55a42d7 commit 8401831

File tree

4 files changed

+238
-1
lines changed

4 files changed

+238
-1
lines changed

Makefile.nmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ objs = \
126126
bin\pq_gen_avx.obj \
127127
bin\xor_gen_avx.obj \
128128
bin\pq_gen_avx2.obj \
129+
bin\pq_gen_avx2_gfni.obj \
129130
bin\xor_gen_avx512.obj \
130131
bin\pq_gen_avx512.obj \
131132
bin\pq_gen_avx512_gfni.obj \

raid/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ lsrc_x86_64 += \
4444
raid/pq_gen_avx.asm \
4545
raid/xor_gen_avx.asm \
4646
raid/pq_gen_avx2.asm \
47+
raid/pq_gen_avx2_gfni.asm \
4748
raid/xor_gen_avx512.asm \
4849
raid/pq_gen_avx512.asm \
4950
raid/pq_gen_avx512_gfni.asm \

raid/pq_gen_avx2_gfni.asm

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2+
; Copyright(c) 2025 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+
;;; Optimized pq of N source vectors using AVX2+GFNI
31+
;;; int pq_gen_avx2_gfni(int vects, int len, void **array)
32+
33+
;;; Generates P+Q parity vector from N (vects-2) sources in array of pointers
34+
;;; (**array). Last two pointers are the P and Q destinations respectively.
35+
;;; Vectors must be aligned to 64 bytes if NO_NT_LDST is not defined.
36+
;;; Length must be 32 byte multiple.
37+
38+
%include "reg_sizes.asm"
39+
40+
%ifdef HAVE_AS_KNOWS_AVX512
41+
42+
%ifidn __OUTPUT_FORMAT__, elf64
43+
%define arg0 rdi
44+
%define arg1 rsi
45+
%define arg2 rdx
46+
%define arg3 rcx
47+
%define arg4 r8
48+
%define arg5 r9
49+
%define tmp r11
50+
%define tmp3 arg4
51+
%define return rax
52+
%define func(x) x: endbranch
53+
%define FUNC_SAVE
54+
%define FUNC_RESTORE
55+
%endif
56+
57+
%ifidn __OUTPUT_FORMAT__, win64
58+
%define arg0 rcx
59+
%define arg1 rdx
60+
%define arg2 r8
61+
%define arg3 r9
62+
%define tmp r11
63+
%define tmp3 r10
64+
%define return rax
65+
%define stack_size 1*16 + 8 ; must be an odd multiple of 8
66+
%define func(x) proc_frame x
67+
%macro FUNC_SAVE 0
68+
alloc_stack stack_size
69+
vmovdqa [rsp + 0*16], xmm6
70+
end_prolog
71+
%endmacro
72+
73+
%macro FUNC_RESTORE 0
74+
vmovdqa xmm6, [rsp + 0*16]
75+
add rsp, stack_size
76+
%endmacro
77+
%endif
78+
79+
%define vec arg0
80+
%define len arg1
81+
%define ptr arg3
82+
%define pos rax
83+
84+
%define xp1 ymm0
85+
%define xq1 ymm1
86+
%define xs1 ymm2
87+
88+
%define xp2 ymm3
89+
%define xq2 ymm4
90+
%define xs2 ymm5
91+
92+
%define gfmatrix ymm6
93+
94+
%define xp1x xmm0
95+
%define xq1x xmm1
96+
%define xs1x xmm2
97+
98+
%define gfmatrixy ymm6
99+
100+
%define NO_NT_LDST
101+
;;; Use Non-temporal load/stor
102+
%ifdef NO_NT_LDST
103+
%define XLDR vmovdqu ;u8
104+
%define XSTR vmovdqu
105+
%else
106+
%define XLDR vmovntdqa
107+
%define XSTR vmovntdq
108+
%endif
109+
110+
; Matrix with 0x11d as first column
111+
; and identity matrix shited by 1 (as we are multiplying data by 2, mod 0x11d)
112+
; 0 1 0 0 0 0 0 0
113+
; 0 0 1 0 0 0 0 0
114+
; 0 0 0 1 0 0 0 0
115+
; 0 0 0 0 1 0 0 0
116+
; 1 0 0 0 0 1 0 0
117+
; 1 0 0 0 0 0 1 0
118+
; 0 0 0 0 0 0 0 1
119+
; 1 0 0 0 0 0 0 0
120+
default rel
121+
align 32
122+
gf_matrix:
123+
db 0x40, 0x20, 0x10, 0x88, 0x84, 0x82, 0x01, 0x80
124+
db 0x40, 0x20, 0x10, 0x88, 0x84, 0x82, 0x01, 0x80
125+
db 0x40, 0x20, 0x10, 0x88, 0x84, 0x82, 0x01, 0x80
126+
db 0x40, 0x20, 0x10, 0x88, 0x84, 0x82, 0x01, 0x80
127+
128+
129+
[bits 64]
130+
section .text
131+
132+
align 16
133+
mk_global pq_gen_avx2_gfni, function
134+
func(pq_gen_avx2_gfni)
135+
FUNC_SAVE
136+
sub vec, 3 ;Keep as offset to last source
137+
jng return_fail ;Must have at least 2 sources
138+
cmp len, 0
139+
je return_pass
140+
test len, (32-1) ;Check alignment of length
141+
jnz return_fail
142+
143+
vmovdqa gfmatrix, [rel gf_matrix]
144+
145+
xor pos, pos
146+
cmp len, 64
147+
jb loop32
148+
149+
len_aligned_32bytes:
150+
sub len, 64 ;Len points to last block
151+
152+
loop64:
153+
mov ptr, [arg2+vec*8] ;Fetch last source pointer
154+
mov tmp, vec ;Set tmp to point back to last vector
155+
XLDR xs1, [ptr+pos] ;Preload last vector (source)
156+
XLDR xs2, [ptr+pos+32] ;Preload last vector (source)
157+
vpxor xp1, xp1, xp1 ;p1 = 0
158+
vpxor xp2, xp2, xp2 ;p2 = 0
159+
vpxor xq1, xq1, xq1 ;q1 = 0
160+
vpxor xq2, xq2, xq2 ;q2 = 0
161+
162+
next_vect:
163+
sub tmp, 1 ;Inner loop for each source vector
164+
mov ptr, [arg2+tmp*8] ; get pointer to next vect
165+
vpxor xq1, xq1, xs1 ; q1 ^= s1
166+
vpxor xq2, xq2, xs2 ; q2 ^= s2
167+
vpxor xp1, xp1, xs1 ; p1 ^= s1
168+
vpxor xp2, xp2, xs2 ; p2 ^= s2
169+
XLDR xs1, [ptr+pos] ; Get next vector (source data1)
170+
XLDR xs2, [ptr+pos+32] ; Get next vector (source data2)
171+
vgf2p8affineqb xq1, xq1, gfmatrix, 0x00
172+
vgf2p8affineqb xq2, xq2, gfmatrix, 0x00
173+
jg next_vect ; Loop for each vect except 0
174+
175+
mov ptr, [arg2+8+vec*8] ;Get address of P parity vector
176+
mov tmp, [arg2+(2*8)+vec*8] ;Get address of Q parity vector
177+
vpxor xp1, xp1, xs1 ;p1 ^= s1[0] - last source is already loaded
178+
vpxor xq1, xq1, xs1 ;q1 ^= 1 * s1[0]
179+
vpxor xp2, xp2, xs2 ;p2 ^= s2[0]
180+
vpxor xq2, xq2, xs2 ;q2 ^= 1 * s2[0]
181+
XSTR [ptr+pos], xp1 ;Write parity P1 vector
182+
XSTR [ptr+pos+32], xp2 ;Write parity P2 vector
183+
XSTR [tmp+pos], xq1 ;Write parity Q1 vector
184+
XSTR [tmp+pos+32], xq2 ;Write parity Q2 vector
185+
add pos, 2*32
186+
cmp pos, len
187+
jle loop64
188+
189+
;; ------------------------------
190+
;; Do last 32 or 64 Bytes remaining
191+
add len, 2*32
192+
cmp pos, len
193+
je return_pass
194+
195+
loop32:
196+
mov ptr, [arg2+vec*8] ;Fetch last source pointer
197+
mov tmp, vec ;Set tmp to point back to last vector
198+
XLDR xs1, [ptr+pos] ;Preload last vector (source)
199+
vpxor xp1, xp1, xp1 ;p = 0
200+
vpxor xq1, xq1, xq1 ;q = 0
201+
202+
next_vect32:
203+
sub tmp, 1 ;Inner loop for each source vector
204+
mov ptr, [arg2+tmp*8] ; get pointer to next vect
205+
vpxor xq1, xq1, xs1 ; q1 ^= s1
206+
vgf2p8affineqb xq1, xq1, gfmatrix, 0x00
207+
vpxor xp1, xp1, xs1 ; p ^= s
208+
XLDR xs1, [ptr+pos] ; Get next vector (source data)
209+
jg next_vect32 ; Loop for each vect except 0
210+
211+
mov ptr, [arg2+8+vec*8] ;Get address of P parity vector
212+
mov tmp, [arg2+(2*8)+vec*8] ;Get address of Q parity vector
213+
vpxor xp1, xp1, xs1 ;p ^= s[0] - last source is already loaded
214+
vpxor xq1, xq1, xs1 ;q ^= 1 * s[0]
215+
XSTR [ptr+pos], xp1 ;Write parity P vector
216+
XSTR [tmp+pos], xq1 ;Write parity Q vector
217+
add pos, 32
218+
cmp pos, len
219+
jl loop32
220+
221+
222+
return_pass:
223+
mov return, 0
224+
FUNC_RESTORE
225+
ret
226+
227+
return_fail:
228+
mov return, 1
229+
FUNC_RESTORE
230+
ret
231+
232+
endproc_frame
233+
234+
%endif ; ifdef HAVE_AS_KNOWS_AVX512

raid/raid_multibinary.asm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ extern xor_check_sse
5555

5656
%if (AS_FEATURE_LEVEL) >= 10
5757
extern pq_gen_avx512_gfni
58+
extern pq_gen_avx2_gfni
5859
%endif
5960

6061
mbin_interface xor_gen
6162
mbin_interface pq_gen
6263

6364

6465
mbin_dispatch_init6 xor_gen, xor_gen_base, xor_gen_sse, xor_gen_avx, xor_gen_avx, xor_gen_avx512
65-
mbin_dispatch_init8 pq_gen, pq_gen_base, pq_gen_sse, pq_gen_avx, pq_gen_avx2, pq_gen_avx512, pq_gen_avx2, pq_gen_avx512_gfni
66+
mbin_dispatch_init8 pq_gen, pq_gen_base, pq_gen_sse, pq_gen_avx, pq_gen_avx2, pq_gen_avx512, pq_gen_avx2_gfni, pq_gen_avx512_gfni
6667

6768
section .data
6869

0 commit comments

Comments
 (0)