-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcrc32-cli.c
51 lines (42 loc) · 1.17 KB
/
crc32-cli.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
/*
* A simple command-line program to exercise the hardware-
* accelerated CRC-32 algorithms.
*
* Copyright IBM Corp. 2016
* Author(s): Chris Zou <chriszou@ca.ibm.com>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "crc32-s390x.h"
int main(int argc, char *argv[]) {
unsigned long length;
unsigned long i;
unsigned int initial_value;
unsigned char *data;
unsigned int crcle, crcbe, crccbe, crccle;
if (argc != 3) {
fprintf(stderr, "Usage: %s initial_value length\n", argv[0]);
exit(1);
}
initial_value = strtoul(argv[1], NULL, 0);
length = strtoul(argv[2], NULL, 0);
data = memalign(16, length);
if (!data) {
perror("memalign");
exit(1);
}
srandom(1);
for (i = 0; i < length; i++)
data[i] = random() & 0xff;
crcbe = crc32_be_vx(initial_value, data, length);
crcle = crc32_le_vx(initial_value, data, length);
crccbe = crc32c_be_vx(initial_value, data, length);
crccle = crc32c_le_vx(initial_value, data, length);
printf("IEEE big-endian CRC: %08x\n", crcbe);
printf("IEEE little-endian CRC: %08x\n", crcle);
printf("Castagnoli big-endian CRC: %08x\n", crccbe);
printf("Castagnoli little-endian CRC: %08x\n", crccle);
return 0;
}