IMUL: fix an additional incorrect sbyte use
[nasm/avx512.git] / misc / xcrcgen.c
blobacfd48e010128974bf3ea279e13070f2fe5882cd
1 /*
2 * Produce a "generalized CRC" table. Assumes a platform with
3 * /dev/urandom -- otherwise reimplement get_random_byte().
4 */
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <inttypes.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
14 static uint8_t get_random_byte(void)
16 static int fd = -1;
17 uint8_t buf;
18 int rv;
20 if (fd < 0)
21 fd = open("/dev/urandom", O_RDONLY);
23 do {
24 errno = 0;
25 rv = read(fd, &buf, 1);
26 if (rv < 1 && errno != EAGAIN)
27 abort();
28 } while (rv < 1);
30 return buf;
33 static void random_permute(uint8_t *buf)
35 int i, j, k;
36 int m;
38 for (i = 0; i < 256; i++)
39 buf[i] = i;
41 m = 255;
42 for (i = 255; i > 0; i--) {
43 if (i <= (m >> 1))
44 m >>= 1;
45 do {
46 j = get_random_byte() & m;
47 } while (j > i);
48 k = buf[i];
49 buf[i] = buf[j];
50 buf[j] = k;
54 static void xcrc_table(uint64_t *buf)
56 uint8_t perm[256];
57 int i, j;
59 memset(buf, 0, 8*256); /* Make static checkers happy */
61 for (i = 0; i < 8; i++) {
62 random_permute(perm);
63 for (j = 0; j < 256; j++)
64 buf[j] = (buf[j] << 8) | perm[j];
68 int main(void)
70 int i;
71 uint64_t buf[256];
73 xcrc_table(buf);
75 for (i = 0; i < 256; i++) {
76 printf("%016"PRIx64"\n", buf[i]);
79 return 0;