0001 /* -*- linux-c -*- ------------------------------------------------------- *
0002 *
0003 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
0004 *
0005 * This program is free software; you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
0008 * Boston MA 02111-1307, USA; either version 2 of the License, or
0009 * (at your option) any later version; incorporated herein by reference.
0010 *
0011 * ----------------------------------------------------------------------- */
0012
0013 /*
0014 * int$#.c
0015 *
0016 * $#-way unrolled portable integer math RAID-6 instruction set
0017 *
0018 * This file is postprocessed using unroll.awk
0019 */
0020
0021 #include <linux/raid/pq.h>
0022
0023 /*
0024 * This is the C data type to use
0025 */
0026
0027 /* Change this from BITS_PER_LONG if there is something better... */
0028 #if BITS_PER_LONG == 64
0029 # define NBYTES(x) ((x) * 0x0101010101010101UL)
0030 # define NSIZE 8
0031 # define NSHIFT 3
0032 # define NSTRING "64"
0033 typedef u64 unative_t;
0034 #else
0035 # define NBYTES(x) ((x) * 0x01010101U)
0036 # define NSIZE 4
0037 # define NSHIFT 2
0038 # define NSTRING "32"
0039 typedef u32 unative_t;
0040 #endif
0041
0042
0043
0044 /*
0045 * IA-64 wants insane amounts of unrolling. On other architectures that
0046 * is just a waste of space.
0047 */
0048 #if ($# <= 8) || defined(__ia64__)
0049
0050
0051 /*
0052 * These sub-operations are separate inlines since they can sometimes be
0053 * specially optimized using architecture-specific hacks.
0054 */
0055
0056 /*
0057 * The SHLBYTE() operation shifts each byte left by 1, *not*
0058 * rolling over into the next byte
0059 */
0060 static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
0061 {
0062 unative_t vv;
0063
0064 vv = (v << 1) & NBYTES(0xfe);
0065 return vv;
0066 }
0067
0068 /*
0069 * The MASK() operation returns 0xFF in any byte for which the high
0070 * bit is 1, 0x00 for any byte for which the high bit is 0.
0071 */
0072 static inline __attribute_const__ unative_t MASK(unative_t v)
0073 {
0074 unative_t vv;
0075
0076 vv = v & NBYTES(0x80);
0077 vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */
0078 return vv;
0079 }
0080
0081
0082 static void raid6_int$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
0083 {
0084 u8 **dptr = (u8 **)ptrs;
0085 u8 *p, *q;
0086 int d, z, z0;
0087
0088 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
0089
0090 z0 = disks - 3; /* Highest data disk */
0091 p = dptr[z0+1]; /* XOR parity */
0092 q = dptr[z0+2]; /* RS syndrome */
0093
0094 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
0095 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
0096 for ( z = z0-1 ; z >= 0 ; z-- ) {
0097 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
0098 wp$$ ^= wd$$;
0099 w2$$ = MASK(wq$$);
0100 w1$$ = SHLBYTE(wq$$);
0101 w2$$ &= NBYTES(0x1d);
0102 w1$$ ^= w2$$;
0103 wq$$ = w1$$ ^ wd$$;
0104 }
0105 *(unative_t *)&p[d+NSIZE*$$] = wp$$;
0106 *(unative_t *)&q[d+NSIZE*$$] = wq$$;
0107 }
0108 }
0109
0110 static void raid6_int$#_xor_syndrome(int disks, int start, int stop,
0111 size_t bytes, void **ptrs)
0112 {
0113 u8 **dptr = (u8 **)ptrs;
0114 u8 *p, *q;
0115 int d, z, z0;
0116
0117 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
0118
0119 z0 = stop; /* P/Q right side optimization */
0120 p = dptr[disks-2]; /* XOR parity */
0121 q = dptr[disks-1]; /* RS syndrome */
0122
0123 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
0124 /* P/Q data pages */
0125 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
0126 for ( z = z0-1 ; z >= start ; z-- ) {
0127 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
0128 wp$$ ^= wd$$;
0129 w2$$ = MASK(wq$$);
0130 w1$$ = SHLBYTE(wq$$);
0131 w2$$ &= NBYTES(0x1d);
0132 w1$$ ^= w2$$;
0133 wq$$ = w1$$ ^ wd$$;
0134 }
0135 /* P/Q left side optimization */
0136 for ( z = start-1 ; z >= 0 ; z-- ) {
0137 w2$$ = MASK(wq$$);
0138 w1$$ = SHLBYTE(wq$$);
0139 w2$$ &= NBYTES(0x1d);
0140 wq$$ = w1$$ ^ w2$$;
0141 }
0142 *(unative_t *)&p[d+NSIZE*$$] ^= wp$$;
0143 *(unative_t *)&q[d+NSIZE*$$] ^= wq$$;
0144 }
0145
0146 }
0147
0148 const struct raid6_calls raid6_intx$# = {
0149 raid6_int$#_gen_syndrome,
0150 raid6_int$#_xor_syndrome,
0151 NULL, /* always valid */
0152 "int" NSTRING "x$#",
0153 0
0154 };
0155
0156 #endif