| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-fdump-tree-crc-details" } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-g" "-Os" "-funroll-loops" "-fpeel-loops" "-flto" } } */ |
| 4 |
/* { dg-require-effective-target int32plus } */ |
| 5 |
|
| 6 |
// Test from roms/u-boot/drivers/ram/octeon/dimm_spd_eeprom.c |
| 7 |
|
| 8 |
#include <stdint.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
typedef uint8_t u8; |
| 12 |
typedef uint16_t u16; |
| 13 |
|
| 14 |
// We don't verify as crc is of type int (32 bit), |
| 15 |
// but the polynomial fits into 16 bit. |
| 16 |
u16 ddr3_crc16_orig (u8 *ptr, int count) |
| 17 |
{ |
| 18 |
/* From DDR3 SPD specification */ |
| 19 |
int crc, i; |
| 20 |
|
| 21 |
crc = 0; |
| 22 |
while (--count >= 0) { |
| 23 |
crc = crc ^ (int)*ptr++ << 8; |
| 24 |
for (i = 0; i < 8; ++i) { |
| 25 |
if (crc & 0x8000) |
| 26 |
crc = crc << 1 ^ 0x1021; |
| 27 |
else |
| 28 |
crc = crc << 1; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
return (crc & 0xFFFF); |
| 33 |
} |
| 34 |
|
| 35 |
__attribute__ ((noinline,optimize(0))) |
| 36 |
u16 ddr3_crc16_modified_O0 (u8 *ptr, int count) |
| 37 |
{ |
| 38 |
/* From DDR3 SPD specification */ |
| 39 |
u16 crc, i; |
| 40 |
|
| 41 |
crc = 0; |
| 42 |
while (--count >= 0) { |
| 43 |
crc = crc ^ (int)*ptr++ << 8; |
| 44 |
for (i = 0; i < 8; ++i) { |
| 45 |
if (crc & 0x8000) |
| 46 |
crc = crc << 1 ^ 0x1021; |
| 47 |
else |
| 48 |
crc = crc << 1; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return (crc & 0xFFFF); |
| 53 |
} |
| 54 |
|
| 55 |
u16 ddr3_crc16_modified (u8 *ptr, int count) |
| 56 |
{ |
| 57 |
/* From DDR3 SPD specification */ |
| 58 |
u16 crc, i; |
| 59 |
|
| 60 |
crc = 0; |
| 61 |
while (--count >= 0) { |
| 62 |
crc = crc ^ (int)*ptr++ << 8; |
| 63 |
for (i = 0; i < 8; ++i) { |
| 64 |
if (crc & 0x8000) |
| 65 |
crc = crc << 1 ^ 0x1021; |
| 66 |
else |
| 67 |
crc = crc << 1; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
return (crc & 0xFFFF); |
| 72 |
} |
| 73 |
|
| 74 |
int main () |
| 75 |
{ |
| 76 |
u8 st[2] = {'H', 'i'}; |
| 77 |
for (u8 i = 0; i < 255; i++) |
| 78 |
{ |
| 79 |
st[0] = i; |
| 80 |
u16 res1 = ddr3_crc16_modified_O0 (st, 2); |
| 81 |
u16 res2 = ddr3_crc16_modified (st, 2); |
| 82 |
if (res1 != res2) |
| 83 |
__builtin_abort (); |
| 84 |
} |
| 85 |
__builtin_exit (0); |
| 86 |
} |
| 87 |
|
| 88 |
/* { dg-final { scan-tree-dump "function maybe contains CRC calculation." "crc"} } */ |
| 89 |
/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc"} } */ |
| 90 |
/* { dg-final { scan-tree-dump "Bit forward" "crc"} } */ |
| 91 |
/* { dg-final { scan-tree-dump "calculates CRC!" "crc"} } */ |
| 92 |
/* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */ |