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
94
95
96
97
98
99
100
101
102
103
104
|
/* This tests the rotate patterns that some machines support. */
#include <limits.h>
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
#define ROR(a,b) (((a) >> (b)) | ((a) << ((sizeof (a) * CHAR_BIT) - (b))))
#define ROL(a,b) (((a) << (b)) | ((a) >> ((sizeof (a) * CHAR_BIT) - (b))))
#define CHAR_VALUE ((unsigned char)0x1234U)
#define SHORT_VALUE ((unsigned short)0x1234U)
#define INT_VALUE 0x1234U
#define LONG_VALUE 0x12345678LU
#define LL_VALUE 0x12345678abcdef0LLU
#define SHIFT1 4
#define SHIFT2 ((sizeof (long long) * CHAR_BIT) - SHIFT1)
unsigned char uc = CHAR_VALUE;
unsigned short us = SHORT_VALUE;
unsigned int ui = INT_VALUE;
unsigned long ul = LONG_VALUE;
unsigned long long ull = LL_VALUE;
int shift1 = SHIFT1;
int shift2 = SHIFT2;
main ()
{
if (ROR (uc, shift1) != ROR (CHAR_VALUE, SHIFT1))
abort ();
if (ROR (uc, SHIFT1) != ROR (CHAR_VALUE, SHIFT1))
abort ();
if (ROR (us, shift1) != ROR (SHORT_VALUE, SHIFT1))
abort ();
if (ROR (us, SHIFT1) != ROR (SHORT_VALUE, SHIFT1))
abort ();
if (ROR (ui, shift1) != ROR (INT_VALUE, SHIFT1))
abort ();
if (ROR (ui, SHIFT1) != ROR (INT_VALUE, SHIFT1))
abort ();
if (ROR (ul, shift1) != ROR (LONG_VALUE, SHIFT1))
abort ();
if (ROR (ul, SHIFT1) != ROR (LONG_VALUE, SHIFT1))
abort ();
if (ROR (ull, shift1) != ROR (LL_VALUE, SHIFT1))
abort ();
if (ROR (ull, SHIFT1) != ROR (LL_VALUE, SHIFT1))
abort ();
if (ROR (ull, shift2) != ROR (LL_VALUE, SHIFT2))
abort ();
if (ROR (ull, SHIFT2) != ROR (LL_VALUE, SHIFT2))
abort ();
if (ROL (uc, shift1) != ROL (CHAR_VALUE, SHIFT1))
abort ();
if (ROL (uc, SHIFT1) != ROL (CHAR_VALUE, SHIFT1))
abort ();
if (ROL (us, shift1) != ROL (SHORT_VALUE, SHIFT1))
abort ();
if (ROL (us, SHIFT1) != ROL (SHORT_VALUE, SHIFT1))
abort ();
if (ROL (ui, shift1) != ROL (INT_VALUE, SHIFT1))
abort ();
if (ROL (ui, SHIFT1) != ROL (INT_VALUE, SHIFT1))
abort ();
if (ROL (ul, shift1) != ROL (LONG_VALUE, SHIFT1))
abort ();
if (ROL (ul, SHIFT1) != ROL (LONG_VALUE, SHIFT1))
abort ();
if (ROL (ull, shift1) != ROL (LL_VALUE, SHIFT1))
abort ();
if (ROL (ull, SHIFT1) != ROL (LL_VALUE, SHIFT1))
abort ();
if (ROL (ull, shift2) != ROL (LL_VALUE, SHIFT2))
abort ();
if (ROL (ull, SHIFT2) != ROL (LL_VALUE, SHIFT2))
abort ();
exit (0);
}
|