diff options
author | Oliver Pinter <oliver.pntr@gmail.com> | 2008-02-06 04:39:47 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-06 13:41:18 -0500 |
commit | 54212cf4054e7cf44f3ca97c3c5fb942dbfe7013 (patch) | |
tree | 11a2c20dbe43baacdf569a5ccfb6d0e0e6824bdb /drivers/md | |
parent | 91c4313206e4409871e2ddd13c29508afe1c8834 (diff) |
coding style cleanups for drivers/md/mktables.c
Signed-off-by: Oliver Pinter <oliver.pntr@gmail.com>
Cc: Neil Brown <neilb@suse.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/mktables.c | 180 |
1 files changed, 92 insertions, 88 deletions
diff --git a/drivers/md/mktables.c b/drivers/md/mktables.c index adef299908cf..339afd0e1b15 100644 --- a/drivers/md/mktables.c +++ b/drivers/md/mktables.c | |||
@@ -26,100 +26,104 @@ | |||
26 | 26 | ||
27 | static uint8_t gfmul(uint8_t a, uint8_t b) | 27 | static uint8_t gfmul(uint8_t a, uint8_t b) |
28 | { | 28 | { |
29 | uint8_t v = 0; | 29 | uint8_t v = 0; |
30 | 30 | ||
31 | while ( b ) { | 31 | while (b) { |
32 | if ( b & 1 ) v ^= a; | 32 | if (b & 1) |
33 | a = (a << 1) ^ (a & 0x80 ? 0x1d : 0); | 33 | v ^= a; |
34 | b >>= 1; | 34 | a = (a << 1) ^ (a & 0x80 ? 0x1d : 0); |
35 | } | 35 | b >>= 1; |
36 | return v; | 36 | } |
37 | |||
38 | return v; | ||
37 | } | 39 | } |
38 | 40 | ||
39 | static uint8_t gfpow(uint8_t a, int b) | 41 | static uint8_t gfpow(uint8_t a, int b) |
40 | { | 42 | { |
41 | uint8_t v = 1; | 43 | uint8_t v = 1; |
42 | 44 | ||
43 | b %= 255; | 45 | b %= 255; |
44 | if ( b < 0 ) | 46 | if (b < 0) |
45 | b += 255; | 47 | b += 255; |
46 | 48 | ||
47 | while ( b ) { | 49 | while (b) { |
48 | if ( b & 1 ) v = gfmul(v,a); | 50 | if (b & 1) |
49 | a = gfmul(a,a); | 51 | v = gfmul(v, a); |
50 | b >>= 1; | 52 | a = gfmul(a, a); |
51 | } | 53 | b >>= 1; |
52 | return v; | 54 | } |
55 | |||
56 | return v; | ||
53 | } | 57 | } |
54 | 58 | ||
55 | int main(int argc, char *argv[]) | 59 | int main(int argc, char *argv[]) |
56 | { | 60 | { |
57 | int i, j, k; | 61 | int i, j, k; |
58 | uint8_t v; | 62 | uint8_t v; |
59 | uint8_t exptbl[256], invtbl[256]; | 63 | uint8_t exptbl[256], invtbl[256]; |
60 | 64 | ||
61 | printf("#include \"raid6.h\"\n"); | 65 | printf("#include \"raid6.h\"\n"); |
62 | 66 | ||
63 | /* Compute multiplication table */ | 67 | /* Compute multiplication table */ |
64 | printf("\nconst u8 __attribute__((aligned(256)))\n" | 68 | printf("\nconst u8 __attribute__((aligned(256)))\n" |
65 | "raid6_gfmul[256][256] =\n" | 69 | "raid6_gfmul[256][256] =\n" |
66 | "{\n"); | 70 | "{\n"); |
67 | for ( i = 0 ; i < 256 ; i++ ) { | 71 | for (i = 0; i < 256; i++) { |
68 | printf("\t{\n"); | 72 | printf("\t{\n"); |
69 | for ( j = 0 ; j < 256 ; j += 8 ) { | 73 | for (j = 0; j < 256; j += 8) { |
70 | printf("\t\t"); | 74 | printf("\t\t"); |
71 | for ( k = 0 ; k < 8 ; k++ ) { | 75 | for (k = 0; k < 8; k++) |
72 | printf("0x%02x, ", gfmul(i,j+k)); | 76 | printf("0x%02x, ", gfmul(i, j+k)); |
73 | } | 77 | printf("\n"); |
74 | printf("\n"); | 78 | } |
75 | } | 79 | printf("\t},\n"); |
76 | printf("\t},\n"); | 80 | } |
77 | } | 81 | printf("};\n"); |
78 | printf("};\n"); | 82 | |
79 | 83 | /* Compute power-of-2 table (exponent) */ | |
80 | /* Compute power-of-2 table (exponent) */ | 84 | v = 1; |
81 | v = 1; | 85 | printf("\nconst u8 __attribute__((aligned(256)))\n" |
82 | printf("\nconst u8 __attribute__((aligned(256)))\n" | 86 | "raid6_gfexp[256] =\n" |
83 | "raid6_gfexp[256] =\n" | 87 | "{\n"); |
84 | "{\n"); | 88 | for (i = 0; i < 256; i += 8) { |
85 | for ( i = 0 ; i < 256 ; i += 8 ) { | 89 | printf("\t"); |
86 | printf("\t"); | 90 | for (j = 0; j < 8; j++) { |
87 | for ( j = 0 ; j < 8 ; j++ ) { | 91 | exptbl[i+j] = v; |
88 | exptbl[i+j] = v; | 92 | printf("0x%02x, ", v); |
89 | printf("0x%02x, ", v); | 93 | v = gfmul(v, 2); |
90 | v = gfmul(v,2); | 94 | if (v == 1) |
91 | if ( v == 1 ) v = 0; /* For entry 255, not a real entry */ | 95 | v = 0; /* For entry 255, not a real entry */ |
92 | } | 96 | } |
93 | printf("\n"); | 97 | printf("\n"); |
94 | } | 98 | } |
95 | printf("};\n"); | 99 | printf("};\n"); |
96 | 100 | ||
97 | /* Compute inverse table x^-1 == x^254 */ | 101 | /* Compute inverse table x^-1 == x^254 */ |
98 | printf("\nconst u8 __attribute__((aligned(256)))\n" | 102 | printf("\nconst u8 __attribute__((aligned(256)))\n" |
99 | "raid6_gfinv[256] =\n" | 103 | "raid6_gfinv[256] =\n" |
100 | "{\n"); | 104 | "{\n"); |
101 | for ( i = 0 ; i < 256 ; i += 8 ) { | 105 | for (i = 0; i < 256; i += 8) { |
102 | printf("\t"); | 106 | printf("\t"); |
103 | for ( j = 0 ; j < 8 ; j++ ) { | 107 | for (j = 0; j < 8; j++) { |
104 | invtbl[i+j] = v = gfpow(i+j,254); | 108 | v = gfpow(i+j, 254); |
105 | printf("0x%02x, ", v); | 109 | invtbl[i+j] = v; |
106 | } | 110 | printf("0x%02x, ", v); |
107 | printf("\n"); | 111 | } |
108 | } | 112 | printf("\n"); |
109 | printf("};\n"); | 113 | } |
110 | 114 | printf("};\n"); | |
111 | /* Compute inv(2^x + 1) (exponent-xor-inverse) table */ | 115 | |
112 | printf("\nconst u8 __attribute__((aligned(256)))\n" | 116 | /* Compute inv(2^x + 1) (exponent-xor-inverse) table */ |
113 | "raid6_gfexi[256] =\n" | 117 | printf("\nconst u8 __attribute__((aligned(256)))\n" |
114 | "{\n"); | 118 | "raid6_gfexi[256] =\n" |
115 | for ( i = 0 ; i < 256 ; i += 8 ) { | 119 | "{\n"); |
116 | printf("\t"); | 120 | for (i = 0; i < 256; i += 8) { |
117 | for ( j = 0 ; j < 8 ; j++ ) { | 121 | printf("\t"); |
118 | printf("0x%02x, ", invtbl[exptbl[i+j]^1]); | 122 | for (j = 0; j < 8; j++) |
119 | } | 123 | printf("0x%02x, ", invtbl[exptbl[i+j]^1]); |
120 | printf("\n"); | 124 | printf("\n"); |
121 | } | 125 | } |
122 | printf("};\n\n"); | 126 | printf("};\n\n"); |
123 | 127 | ||
124 | return 0; | 128 | return 0; |
125 | } | 129 | } |