1 /* -*- linux-c -*- --------------------------- 2 * 3 * Copyright 2002-2004 H. Peter Anvin - All 4 * 5 * This program is free software; you can re 6 * it under the terms of the GNU General Pub 7 * the Free Software Foundation, Inc., 53 Te 8 * Boston MA 02111-1307, USA; either version 9 * (at your option) any later version; incor 10 * 11 * ------------------------------------------- 12 13 /* 14 * raid6altivec$#.c 15 * 16 * $#-way unrolled portable integer math RAID- 17 * 18 * This file is postprocessed using unroll.awk 19 * 20 * <benh> hpa: in process, 21 * you can just "steal" the vec unit with enab 22 * bracked this with preempt_disable/enable or 23 */ 24 25 #include <linux/raid/pq.h> 26 27 #ifdef CONFIG_ALTIVEC 28 29 #include <altivec.h> 30 #ifdef __KERNEL__ 31 # include <asm/cputable.h> 32 # include <asm/switch_to.h> 33 #endif /* __KERNEL__ */ 34 35 /* 36 * This is the C data type to use. We use a v 37 * signed char so vec_cmpgt() will generate th 38 * instruction. 39 */ 40 41 typedef vector signed char unative_t; 42 43 #define NBYTES(x) ((vector signed char) {x,x,x 44 #define NSIZE sizeof(unative_t) 45 46 /* 47 * The SHLBYTE() operation shifts each byte le 48 * rolling over into the next byte 49 */ 50 static inline __attribute_const__ unative_t SH 51 { 52 return vec_add(v,v); 53 } 54 55 /* 56 * The MASK() operation returns 0xFF in any by 57 * bit is 1, 0x00 for any byte for which the h 58 */ 59 static inline __attribute_const__ unative_t MA 60 { 61 unative_t zv = NBYTES(0); 62 63 /* vec_cmpgt returns a vector bool cha 64 return (unative_t)vec_cmpgt(zv, v); 65 } 66 67 68 /* This is noinline to make damned sure that g 69 Altivec code around the enable/disable code 70 static void noinline 71 raid6_altivec$#_gen_syndrome_real(int disks, s 72 { 73 u8 **dptr = (u8 **)ptrs; 74 u8 *p, *q; 75 int d, z, z0; 76 77 unative_t wd$$, wq$$, wp$$, w1$$, w2$$ 78 unative_t x1d = NBYTES(0x1d); 79 80 z0 = disks - 3; /* Highest dat 81 p = dptr[z0+1]; /* XOR parity 82 q = dptr[z0+2]; /* RS syndrome 83 84 for ( d = 0 ; d < bytes ; d += NSIZE*$ 85 wq$$ = wp$$ = *(unative_t *)&d 86 for ( z = z0-1 ; z >= 0 ; z-- 87 wd$$ = *(unative_t *)& 88 wp$$ = vec_xor(wp$$, w 89 w2$$ = MASK(wq$$); 90 w1$$ = SHLBYTE(wq$$); 91 w2$$ = vec_and(w2$$, x 92 w1$$ = vec_xor(w1$$, w 93 wq$$ = vec_xor(w1$$, w 94 } 95 *(unative_t *)&p[d+NSIZE*$$] = 96 *(unative_t *)&q[d+NSIZE*$$] = 97 } 98 } 99 100 static void raid6_altivec$#_gen_syndrome(int d 101 { 102 preempt_disable(); 103 enable_kernel_altivec(); 104 105 raid6_altivec$#_gen_syndrome_real(disk 106 107 disable_kernel_altivec(); 108 preempt_enable(); 109 } 110 111 int raid6_have_altivec(void); 112 #if $# == 1 113 int raid6_have_altivec(void) 114 { 115 /* This assumes either all CPUs have A 116 # ifdef __KERNEL__ 117 return cpu_has_feature(CPU_FTR_ALTIVEC 118 # else 119 return 1; 120 # endif 121 } 122 #endif 123 124 const struct raid6_calls raid6_altivec$# = { 125 raid6_altivec$#_gen_syndrome, 126 NULL, /* XOR not yet 127 raid6_have_altivec, 128 "altivecx$#", 129 0 130 }; 131 132 #endif /* CONFIG_ALTIVEC */
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.