1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
5 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2 or (at your
7 * option) any later version; incorporated herein by reference.
9 * ----------------------------------------------------------------------- */
14 * Make RAID-6 tables. This is a host user space program to be run at
19 * Btrfs-progs port, with following minor fixes:
20 * 1) Use "kerncompat.h"
21 * 2) Get rid of __KERNEL__ related macros
30 static uint8_t gfmul(uint8_t a, uint8_t b)
37 a = (a << 1) ^ (a & 0x80 ? 0x1d : 0);
44 static uint8_t gfpow(uint8_t a, int b)
62 int main(int argc, char *argv[])
66 uint8_t exptbl[256], invtbl[256];
68 printf("#include \"kerncompat.h\"\n");
70 /* Compute multiplication table */
71 printf("\nconst u8 __attribute__((aligned(256)))\n"
72 "raid6_gfmul[256][256] =\n"
74 for (i = 0; i < 256; i++) {
76 for (j = 0; j < 256; j += 8) {
78 for (k = 0; k < 8; k++)
79 printf("0x%02x,%c", gfmul(i, j + k),
80 (k == 7) ? '\n' : ' ');
86 /* Compute vector multiplication table */
87 printf("\nconst u8 __attribute__((aligned(256)))\n"
88 "raid6_vgfmul[256][32] =\n"
90 for (i = 0; i < 256; i++) {
92 for (j = 0; j < 16; j += 8) {
94 for (k = 0; k < 8; k++)
95 printf("0x%02x,%c", gfmul(i, j + k),
96 (k == 7) ? '\n' : ' ');
98 for (j = 0; j < 16; j += 8) {
100 for (k = 0; k < 8; k++)
101 printf("0x%02x,%c", gfmul(i, (j + k) << 4),
102 (k == 7) ? '\n' : ' ');
108 /* Compute power-of-2 table (exponent) */
110 printf("\nconst u8 __attribute__((aligned(256)))\n"
111 "raid6_gfexp[256] =\n" "{\n");
112 for (i = 0; i < 256; i += 8) {
114 for (j = 0; j < 8; j++) {
116 printf("0x%02x,%c", v, (j == 7) ? '\n' : ' ');
119 v = 0; /* For entry 255, not a real entry */
124 /* Compute inverse table x^-1 == x^254 */
125 printf("\nconst u8 __attribute__((aligned(256)))\n"
126 "raid6_gfinv[256] =\n" "{\n");
127 for (i = 0; i < 256; i += 8) {
129 for (j = 0; j < 8; j++) {
130 invtbl[i + j] = v = gfpow(i + j, 254);
131 printf("0x%02x,%c", v, (j == 7) ? '\n' : ' ');
136 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
137 printf("\nconst u8 __attribute__((aligned(256)))\n"
138 "raid6_gfexi[256] =\n" "{\n");
139 for (i = 0; i < 256; i += 8) {
141 for (j = 0; j < 8; j++)
142 printf("0x%02x,%c", invtbl[exptbl[i + j] ^ 1],
143 (j == 7) ? '\n' : ' ');