xref: /linux/lib/raid6/neon.uc (revision 7d11965ddb9b9b1e0a5d13c58345ada1ccbc663b)
1*7d11965dSArd Biesheuvel/* -----------------------------------------------------------------------
2*7d11965dSArd Biesheuvel *
3*7d11965dSArd Biesheuvel *   neon.uc - RAID-6 syndrome calculation using ARM NEON instructions
4*7d11965dSArd Biesheuvel *
5*7d11965dSArd Biesheuvel *   Copyright (C) 2012 Rob Herring
6*7d11965dSArd Biesheuvel *
7*7d11965dSArd Biesheuvel *   Based on altivec.uc:
8*7d11965dSArd Biesheuvel *     Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
9*7d11965dSArd Biesheuvel *
10*7d11965dSArd Biesheuvel *   This program is free software; you can redistribute it and/or modify
11*7d11965dSArd Biesheuvel *   it under the terms of the GNU General Public License as published by
12*7d11965dSArd Biesheuvel *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
13*7d11965dSArd Biesheuvel *   Boston MA 02111-1307, USA; either version 2 of the License, or
14*7d11965dSArd Biesheuvel *   (at your option) any later version; incorporated herein by reference.
15*7d11965dSArd Biesheuvel *
16*7d11965dSArd Biesheuvel * ----------------------------------------------------------------------- */
17*7d11965dSArd Biesheuvel
18*7d11965dSArd Biesheuvel/*
19*7d11965dSArd Biesheuvel * neon$#.c
20*7d11965dSArd Biesheuvel *
21*7d11965dSArd Biesheuvel * $#-way unrolled NEON intrinsics math RAID-6 instruction set
22*7d11965dSArd Biesheuvel *
23*7d11965dSArd Biesheuvel * This file is postprocessed using unroll.awk
24*7d11965dSArd Biesheuvel */
25*7d11965dSArd Biesheuvel
26*7d11965dSArd Biesheuvel#include <arm_neon.h>
27*7d11965dSArd Biesheuvel
28*7d11965dSArd Biesheuveltypedef uint8x16_t unative_t;
29*7d11965dSArd Biesheuvel
30*7d11965dSArd Biesheuvel#define NBYTES(x) ((unative_t){x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x})
31*7d11965dSArd Biesheuvel#define NSIZE	sizeof(unative_t)
32*7d11965dSArd Biesheuvel
33*7d11965dSArd Biesheuvel/*
34*7d11965dSArd Biesheuvel * The SHLBYTE() operation shifts each byte left by 1, *not*
35*7d11965dSArd Biesheuvel * rolling over into the next byte
36*7d11965dSArd Biesheuvel */
37*7d11965dSArd Biesheuvelstatic inline unative_t SHLBYTE(unative_t v)
38*7d11965dSArd Biesheuvel{
39*7d11965dSArd Biesheuvel	return vshlq_n_u8(v, 1);
40*7d11965dSArd Biesheuvel}
41*7d11965dSArd Biesheuvel
42*7d11965dSArd Biesheuvel/*
43*7d11965dSArd Biesheuvel * The MASK() operation returns 0xFF in any byte for which the high
44*7d11965dSArd Biesheuvel * bit is 1, 0x00 for any byte for which the high bit is 0.
45*7d11965dSArd Biesheuvel */
46*7d11965dSArd Biesheuvelstatic inline unative_t MASK(unative_t v)
47*7d11965dSArd Biesheuvel{
48*7d11965dSArd Biesheuvel	const uint8x16_t temp = NBYTES(0);
49*7d11965dSArd Biesheuvel	return (unative_t)vcltq_s8((int8x16_t)v, (int8x16_t)temp);
50*7d11965dSArd Biesheuvel}
51*7d11965dSArd Biesheuvel
52*7d11965dSArd Biesheuvelvoid raid6_neon$#_gen_syndrome_real(int disks, unsigned long bytes, void **ptrs)
53*7d11965dSArd Biesheuvel{
54*7d11965dSArd Biesheuvel	uint8_t **dptr = (uint8_t **)ptrs;
55*7d11965dSArd Biesheuvel	uint8_t *p, *q;
56*7d11965dSArd Biesheuvel	int d, z, z0;
57*7d11965dSArd Biesheuvel
58*7d11965dSArd Biesheuvel	register unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
59*7d11965dSArd Biesheuvel	const unative_t x1d = NBYTES(0x1d);
60*7d11965dSArd Biesheuvel
61*7d11965dSArd Biesheuvel	z0 = disks - 3;		/* Highest data disk */
62*7d11965dSArd Biesheuvel	p = dptr[z0+1];		/* XOR parity */
63*7d11965dSArd Biesheuvel	q = dptr[z0+2];		/* RS syndrome */
64*7d11965dSArd Biesheuvel
65*7d11965dSArd Biesheuvel	for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
66*7d11965dSArd Biesheuvel		wq$$ = wp$$ = vld1q_u8(&dptr[z0][d+$$*NSIZE]);
67*7d11965dSArd Biesheuvel		for ( z = z0-1 ; z >= 0 ; z-- ) {
68*7d11965dSArd Biesheuvel			wd$$ = vld1q_u8(&dptr[z][d+$$*NSIZE]);
69*7d11965dSArd Biesheuvel			wp$$ = veorq_u8(wp$$, wd$$);
70*7d11965dSArd Biesheuvel			w2$$ = MASK(wq$$);
71*7d11965dSArd Biesheuvel			w1$$ = SHLBYTE(wq$$);
72*7d11965dSArd Biesheuvel
73*7d11965dSArd Biesheuvel			w2$$ = vandq_u8(w2$$, x1d);
74*7d11965dSArd Biesheuvel			w1$$ = veorq_u8(w1$$, w2$$);
75*7d11965dSArd Biesheuvel			wq$$ = veorq_u8(w1$$, wd$$);
76*7d11965dSArd Biesheuvel		}
77*7d11965dSArd Biesheuvel		vst1q_u8(&p[d+NSIZE*$$], wp$$);
78*7d11965dSArd Biesheuvel		vst1q_u8(&q[d+NSIZE*$$], wq$$);
79*7d11965dSArd Biesheuvel	}
80*7d11965dSArd Biesheuvel}
81