PandA-2024.02
examples
crc
spec.c
Go to the documentation of this file.
1
/******* PowerStone Benchmark *******/
2
3
#include <math.h>
4
#include <stdio.h>
5
6
typedef
unsigned
char
uchar
;
7
#define LOBYTE(x) ((uchar)((x) & 0xFF))
8
#define HIBYTE(x) ((uchar)((x) >> 8))
9
10
unsigned
char
aa
[] =
"asdffeagewaHAFEFaeDsFEawFdsFaefaeerdjgpim23"
;
11
12
unsigned
short
icrc1
(
unsigned
short
crc,
unsigned
char
onech)
13
{
14
int
i;
15
unsigned
short
ans=(crc^onech << 8);
16
17
for
(i=0;i<8;i++) {
18
if
(ans & 0x8000)
19
ans = (ans << 1) ^ 4129;
20
else
21
ans <<= 1;
22
}
23
return
ans;
24
}
25
26
unsigned
short
icrc
(
unsigned
short
crc,
unsigned
char
*lin,
unsigned
int
len,
27
short
jinit,
int
jrev)
28
{
29
unsigned
short
icrc1
(
unsigned
short
crc,
unsigned
char
onech);
30
static
unsigned
short
icrctb[256],
init
=0;
31
static
uchar
rchr[256];
32
unsigned
short
tmp1, tmp2, j,cword=crc;
33
static
uchar
it[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
34
35
if
(!init) {
36
init=1;
37
for
(j=0;j<=255;j++) {
38
icrctb[j]=
icrc1
(j << 8,(
uchar
)0);
39
rchr[j]=(
uchar
)(it[j & 0xF] << 4 | it[j >> 4]);
40
}
41
}
42
if
(jinit >= 0) cword=((
uchar
) jinit) | (((
uchar
) jinit) << 8);
43
else
if
(jrev < 0)
44
cword=rchr[
HIBYTE
(cword)] | rchr[
LOBYTE
(cword)] << 8;
45
for
(j=1;j<=len;j++) {
46
if
(jrev < 0) {
47
tmp1 = rchr[lin[j]]^
HIBYTE
(cword);
48
}
49
else
{
50
tmp1 = lin[j]^
HIBYTE
(cword);
51
}
52
cword = icrctb[tmp1] ^
LOBYTE
(cword) << 8;
53
}
54
if
(jrev >= 0) {
55
tmp2 = cword;
56
}
57
else
{
58
tmp2 = rchr[
HIBYTE
(cword)] | rchr[
LOBYTE
(cword)] << 8;
59
}
60
return
(tmp2 );
61
}
62
63
int
main
(
void
)
64
{
65
unsigned
short
i1,i2;
66
67
i1=
icrc
(0,
aa
,40,(
short
)0,1);
68
i2=
icrc
(i1,
aa
,42,(
short
)-1,1);
69
if
(i2 != 268) {
70
return
1;
71
}
72
else
{
73
return
0;
74
}
75
}
uchar
unsigned char uchar
Definition:
spec.c:6
icrc
unsigned short icrc(unsigned short crc, unsigned char *lin, unsigned int len, short jinit, int jrev)
Definition:
spec.c:26
icrc1
unsigned short icrc1(unsigned short crc, unsigned char onech)
Definition:
spec.c:12
HIBYTE
#define HIBYTE(x)
Definition:
spec.c:8
main
int main(void)
Definition:
spec.c:63
init
void init(int bucket[BUCKETSIZE])
Definition:
sort.c:42
aa
unsigned char aa[]
Definition:
spec.c:10
LOBYTE
#define LOBYTE(x)
Definition:
spec.c:7
Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by
1.8.13