aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid6altivec.uc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/md/raid6altivec.uc
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/md/raid6altivec.uc')
-rw-r--r--drivers/md/raid6altivec.uc122
1 files changed, 122 insertions, 0 deletions
diff --git a/drivers/md/raid6altivec.uc b/drivers/md/raid6altivec.uc
new file mode 100644
index 000000000000..1de8f030eee0
--- /dev/null
+++ b/drivers/md/raid6altivec.uc
@@ -0,0 +1,122 @@
1/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright 2002-2004 H. Peter Anvin - All Rights Reserved
4 *
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 * Bostom MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * raid6altivec$#.c
15 *
16 * $#-way unrolled portable integer math RAID-6 instruction set
17 *
18 * This file is postprocessed using unroll.pl
19 *
20 * <benh> hpa: in process,
21 * you can just "steal" the vec unit with enable_kernel_altivec() (but
22 * bracked this with preempt_disable/enable or in a lock)
23 */
24
25#include "raid6.h"
26
27#ifdef CONFIG_ALTIVEC
28
29#include <altivec.h>
30#include <asm/system.h>
31#include <asm/cputable.h>
32
33/*
34 * This is the C data type to use
35 */
36
37typedef vector unsigned char unative_t;
38
39#define NBYTES(x) ((vector unsigned char) {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x})
40#define NSIZE sizeof(unative_t)
41
42/*
43 * The SHLBYTE() operation shifts each byte left by 1, *not*
44 * rolling over into the next byte
45 */
46static inline __attribute_const__ unative_t SHLBYTE(unative_t v)
47{
48 return vec_add(v,v);
49}
50
51/*
52 * The MASK() operation returns 0xFF in any byte for which the high
53 * bit is 1, 0x00 for any byte for which the high bit is 0.
54 */
55static inline __attribute_const__ unative_t MASK(unative_t v)
56{
57 unative_t zv = NBYTES(0);
58
59 /* vec_cmpgt returns a vector bool char; thus the need for the cast */
60 return (unative_t)vec_cmpgt(zv, v);
61}
62
63
64/* This is noinline to make damned sure that gcc doesn't move any of the
65 Altivec code around the enable/disable code */
66static void noinline
67raid6_altivec$#_gen_syndrome_real(int disks, size_t bytes, void **ptrs)
68{
69 u8 **dptr = (u8 **)ptrs;
70 u8 *p, *q;
71 int d, z, z0;
72
73 unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
74 unative_t x1d = NBYTES(0x1d);
75
76 z0 = disks - 3; /* Highest data disk */
77 p = dptr[z0+1]; /* XOR parity */
78 q = dptr[z0+2]; /* RS syndrome */
79
80 for ( d = 0 ; d < bytes ; d += NSIZE*$# ) {
81 wq$$ = wp$$ = *(unative_t *)&dptr[z0][d+$$*NSIZE];
82 for ( z = z0-1 ; z >= 0 ; z-- ) {
83 wd$$ = *(unative_t *)&dptr[z][d+$$*NSIZE];
84 wp$$ = vec_xor(wp$$, wd$$);
85 w2$$ = MASK(wq$$);
86 w1$$ = SHLBYTE(wq$$);
87 w2$$ = vec_and(w2$$, x1d);
88 w1$$ = vec_xor(w1$$, w2$$);
89 wq$$ = vec_xor(w1$$, wd$$);
90 }
91 *(unative_t *)&p[d+NSIZE*$$] = wp$$;
92 *(unative_t *)&q[d+NSIZE*$$] = wq$$;
93 }
94}
95
96static void raid6_altivec$#_gen_syndrome(int disks, size_t bytes, void **ptrs)
97{
98 preempt_disable();
99 enable_kernel_altivec();
100
101 raid6_altivec$#_gen_syndrome_real(disks, bytes, ptrs);
102
103 preempt_enable();
104}
105
106int raid6_have_altivec(void);
107#if $# == 1
108int raid6_have_altivec(void)
109{
110 /* This assumes either all CPUs have Altivec or none does */
111 return cpu_has_feature(CPU_FTR_ALTIVEC);
112}
113#endif
114
115const struct raid6_calls raid6_altivec$# = {
116 raid6_altivec$#_gen_syndrome,
117 raid6_have_altivec,
118 "altivecx$#",
119 0
120};
121
122#endif /* CONFIG_ALTIVEC */