| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details" } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-flto" } } */ |
| 4 |
|
| 5 |
// Test from roms/ipxe/src/util/zbin.c |
| 6 |
// We don't detect this case, as second operand of the xor is a variable. |
| 7 |
|
| 8 |
#include <stdint.h> |
| 9 |
#include <stddef.h> |
| 10 |
|
| 11 |
#define CRCPOLY 0xedb88320 |
| 12 |
#define CRCSEED 0xffffffff |
| 13 |
|
| 14 |
uint32_t crc32_le ( uint32_t crc, const void *data, size_t len ) { |
| 15 |
const uint8_t *src = data; |
| 16 |
uint32_t mult; |
| 17 |
unsigned int i; |
| 18 |
|
| 19 |
while ( len-- ) { |
| 20 |
crc ^= *(src++); |
| 21 |
for ( i = 0 ; i < 8 ; i++ ) { |
| 22 |
mult = ( ( crc & 1 ) ? CRCPOLY : 0 ); |
| 23 |
crc = ( ( crc >> 1 ) ^ mult ); |
| 24 |
} |
| 25 |
} |
| 26 |
return crc; |
| 27 |
} |