1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * $#-way unrolled portable integer math RAID-6 instruction set
18 * This file is postprocessed using unroll.awk
21 #include <linux/raid/pq.h>
24 * This is the C data type to use
27 /* Change this from BITS_PER_LONG if there is something better... */
28 #if BITS_PER_LONG == 64
29 # define NBYTES(x) ((x) * 0x0101010101010101UL)
33 typedef u64 unative_t;
35 # define NBYTES(x) ((x) * 0x01010101U)
39 typedef u32 unative_t;
45 * These sub-operations are separate inlines since they can sometimes be
46 * specially optimized using architecture-specific hacks.
50 * The SHLBYTE() operation shifts each byte left by 1, *not*
51 * rolling over into the next byte
53 static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
57 vv = (v << 1) & NBYTES(0xfe);
62 * The MASK() operation returns 0xFF in any byte for which the high
63 * bit is 1, 0x00 for any byte for which the high bit is 0.
65 static inline __attribute_const__ unative_t MASK(unative_t v)
69 vv = v & NBYTES(0x80);
70 vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */
75 static void raid6_int$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
77 u8 **dptr = (u8 **)ptrs;
81 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
83 z0 = disks - 3; /* Highest data disk */
84 p = dptr[z0+1]; /* XOR parity */
85 q = dptr[z0+2]; /* RS syndrome */
87 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
88 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
89 for ( z = z0-1 ; z >= 0 ; z-- ) {
90 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
98 *(unative_t *)&p[d+NSIZE*$$] = wp$$;
99 *(unative_t *)&q[d+NSIZE*$$] = wq$$;
103 static void raid6_int$#_xor_syndrome(int disks, int start, int stop,
104 size_t bytes, void **ptrs)
106 u8 **dptr = (u8 **)ptrs;
110 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
112 z0 = stop; /* P/Q right side optimization */
113 p = dptr[disks-2]; /* XOR parity */
114 q = dptr[disks-1]; /* RS syndrome */
116 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
118 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
119 for ( z = z0-1 ; z >= start ; z-- ) {
120 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
123 w1$$ = SHLBYTE(wq$$);
124 w2$$ &= NBYTES(0x1d);
128 /* P/Q left side optimization */
129 for ( z = start-1 ; z >= 0 ; z-- ) {
131 w1$$ = SHLBYTE(wq$$);
132 w2$$ &= NBYTES(0x1d);
135 *(unative_t *)&p[d+NSIZE*$$] ^= wp$$;
136 *(unative_t *)&q[d+NSIZE*$$] ^= wq$$;
141 const struct raid6_calls raid6_intx$# = {
142 raid6_int$#_gen_syndrome,
143 raid6_int$#_xor_syndrome,
144 NULL, /* always valid */