| 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-sam460ex/drivers/net/mpc512x_fec.c(fsl_mcdmafec.c) |
| 7 |
|
| 8 |
#include <stdint.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
typedef uint8_t u8; |
| 12 |
typedef uint32_t u32; |
| 13 |
|
| 14 |
__attribute__ ((noinline,optimize(0))) |
| 15 |
u32 mpc512x_fec_set_hwaddr_O0 (unsigned char *mac) |
| 16 |
{ |
| 17 |
u8 currByte; /* byte for which to compute the CRC */ |
| 18 |
int byte; /* loop - counter */ |
| 19 |
int bit; /* loop - counter */ |
| 20 |
u32 crc = 0xffffffff; /* initial value */ |
| 21 |
|
| 22 |
for (byte = 0; byte < 6; byte++) { |
| 23 |
currByte = mac[byte]; |
| 24 |
for (bit = 0; bit < 8; bit++) { |
| 25 |
if ((currByte & 0x01) ^ (crc & 0x01)) { |
| 26 |
crc >>= 1; |
| 27 |
crc = crc ^ 0xedb88320; |
| 28 |
} else { |
| 29 |
crc >>= 1; |
| 30 |
} |
| 31 |
currByte >>= 1; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
crc = crc >> 26; |
| 36 |
return crc; |
| 37 |
} |
| 38 |
|
| 39 |
u32 mpc512x_fec_set_hwaddr (unsigned char *mac) |
| 40 |
{ |
| 41 |
u8 currByte; /* byte for which to compute the CRC */ |
| 42 |
int byte; /* loop - counter */ |
| 43 |
int bit; /* loop - counter */ |
| 44 |
u32 crc = 0xffffffff; /* initial value */ |
| 45 |
|
| 46 |
for (byte = 0; byte < 6; byte++) { |
| 47 |
currByte = mac[byte]; |
| 48 |
for (bit = 0; bit < 8; bit++) { |
| 49 |
if ((currByte & 0x01) ^ (crc & 0x01)) { |
| 50 |
crc >>= 1; |
| 51 |
crc = crc ^ 0xedb88320; |
| 52 |
} else { |
| 53 |
crc >>= 1; |
| 54 |
} |
| 55 |
currByte >>= 1; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
crc = crc >> 26; |
| 60 |
return crc; |
| 61 |
} |
| 62 |
|
| 63 |
int main () |
| 64 |
{ |
| 65 |
unsigned char st[6] = "Hello"; |
| 66 |
for (unsigned char i = 0; i < 255; i++) |
| 67 |
{ |
| 68 |
st[0] = i; |
| 69 |
u32 res1 = mpc512x_fec_set_hwaddr_O0 (st); |
| 70 |
u32 res2 = mpc512x_fec_set_hwaddr (st); |
| 71 |
if (res1 != res2) |
| 72 |
__builtin_abort (); |
| 73 |
} |
| 74 |
__builtin_exit (0); |
| 75 |
} |
| 76 |
/* { dg-final { scan-tree-dump "function maybe contains CRC calculation." "crc" } } */ |
| 77 |
/* { dg-final { scan-tree-dump "Loop iteration number is 7" "crc"} } */ |
| 78 |
/* { dg-final { scan-tree-dump "Bit reversed" "crc"} } */ |
| 79 |
/* { dg-final { scan-tree-dump "calculates CRC!" "crc"} } */ |
| 80 |
/* { dg-final { scan-tree-dump-times "Couldn't generate faster CRC code." 0 "crc"} } */ |