1 #ident "$Id: mktables.c,v 1.2 2002/12/12 22:41:27 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
4 * Copyright 2002 H. Peter Anvin - All Rights Reserved
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Bostom MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
17 * Make RAID-6 tables. This is a host user space program to be run at
27 static uint8_t gfmul(uint8_t a
, uint8_t b
)
33 a
= (a
<< 1) ^ (a
& 0x80 ? 0x1d : 0);
39 static uint8_t gfpow(uint8_t a
, int b
)
48 if ( b
& 1 ) v
= gfmul(v
,a
);
55 int main(int argc
, char *argv
[])
59 uint8_t exptbl
[256], invtbl
[256];
61 printf("#include \"raid6.h\"\n");
63 /* Compute multiplication table */
64 printf("\nconst u8 __attribute__((aligned(256)))\n"
65 "raid6_gfmul[256][256] =\n"
67 for ( i
= 0 ; i
< 256 ; i
++ ) {
69 for ( j
= 0 ; j
< 256 ; j
+= 8 ) {
71 for ( k
= 0 ; k
< 8 ; k
++ ) {
72 printf("0x%02x, ", gfmul(i
,j
+k
));
80 /* Compute power-of-2 table (exponent) */
82 printf("\nconst u8 __attribute__((aligned(256)))\n"
83 "raid6_gfexp[256] =\n"
85 for ( i
= 0 ; i
< 256 ; i
+= 8 ) {
87 for ( j
= 0 ; j
< 8 ; j
++ ) {
89 printf("0x%02x, ", v
);
91 if ( v
== 1 ) v
= 0; /* For entry 255, not a real entry */
97 /* Compute inverse table x^-1 == x^254 */
98 printf("\nconst u8 __attribute__((aligned(256)))\n"
99 "raid6_gfinv[256] =\n"
101 for ( i
= 0 ; i
< 256 ; i
+= 8 ) {
103 for ( j
= 0 ; j
< 8 ; j
++ ) {
104 invtbl
[i
+j
] = v
= gfpow(i
+j
,254);
105 printf("0x%02x, ", v
);
111 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
112 printf("\nconst u8 __attribute__((aligned(256)))\n"
113 "raid6_gfexi[256] =\n"
115 for ( i
= 0 ; i
< 256 ; i
+= 8 ) {
117 for ( j
= 0 ; j
< 8 ; j
++ ) {
118 printf("0x%02x, ", invtbl
[exptbl
[i
+j
]^1]);