| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-w -fdump-tree-crc-details" } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ |
| 4 |
|
| 5 |
/* Test from busybox, we don't verify as it depends on endian variable. */ |
| 6 |
#include <stdint.h> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
uint32_t* crc32_filltable(uint32_t *crc_table, int endian) |
| 10 |
{ |
| 11 |
uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; |
| 12 |
uint32_t c; |
| 13 |
unsigned i, j; |
| 14 |
|
| 15 |
if (!crc_table) |
| 16 |
crc_table = malloc (256 * sizeof (uint32_t)); |
| 17 |
|
| 18 |
for (i = 0; i < 256; i++) |
| 19 |
{ |
| 20 |
c = endian ? (i << 24) : i; |
| 21 |
for (j = 8; j; j--) |
| 22 |
{ |
| 23 |
if (endian) |
| 24 |
c = (c & 0x80000000) ? ((c << 1) ^ polynomial) : (c << 1); |
| 25 |
else |
| 26 |
c = (c & 1) ? ((c >> 1) ^ polynomial) : (c >> 1); |
| 27 |
} |
| 28 |
*crc_table++ = c; |
| 29 |
} |
| 30 |
|
| 31 |
return crc_table - 256; |
| 32 |
} |