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 * ----------------------------------------------------------------------- */
14 * Added helpers for unaligned native int access
20 * 1-way unrolled portable integer math RAID-6 instruction set
22 * This file was postprocessed using unroll.pl and then ported to userspace
26 #include "kerncompat.h"
31 * This is the C data type to use
34 /* Change this from BITS_PER_LONG if there is something better... */
35 #if BITS_PER_LONG == 64
36 # define NBYTES(x) ((x) * 0x0101010101010101UL)
39 typedef uint64_t unative_t;
40 #define put_unaligned_native(val,p) put_unaligned_64((val),(p))
41 #define get_unaligned_native(p) get_unaligned_64((p))
43 # define NBYTES(x) ((x) * 0x01010101U)
46 typedef uint32_t unative_t;
47 #define put_unaligned_native(val,p) put_unaligned_32((val),(p))
48 #define get_unaligned_native(p) get_unaligned_32((p))
52 * These sub-operations are separate inlines since they can sometimes be
53 * specially optimized using architecture-specific hacks.
57 * The SHLBYTE() operation shifts each byte left by 1, *not*
58 * rolling over into the next byte
60 static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
64 vv = (v << 1) & NBYTES(0xfe);
69 * The MASK() operation returns 0xFF in any byte for which the high
70 * bit is 1, 0x00 for any byte for which the high bit is 0.
72 static inline __attribute_const__ unative_t MASK(unative_t v)
76 vv = v & NBYTES(0x80);
77 vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */
82 void raid6_gen_syndrome(int disks, size_t bytes, void **ptrs)
84 uint8_t **dptr = (uint8_t **)ptrs;
88 unative_t wd0, wq0, wp0, w10, w20;
90 z0 = disks - 3; /* Highest data disk */
91 p = dptr[z0+1]; /* XOR parity */
92 q = dptr[z0+2]; /* RS syndrome */
94 for ( d = 0 ; d < bytes ; d += NSIZE*1 ) {
95 wq0 = wp0 = get_unaligned_native(&dptr[z0][d+0*NSIZE]);
96 for ( z = z0-1 ; z >= 0 ; z-- ) {
97 wd0 = get_unaligned_native(&dptr[z][d+0*NSIZE]);
105 put_unaligned_native(wp0, &p[d+NSIZE*0]);
106 put_unaligned_native(wq0, &q[d+NSIZE*0]);