forked from antonblanchard/crc32-vpmsum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_fold_test.c
93 lines (75 loc) · 1.86 KB
/
final_fold_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Test POWER8 128 bit checksum algorithms.
*
* Copyright (C) 2015 Anton Blanchard <[email protected]>, IBM
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <stdio.h>
#include <string.h>
#include "crcmodel.h"
/* CRC without the top bit */
#define CRC 0x04C11DB7
char crc_data[] __attribute__((aligned(16))) = {
0x9e, 0xd3, 0x20, 0xcc, 0x34, 0x1a, 0x50, 0x64,
0x5c, 0x73, 0x22, 0x26, 0x5c, 0x32, 0x0d, 0xad,
};
static void doit(p_cm_t p_cm, char *str)
{
int i;
for (i = 0; i < sizeof(crc_data)/sizeof(crc_data[0]); i++)
cm_nxt(p_cm, crc_data[i]);
printf("%-25s = 0x%08lx\n", str, cm_crc(p_cm));
}
#ifdef __powerpc__
unsigned int final_fold(void *data);
unsigned int final_fold_reflected(void *data);
static void do_final_fold(void)
{
unsigned int crc;
printf("final_fold\n");
crc = final_fold(crc_data);
printf("%-25s = 0x%08x\n", "Base", crc);
crc = final_fold_reflected(crc_data);
printf("%-25s = 0x%08x\n", "Reflected", crc);
printf("\n");
}
#else
static void do_final_fold(void) { }
#endif
static void do_crc(void)
{
cm_t cm_t = { 0, };
printf("CRC comparision\n");
cm_t.cm_width = 32;
cm_t.cm_poly = CRC;
cm_t.cm_init = 0x0;
cm_t.cm_refin = FALSE;
cm_t.cm_refot = FALSE;
cm_t.cm_xorot = 0x0;
cm_ini(&cm_t);
doit(&cm_t, "Base");
cm_t.cm_init = 0xffffffff;
cm_t.cm_xorot = 0xffffffff;
cm_ini(&cm_t);
doit(&cm_t, "Inverted");
cm_t.cm_init = 0x0;
cm_t.cm_xorot = 0x0;
cm_t.cm_refin = TRUE;
cm_t.cm_refot = TRUE;
cm_ini(&cm_t);
doit(&cm_t, "Reflected");
cm_t.cm_init = 0xffffffff;
cm_t.cm_xorot = 0xffffffff;
cm_ini(&cm_t);
doit(&cm_t, "Reflected and Inverted");
}
int main(void)
{
do_final_fold();
do_crc();
return 0;
}