aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/isa-l/erasure_code/aarch64/gf_6vect_mad_neon.S
blob: 3b1b1b4b21094f263c8bc5f2b652a0bdb675178b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/**************************************************************
  Copyright (c) 2019 Huawei Technologies Co., Ltd.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.
    * Neither the name of Huawei Corporation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/

#include "../include/aarch64_label.h"

.text
.global cdecl(gf_6vect_mad_neon)
#ifndef __APPLE__
.type gf_6vect_mad_neon, %function
#endif

/* arguments */
x_len		.req	x0
x_vec		.req	x1
x_vec_i		.req	x2
x_tbl		.req	x3
x_src		.req	x4
x_dest		.req	x5

/* returns */
w_ret		.req	w0

/* local variables */
x_src_end	.req	x6
x_dest1		.req	x7
x_dest2		.req	x8
x_dest3		.req	x9
x_dest4		.req	x10
x_dest5		.req	x11
x_dest6		.req	x_dest
x_tmp		.req	x12
x_tbl1		.req	x13
x_tbl2		.req	x14
x_tbl3		.req	x15
x_tbl4		.req	x16
x_tbl5		.req	x17
x_tbl6		.req	x_tbl
x_const		.req	x18

/* vectors */
v_mask0f	.req	v0
v_tmp_lo	.req	v1
v_tmp_hi	.req	v2
v_tmp		.req	v3
q_tmp		.req	q3

v_gft1_lo	.req	v4
v_gft1_hi	.req	v5
v_gft2_lo	.req	v6
v_gft2_hi	.req	v7
v_gft3_lo	.req	v16
v_gft3_hi	.req	v17
q_gft1_lo	.req	q4
q_gft1_hi	.req	q5
q_gft2_lo	.req	q6
q_gft2_hi	.req	q7
q_gft3_lo	.req	q16
q_gft3_hi	.req	q17

v_gft4_lo	.req	v18
v_gft4_hi	.req	v19
q_gft4_lo	.req	q18
q_gft4_hi	.req	q19
v_gft5_lo	.req	v_gft2_lo
v_gft5_hi	.req	v_gft2_hi
q_gft5_lo	.req	q_gft2_lo
q_gft5_hi	.req	q_gft2_hi
v_gft6_lo	.req	v_gft3_lo
v_gft6_hi	.req	v_gft3_hi
q_gft6_lo	.req	q_gft3_lo
q_gft6_hi	.req	q_gft3_hi

v_data_0	.req	v8
v_data_1	.req	v9
v_data_2	.req	v10
v_data_3	.req	v11
q_data_0	.req	q8
q_data_1	.req	q9
q_data_2	.req	q10
q_data_3	.req	q11

v_data_0_lo	.req	v12
v_data_1_lo	.req	v13
v_data_2_lo	.req	v14
v_data_3_lo	.req	v15
v_data_0_hi	.req	v_data_0
v_data_1_hi	.req	v_data_1
v_data_2_hi	.req	v_data_2
v_data_3_hi	.req	v_data_3

v_d1_0		.req	v20
v_d1_1		.req	v21
v_d1_2		.req	v22
v_d1_3		.req	v23
v_d2_0		.req	v24
v_d2_1		.req	v25
v_d2_2		.req	v26
v_d2_3		.req	v27
v_d3_0		.req	v28
v_d3_1		.req	v29
v_d3_2		.req	v30
v_d3_3		.req	v31
q_d1_0		.req	q20
q_d1_1		.req	q21
q_d1_2		.req	q22
q_d1_3		.req	q23
q_d2_0		.req	q24
q_d2_1		.req	q25
q_d2_2		.req	q26
q_d2_3		.req	q27
q_d3_0		.req	q28
q_d3_1		.req	q29
q_d3_2		.req	q30
q_d3_3		.req	q31

v_d4_0		.req	v_d1_0
v_d4_1		.req	v_d1_1
v_d4_2		.req	v_d1_2
v_d4_3		.req	v_d1_3
q_d4_0		.req	q_d1_0
q_d4_1		.req	q_d1_1
q_d4_2		.req	q_d1_2
q_d4_3		.req	q_d1_3
v_d5_0		.req	v_d2_0
v_d5_1		.req	v_d2_1
v_d5_2		.req	v_d2_2
v_d5_3		.req	v_d2_3
q_d5_0		.req	q_d2_0
q_d5_1		.req	q_d2_1
q_d5_2		.req	q_d2_2
q_d5_3		.req	q_d2_3
v_d6_0		.req	v_d3_0
v_d6_1		.req	v_d3_1
v_d6_2		.req	v_d3_2
v_d6_3		.req	v_d3_3
q_d6_0		.req	q_d3_0
q_d6_1		.req	q_d3_1
q_d6_2		.req	q_d3_2
q_d6_3		.req	q_d3_3

v_data		.req	v21
q_data		.req	q21
v_data_lo	.req	v22
v_data_hi	.req	v23

cdecl(gf_6vect_mad_neon):
	/* less than 16 bytes, return_fail */
	cmp	x_len, #16
	blt	.return_fail

	movi	v_mask0f.16b, #0x0f
	lsl	x_vec_i, x_vec_i, #5
	lsl	x_vec, x_vec, #5
	add	x_tbl1, x_tbl, x_vec_i
	add	x_tbl2, x_tbl1, x_vec
	add	x_tbl3, x_tbl2, x_vec
	add	x_tbl4, x_tbl3, x_vec
	add	x_tbl5, x_tbl4, x_vec
	add	x_tbl6, x_tbl5, x_vec
	add	x_src_end, x_src, x_len
	ldr	x_dest1, [x_dest, #8*0]
	ldr	x_dest2, [x_dest, #8*1]
	ldr	x_dest3, [x_dest, #8*2]
	ldr	x_dest4, [x_dest, #8*3]
	ldr	x_dest5, [x_dest, #8*4]
	ldr	x_dest6, [x_dest, #8*5]
	ldr	q_gft1_lo, [x_tbl1]
	ldr	q_gft1_hi, [x_tbl1, #16]
	ldr	q_gft4_lo, [x_tbl4]
	ldr	q_gft4_hi, [x_tbl4, #16]

.Lloop64_init:
	/* less than 64 bytes, goto Lloop16_init */
	cmp	x_len, #64
	blt	.Lloop16_init

	/* save d8 ~ d15 to stack */
	sub	sp, sp, #64
	stp	d8, d9, [sp]
	stp	d10, d11, [sp, #16]
	stp	d12, d13, [sp, #32]
	stp	d14, d15, [sp, #48]

	sub	x_src_end, x_src_end, #64

.Lloop64:
	ldr	q_data_0, [x_src, #16*0]
	ldr	q_data_1, [x_src, #16*1]
	ldr	q_data_2, [x_src, #16*2]
	ldr	q_data_3, [x_src, #16*3]
	add	x_src, x_src, #64

	ldr	q_d1_0, [x_dest1, #16*0]
	ldr	q_d1_1, [x_dest1, #16*1]
	ldr	q_d1_2, [x_dest1, #16*2]
	ldr	q_d1_3, [x_dest1, #16*3]

	ldr	q_d2_0, [x_dest2, #16*0]
	ldr	q_d2_1, [x_dest2, #16*1]
	ldr	q_d2_2, [x_dest2, #16*2]
	ldr	q_d2_3, [x_dest2, #16*3]

	ldr	q_d3_0, [x_dest3, #16*0]
	ldr	q_d3_1, [x_dest3, #16*1]
	ldr	q_d3_2, [x_dest3, #16*2]
	ldr	q_d3_3, [x_dest3, #16*3]

	ldr	q_gft2_lo, [x_tbl2]
	ldr	q_gft2_hi, [x_tbl2, #16]
	ldr	q_gft3_lo, [x_tbl3]
	ldr	q_gft3_hi, [x_tbl3, #16]

	and	v_data_0_lo.16b, v_data_0.16b, v_mask0f.16b
	and	v_data_1_lo.16b, v_data_1.16b, v_mask0f.16b
	and	v_data_2_lo.16b, v_data_2.16b, v_mask0f.16b
	and	v_data_3_lo.16b, v_data_3.16b, v_mask0f.16b

	ushr	v_data_0_hi.16b, v_data_0.16b, #4
	ushr	v_data_1_hi.16b, v_data_1.16b, #4
	ushr	v_data_2_hi.16b, v_data_2.16b, #4
	ushr	v_data_3_hi.16b, v_data_3.16b, #4

	/* dest1 */
	tbl	v_tmp_lo.16b, {v_gft1_lo.16b}, v_data_0_lo.16b
	tbl	v_tmp_hi.16b, {v_gft1_hi.16b}, v_data_0_hi.16b
	eor	v_d1_0.16b, v_tmp_lo.16b, v_d1_0.16b
	eor	v_d1_0.16b, v_d1_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft1_lo.16b}, v_data_1_lo.16b
	tbl	v_tmp_hi.16b, {v_gft1_hi.16b}, v_data_1_hi.16b
	eor	v_d1_1.16b, v_tmp_lo.16b, v_d1_1.16b
	eor	v_d1_1.16b, v_d1_1.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft1_lo.16b}, v_data_2_lo.16b
	tbl	v_tmp_hi.16b, {v_gft1_hi.16b}, v_data_2_hi.16b
	eor	v_d1_2.16b, v_tmp_lo.16b, v_d1_2.16b
	eor	v_d1_2.16b, v_d1_2.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft1_lo.16b}, v_data_3_lo.16b
	tbl	v_tmp_hi.16b, {v_gft1_hi.16b}, v_data_3_hi.16b
	eor	v_d1_3.16b, v_tmp_lo.16b, v_d1_3.16b
	eor	v_d1_3.16b, v_d1_3.16b, v_tmp_hi.16b

	/* dest2 */
	tbl	v_tmp_lo.16b, {v_gft2_lo.16b}, v_data_0_lo.16b
	tbl	v_tmp_hi.16b, {v_gft2_hi.16b}, v_data_0_hi.16b
	eor	v_d2_0.16b, v_tmp_lo.16b, v_d2_0.16b
	eor	v_d2_0.16b, v_d2_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft2_lo.16b}, v_data_1_lo.16b
	tbl	v_tmp_hi.16b, {v_gft2_hi.16b}, v_data_1_hi.16b
	eor	v_d2_1.16b, v_tmp_lo.16b, v_d2_1.16b
	eor	v_d2_1.16b, v_d2_1.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft2_lo.16b}, v_data_2_lo.16b
	tbl	v_tmp_hi.16b, {v_gft2_hi.16b}, v_data_2_hi.16b
	eor	v_d2_2.16b, v_tmp_lo.16b, v_d2_2.16b
	eor	v_d2_2.16b, v_d2_2.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft2_lo.16b}, v_data_3_lo.16b
	tbl	v_tmp_hi.16b, {v_gft2_hi.16b}, v_data_3_hi.16b
	eor	v_d2_3.16b, v_tmp_lo.16b, v_d2_3.16b
	eor	v_d2_3.16b, v_d2_3.16b, v_tmp_hi.16b

	/* dest3 */
	tbl	v_tmp_lo.16b, {v_gft3_lo.16b}, v_data_0_lo.16b
	tbl	v_tmp_hi.16b, {v_gft3_hi.16b}, v_data_0_hi.16b
	eor	v_d3_0.16b, v_tmp_lo.16b, v_d3_0.16b
	eor	v_d3_0.16b, v_d3_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft3_lo.16b}, v_data_1_lo.16b
	tbl	v_tmp_hi.16b, {v_gft3_hi.16b}, v_data_1_hi.16b
	eor	v_d3_1.16b, v_tmp_lo.16b, v_d3_1.16b
	eor	v_d3_1.16b, v_d3_1.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft3_lo.16b}, v_data_2_lo.16b
	tbl	v_tmp_hi.16b, {v_gft3_hi.16b}, v_data_2_hi.16b
	eor	v_d3_2.16b, v_tmp_lo.16b, v_d3_2.16b
	eor	v_d3_2.16b, v_d3_2.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft3_lo.16b}, v_data_3_lo.16b
	tbl	v_tmp_hi.16b, {v_gft3_hi.16b}, v_data_3_hi.16b
	eor	v_d3_3.16b, v_tmp_lo.16b, v_d3_3.16b
	eor	v_d3_3.16b, v_d3_3.16b, v_tmp_hi.16b

	str	q_d1_0, [x_dest1, #16*0]
	str	q_d1_1, [x_dest1, #16*1]
	str	q_d1_2, [x_dest1, #16*2]
	str	q_d1_3, [x_dest1, #16*3]
	add	x_dest1, x_dest1, #64

	str	q_d2_0, [x_dest2, #16*0]
	str	q_d2_1, [x_dest2, #16*1]
	str	q_d2_2, [x_dest2, #16*2]
	str	q_d2_3, [x_dest2, #16*3]
	add	x_dest2, x_dest2, #64

	str	q_d3_0, [x_dest3, #16*0]
	str	q_d3_1, [x_dest3, #16*1]
	str	q_d3_2, [x_dest3, #16*2]
	str	q_d3_3, [x_dest3, #16*3]
	add	x_dest3, x_dest3, #64

	ldr	q_d4_0, [x_dest4, #16*0]
	ldr	q_d4_1, [x_dest4, #16*1]
	ldr	q_d4_2, [x_dest4, #16*2]
	ldr	q_d4_3, [x_dest4, #16*3]

	ldr	q_d5_0, [x_dest5, #16*0]
	ldr	q_d5_1, [x_dest5, #16*1]
	ldr	q_d5_2, [x_dest5, #16*2]
	ldr	q_d5_3, [x_dest5, #16*3]

	ldr	q_d6_0, [x_dest6, #16*0]
	ldr	q_d6_1, [x_dest6, #16*1]
	ldr	q_d6_2, [x_dest6, #16*2]
	ldr	q_d6_3, [x_dest6, #16*3]

	ldr	q_gft5_lo, [x_tbl5]
	ldr	q_gft5_hi, [x_tbl5, #16]
	ldr	q_gft6_lo, [x_tbl6]
	ldr	q_gft6_hi, [x_tbl6, #16]

	/* dest4 */
	tbl	v_tmp_lo.16b, {v_gft4_lo.16b}, v_data_0_lo.16b
	tbl	v_tmp_hi.16b, {v_gft4_hi.16b}, v_data_0_hi.16b
	eor	v_d4_0.16b, v_tmp_lo.16b, v_d4_0.16b
	eor	v_d4_0.16b, v_d4_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft4_lo.16b}, v_data_1_lo.16b
	tbl	v_tmp_hi.16b, {v_gft4_hi.16b}, v_data_1_hi.16b
	eor	v_d4_1.16b, v_tmp_lo.16b, v_d4_1.16b
	eor	v_d4_1.16b, v_d4_1.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft4_lo.16b}, v_data_2_lo.16b
	tbl	v_tmp_hi.16b, {v_gft4_hi.16b}, v_data_2_hi.16b
	eor	v_d4_2.16b, v_tmp_lo.16b, v_d4_2.16b
	eor	v_d4_2.16b, v_d4_2.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft4_lo.16b}, v_data_3_lo.16b
	tbl	v_tmp_hi.16b, {v_gft4_hi.16b}, v_data_3_hi.16b
	eor	v_d4_3.16b, v_tmp_lo.16b, v_d4_3.16b
	eor	v_d4_3.16b, v_d4_3.16b, v_tmp_hi.16b

	/* dest5 */
	tbl	v_tmp_lo.16b, {v_gft5_lo.16b}, v_data_0_lo.16b
	tbl	v_tmp_hi.16b, {v_gft5_hi.16b}, v_data_0_hi.16b
	eor	v_d5_0.16b, v_tmp_lo.16b, v_d5_0.16b
	eor	v_d5_0.16b, v_d5_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft5_lo.16b}, v_data_1_lo.16b
	tbl	v_tmp_hi.16b, {v_gft5_hi.16b}, v_data_1_hi.16b
	eor	v_d5_1.16b, v_tmp_lo.16b, v_d5_1.16b
	eor	v_d5_1.16b, v_d5_1.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft5_lo.16b}, v_data_2_lo.16b
	tbl	v_tmp_hi.16b, {v_gft5_hi.16b}, v_data_2_hi.16b
	eor	v_d5_2.16b, v_tmp_lo.16b, v_d5_2.16b
	eor	v_d5_2.16b, v_d5_2.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft5_lo.16b}, v_data_3_lo.16b
	tbl	v_tmp_hi.16b, {v_gft5_hi.16b}, v_data_3_hi.16b
	eor	v_d5_3.16b, v_tmp_lo.16b, v_d5_3.16b
	eor	v_d5_3.16b, v_d5_3.16b, v_tmp_hi.16b

	/* dest6 */
	tbl	v_tmp_lo.16b, {v_gft6_lo.16b}, v_data_0_lo.16b
	tbl	v_tmp_hi.16b, {v_gft6_hi.16b}, v_data_0_hi.16b
	eor	v_d6_0.16b, v_tmp_lo.16b, v_d6_0.16b
	eor	v_d6_0.16b, v_d6_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft6_lo.16b}, v_data_1_lo.16b
	tbl	v_tmp_hi.16b, {v_gft6_hi.16b}, v_data_1_hi.16b
	eor	v_d6_1.16b, v_tmp_lo.16b, v_d6_1.16b
	eor	v_d6_1.16b, v_d6_1.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft6_lo.16b}, v_data_2_lo.16b
	tbl	v_tmp_hi.16b, {v_gft6_hi.16b}, v_data_2_hi.16b
	eor	v_d6_2.16b, v_tmp_lo.16b, v_d6_2.16b
	eor	v_d6_2.16b, v_d6_2.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft6_lo.16b}, v_data_3_lo.16b
	tbl	v_tmp_hi.16b, {v_gft6_hi.16b}, v_data_3_hi.16b
	eor	v_d6_3.16b, v_tmp_lo.16b, v_d6_3.16b
	eor	v_d6_3.16b, v_d6_3.16b, v_tmp_hi.16b

	str	q_d4_0, [x_dest4, #16*0]
	str	q_d4_1, [x_dest4, #16*1]
	str	q_d4_2, [x_dest4, #16*2]
	str	q_d4_3, [x_dest4, #16*3]
	add	x_dest4, x_dest4, #64

	str	q_d5_0, [x_dest5, #16*0]
	str	q_d5_1, [x_dest5, #16*1]
	str	q_d5_2, [x_dest5, #16*2]
	str	q_d5_3, [x_dest5, #16*3]
	add	x_dest5, x_dest5, #64

	str	q_d6_0, [x_dest6, #16*0]
	str	q_d6_1, [x_dest6, #16*1]
	str	q_d6_2, [x_dest6, #16*2]
	str	q_d6_3, [x_dest6, #16*3]
	add	x_dest6, x_dest6, #64

	cmp	x_src, x_src_end
	bls	.Lloop64

.Lloop64_end:
	/* restore d8 ~ d15 */
	ldp	d8,  d9,  [sp]
	ldp	d10, d11, [sp, #16]
	ldp	d12, d13, [sp, #32]
	ldp	d14, d15, [sp, #48]
	add	sp, sp, #64
	add	x_src_end, x_src_end, #64

.Lloop16_init:
	sub	x_src_end, x_src_end, #16
	cmp	x_src, x_src_end
	bhi	.lessthan16_init

.Lloop16:
	ldr	q_data, [x_src]

	ldr	q_d1_0, [x_dest1]
	ldr	q_d2_0, [x_dest2]
	ldr	q_d3_0, [x_dest3]
	ldr	q_gft2_lo, [x_tbl2]
	ldr	q_gft2_hi, [x_tbl2, #16]
	ldr	q_gft3_lo, [x_tbl3]
	ldr	q_gft3_hi, [x_tbl3, #16]

	and	v_data_lo.16b, v_data.16b, v_mask0f.16b
	ushr	v_data_hi.16b, v_data.16b, #4

	tbl	v_tmp_lo.16b, {v_gft1_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft1_hi.16b}, v_data_hi.16b
	eor	v_d1_0.16b, v_tmp_lo.16b, v_d1_0.16b
	eor	v_d1_0.16b, v_d1_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft2_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft2_hi.16b}, v_data_hi.16b
	eor	v_d2_0.16b, v_tmp_lo.16b, v_d2_0.16b
	eor	v_d2_0.16b, v_d2_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft3_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft3_hi.16b}, v_data_hi.16b
	eor	v_d3_0.16b, v_tmp_lo.16b, v_d3_0.16b
	eor	v_d3_0.16b, v_d3_0.16b, v_tmp_hi.16b

	str	q_d1_0, [x_dest1]
	str	q_d2_0, [x_dest2]
	str	q_d3_0, [x_dest3]

	ldr	q_d4_0, [x_dest4]
	ldr	q_d5_0, [x_dest5]
	ldr	q_d6_0, [x_dest6]
	ldr	q_gft5_lo, [x_tbl5]
	ldr	q_gft5_hi, [x_tbl5, #16]
	ldr	q_gft6_lo, [x_tbl6]
	ldr	q_gft6_hi, [x_tbl6, #16]

	tbl	v_tmp_lo.16b, {v_gft4_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft4_hi.16b}, v_data_hi.16b
	eor	v_d4_0.16b, v_tmp_lo.16b, v_d4_0.16b
	eor	v_d4_0.16b, v_d4_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft5_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft5_hi.16b}, v_data_hi.16b
	eor	v_d5_0.16b, v_tmp_lo.16b, v_d5_0.16b
	eor	v_d5_0.16b, v_d5_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft6_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft6_hi.16b}, v_data_hi.16b
	eor	v_d6_0.16b, v_tmp_lo.16b, v_d6_0.16b
	eor	v_d6_0.16b, v_d6_0.16b, v_tmp_hi.16b

	str	q_d4_0, [x_dest4]
	str	q_d5_0, [x_dest5]
	str	q_d6_0, [x_dest6]

	add	x_src, x_src, #16
	add	x_dest1, x_dest1, #16
	add	x_dest2, x_dest2, #16
	add	x_dest3, x_dest3, #16
	add	x_dest4, x_dest4, #16
	add	x_dest5, x_dest5, #16
	add	x_dest6, x_dest6, #16
	cmp	x_src, x_src_end
	bls	.Lloop16

.lessthan16_init:
	sub	x_tmp, x_src, x_src_end
	cmp	x_tmp, #16
	beq	.return_pass

.lessthan16:
	mov	x_src, x_src_end
	sub	x_dest1, x_dest1, x_tmp
	sub	x_dest2, x_dest2, x_tmp
	sub	x_dest3, x_dest3, x_tmp
	sub	x_dest4, x_dest4, x_tmp
	sub	x_dest5, x_dest5, x_tmp
	sub	x_dest6, x_dest6, x_tmp

#ifndef __APPLE__
	adrp	x_const, const_tbl
	add	x_const, x_const, :lo12:const_tbl
#else
	adrp	x_const, const_tbl@PAGE
	add	x_const, x_const, const_tbl@PAGEOFF
#endif
	sub	x_const, x_const, x_tmp
	ldr	q_tmp, [x_const, #16]

	ldr	q_data, [x_src]
	ldr	q_d1_0, [x_dest1]
	ldr	q_d2_0, [x_dest2]
	ldr	q_d3_0, [x_dest3]
	ldr	q_gft2_lo, [x_tbl2]
	ldr	q_gft2_hi, [x_tbl2, #16]
	ldr	q_gft3_lo, [x_tbl3]
	ldr	q_gft3_hi, [x_tbl3, #16]

	and	v_data_lo.16b, v_data.16b, v_mask0f.16b
	ushr	v_data_hi.16b, v_data.16b, #4

	tbl	v_tmp_lo.16b, {v_gft1_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft1_hi.16b}, v_data_hi.16b
	eor	v_tmp_hi.16b, v_tmp_lo.16b, v_tmp_hi.16b
	and	v_tmp_hi.16b, v_tmp_hi.16b, v_tmp.16b
	eor	v_d1_0.16b, v_d1_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft2_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft2_hi.16b}, v_data_hi.16b
	eor	v_tmp_hi.16b, v_tmp_lo.16b, v_tmp_hi.16b
	and	v_tmp_hi.16b, v_tmp_hi.16b, v_tmp.16b
	eor	v_d2_0.16b, v_d2_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft3_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft3_hi.16b}, v_data_hi.16b
	eor	v_tmp_hi.16b, v_tmp_lo.16b, v_tmp_hi.16b
	and	v_tmp_hi.16b, v_tmp_hi.16b, v_tmp.16b
	eor	v_d3_0.16b, v_d3_0.16b, v_tmp_hi.16b

	str	q_d1_0, [x_dest1]
	str	q_d2_0, [x_dest2]
	str	q_d3_0, [x_dest3]

	ldr	q_d4_0, [x_dest4]
	ldr	q_d5_0, [x_dest5]
	ldr	q_d6_0, [x_dest6]
	ldr	q_gft5_lo, [x_tbl5]
	ldr	q_gft5_hi, [x_tbl5, #16]
	ldr	q_gft6_lo, [x_tbl6]
	ldr	q_gft6_hi, [x_tbl6, #16]

	tbl	v_tmp_lo.16b, {v_gft4_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft4_hi.16b}, v_data_hi.16b
	eor	v_tmp_hi.16b, v_tmp_lo.16b, v_tmp_hi.16b
	and	v_tmp_hi.16b, v_tmp_hi.16b, v_tmp.16b
	eor	v_d4_0.16b, v_d4_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft5_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft5_hi.16b}, v_data_hi.16b
	eor	v_tmp_hi.16b, v_tmp_lo.16b, v_tmp_hi.16b
	and	v_tmp_hi.16b, v_tmp_hi.16b, v_tmp.16b
	eor	v_d5_0.16b, v_d5_0.16b, v_tmp_hi.16b

	tbl	v_tmp_lo.16b, {v_gft6_lo.16b}, v_data_lo.16b
	tbl	v_tmp_hi.16b, {v_gft6_hi.16b}, v_data_hi.16b
	eor	v_tmp_hi.16b, v_tmp_lo.16b, v_tmp_hi.16b
	and	v_tmp_hi.16b, v_tmp_hi.16b, v_tmp.16b
	eor	v_d6_0.16b, v_d6_0.16b, v_tmp_hi.16b

	str	q_d4_0, [x_dest4]
	str	q_d5_0, [x_dest5]
	str	q_d6_0, [x_dest6]

.return_pass:
	mov	w_ret, #0
	ret

.return_fail:
	mov	w_ret, #1
	ret

ASM_DEF_RODATA
.balign 8
const_tbl:
	.dword 0x0000000000000000, 0x0000000000000000
	.dword 0xffffffffffffffff, 0xffffffffffffffff