1 /* -*- linux-c -*- --------------------------- 1 /* -*- linux-c -*- ------------------------------------------------------- * 2 * 2 * 3 * Copyright 2002-2004 H. Peter Anvin - All 3 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved 4 * 4 * 5 * This program is free software; you can re 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Pub 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, Inc., 53 Te 7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330, 8 * Boston MA 02111-1307, USA; either version 8 * Boston MA 02111-1307, USA; either version 2 of the License, or 9 * (at your option) any later version; incor 9 * (at your option) any later version; incorporated herein by reference. 10 * 10 * 11 * ------------------------------------------- 11 * ----------------------------------------------------------------------- */ 12 12 13 /* 13 /* 14 * int$#.c 14 * int$#.c 15 * 15 * 16 * $#-way unrolled portable integer math RAID- 16 * $#-way unrolled portable integer math RAID-6 instruction set 17 * 17 * 18 * This file is postprocessed using unroll.awk 18 * This file is postprocessed using unroll.awk 19 */ 19 */ 20 20 21 #include <linux/raid/pq.h> 21 #include <linux/raid/pq.h> 22 22 23 /* 23 /* 24 * This is the C data type to use 24 * This is the C data type to use 25 */ 25 */ 26 26 27 /* Change this from BITS_PER_LONG if there is 27 /* Change this from BITS_PER_LONG if there is something better... */ 28 #if BITS_PER_LONG == 64 28 #if BITS_PER_LONG == 64 29 # define NBYTES(x) ((x) * 0x0101010101010101UL 29 # define NBYTES(x) ((x) * 0x0101010101010101UL) 30 # define NSIZE 8 30 # define NSIZE 8 31 # define NSHIFT 3 31 # define NSHIFT 3 32 # define NSTRING "64" 32 # define NSTRING "64" 33 typedef u64 unative_t; 33 typedef u64 unative_t; 34 #else 34 #else 35 # define NBYTES(x) ((x) * 0x01010101U) 35 # define NBYTES(x) ((x) * 0x01010101U) 36 # define NSIZE 4 36 # define NSIZE 4 37 # define NSHIFT 2 37 # define NSHIFT 2 38 # define NSTRING "32" 38 # define NSTRING "32" 39 typedef u32 unative_t; 39 typedef u32 unative_t; 40 #endif 40 #endif 41 41 42 42 43 43 44 /* 44 /* >> 45 * IA-64 wants insane amounts of unrolling. On other architectures that >> 46 * is just a waste of space. >> 47 */ >> 48 #if ($# <= 8) || defined(__ia64__) >> 49 >> 50 >> 51 /* 45 * These sub-operations are separate inlines s 52 * These sub-operations are separate inlines since they can sometimes be 46 * specially optimized using architecture-spec 53 * specially optimized using architecture-specific hacks. 47 */ 54 */ 48 55 49 /* 56 /* 50 * The SHLBYTE() operation shifts each byte le 57 * The SHLBYTE() operation shifts each byte left by 1, *not* 51 * rolling over into the next byte 58 * rolling over into the next byte 52 */ 59 */ 53 static inline __attribute_const__ unative_t SH 60 static inline __attribute_const__ unative_t SHLBYTE(unative_t v) 54 { 61 { 55 unative_t vv; 62 unative_t vv; 56 63 57 vv = (v << 1) & NBYTES(0xfe); 64 vv = (v << 1) & NBYTES(0xfe); 58 return vv; 65 return vv; 59 } 66 } 60 67 61 /* 68 /* 62 * The MASK() operation returns 0xFF in any by 69 * The MASK() operation returns 0xFF in any byte for which the high 63 * bit is 1, 0x00 for any byte for which the h 70 * bit is 1, 0x00 for any byte for which the high bit is 0. 64 */ 71 */ 65 static inline __attribute_const__ unative_t MA 72 static inline __attribute_const__ unative_t MASK(unative_t v) 66 { 73 { 67 unative_t vv; 74 unative_t vv; 68 75 69 vv = v & NBYTES(0x80); 76 vv = v & NBYTES(0x80); 70 vv = (vv << 1) - (vv >> 7); /* Overflo 77 vv = (vv << 1) - (vv >> 7); /* Overflow on the top bit is OK */ 71 return vv; 78 return vv; 72 } 79 } 73 80 74 81 75 static void raid6_int$#_gen_syndrome(int disks 82 static void raid6_int$#_gen_syndrome(int disks, size_t bytes, void **ptrs) 76 { 83 { 77 u8 **dptr = (u8 **)ptrs; 84 u8 **dptr = (u8 **)ptrs; 78 u8 *p, *q; 85 u8 *p, *q; 79 int d, z, z0; 86 int d, z, z0; 80 87 81 unative_t wd$$, wq$$, wp$$, w1$$, w2$$ 88 unative_t wd$$, wq$$, wp$$, w1$$, w2$$; 82 89 83 z0 = disks - 3; /* Highest dat 90 z0 = disks - 3; /* Highest data disk */ 84 p = dptr[z0+1]; /* XOR parity 91 p = dptr[z0+1]; /* XOR parity */ 85 q = dptr[z0+2]; /* RS syndrome 92 q = dptr[z0+2]; /* RS syndrome */ 86 93 87 for ( d = 0 ; d < bytes ; d += NSIZE*$ 94 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) { 88 wq$$ = wp$$ = *(unative_t *)&d 95 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE]; 89 for ( z = z0-1 ; z >= 0 ; z-- 96 for ( z = z0-1 ; z >= 0 ; z-- ) { 90 wd$$ = *(unative_t *)& 97 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE]; 91 wp$$ ^= wd$$; 98 wp$$ ^= wd$$; 92 w2$$ = MASK(wq$$); 99 w2$$ = MASK(wq$$); 93 w1$$ = SHLBYTE(wq$$); 100 w1$$ = SHLBYTE(wq$$); 94 w2$$ &= NBYTES(0x1d); 101 w2$$ &= NBYTES(0x1d); 95 w1$$ ^= w2$$; 102 w1$$ ^= w2$$; 96 wq$$ = w1$$ ^ wd$$; 103 wq$$ = w1$$ ^ wd$$; 97 } 104 } 98 *(unative_t *)&p[d+NSIZE*$$] = 105 *(unative_t *)&p[d+NSIZE*$$] = wp$$; 99 *(unative_t *)&q[d+NSIZE*$$] = 106 *(unative_t *)&q[d+NSIZE*$$] = wq$$; 100 } 107 } 101 } 108 } 102 109 103 static void raid6_int$#_xor_syndrome(int disks 110 static void raid6_int$#_xor_syndrome(int disks, int start, int stop, 104 size_t by 111 size_t bytes, void **ptrs) 105 { 112 { 106 u8 **dptr = (u8 **)ptrs; 113 u8 **dptr = (u8 **)ptrs; 107 u8 *p, *q; 114 u8 *p, *q; 108 int d, z, z0; 115 int d, z, z0; 109 116 110 unative_t wd$$, wq$$, wp$$, w1$$, w2$$ 117 unative_t wd$$, wq$$, wp$$, w1$$, w2$$; 111 118 112 z0 = stop; /* P/Q right s 119 z0 = stop; /* P/Q right side optimization */ 113 p = dptr[disks-2]; /* XOR parity 120 p = dptr[disks-2]; /* XOR parity */ 114 q = dptr[disks-1]; /* RS syndrome 121 q = dptr[disks-1]; /* RS syndrome */ 115 122 116 for ( d = 0 ; d < bytes ; d += NSIZE*$ 123 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) { 117 /* P/Q data pages */ 124 /* P/Q data pages */ 118 wq$$ = wp$$ = *(unative_t *)&d 125 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE]; 119 for ( z = z0-1 ; z >= start ; 126 for ( z = z0-1 ; z >= start ; z-- ) { 120 wd$$ = *(unative_t *)& 127 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE]; 121 wp$$ ^= wd$$; 128 wp$$ ^= wd$$; 122 w2$$ = MASK(wq$$); 129 w2$$ = MASK(wq$$); 123 w1$$ = SHLBYTE(wq$$); 130 w1$$ = SHLBYTE(wq$$); 124 w2$$ &= NBYTES(0x1d); 131 w2$$ &= NBYTES(0x1d); 125 w1$$ ^= w2$$; 132 w1$$ ^= w2$$; 126 wq$$ = w1$$ ^ wd$$; 133 wq$$ = w1$$ ^ wd$$; 127 } 134 } 128 /* P/Q left side optimization 135 /* P/Q left side optimization */ 129 for ( z = start-1 ; z >= 0 ; z 136 for ( z = start-1 ; z >= 0 ; z-- ) { 130 w2$$ = MASK(wq$$); 137 w2$$ = MASK(wq$$); 131 w1$$ = SHLBYTE(wq$$); 138 w1$$ = SHLBYTE(wq$$); 132 w2$$ &= NBYTES(0x1d); 139 w2$$ &= NBYTES(0x1d); 133 wq$$ = w1$$ ^ w2$$; 140 wq$$ = w1$$ ^ w2$$; 134 } 141 } 135 *(unative_t *)&p[d+NSIZE*$$] ^ 142 *(unative_t *)&p[d+NSIZE*$$] ^= wp$$; 136 *(unative_t *)&q[d+NSIZE*$$] ^ 143 *(unative_t *)&q[d+NSIZE*$$] ^= wq$$; 137 } 144 } 138 145 139 } 146 } 140 147 141 const struct raid6_calls raid6_intx$# = { 148 const struct raid6_calls raid6_intx$# = { 142 raid6_int$#_gen_syndrome, 149 raid6_int$#_gen_syndrome, 143 raid6_int$#_xor_syndrome, 150 raid6_int$#_xor_syndrome, 144 NULL, /* always vali 151 NULL, /* always valid */ 145 "int" NSTRING "x$#", 152 "int" NSTRING "x$#", 146 0 153 0 147 }; 154 }; >> 155 >> 156 #endif
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.