struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / rotate.c.in
blob0a3954040c5cc12c59516758964d8d72dac5b19f
1 /** Tests covering rotate operations
2 size: 8,16,32
3 msb: 0,1
4 */
5 #include <testfwk.h>
6 #ifdef __sun__
7 #include <inttypes.h>
8 #else
9 #include <stdint.h>
10 #endif
12 #ifndef __SDCC_pdk14 // Lack of memory
13 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
15 #define SIZE ({size})
16 #define MSB ({msb})
18 #if SIZE == 8
19 # define TYPE uint8_t
20 # if MSB
21 # define TEST_VECT 0xa4
22 # else
23 # define TEST_VECT 0x53
24 # endif
25 #endif
27 #if SIZE == 16
28 # define TYPE uint16_t
29 # if MSB
30 # define TEST_VECT 0xa8ce
31 # else
32 # define TEST_VECT 0x5357
33 # endif
34 #endif
36 #if SIZE == 32
37 # define TYPE uint32_t
38 # if MSB
39 # define TEST_VECT 0xa8c5a5c6
40 # else
41 # define TEST_VECT 0x55357553
42 # endif
43 #endif
45 #if SIZE == 64
46 # define TYPE uint64_t
47 # if MSB
48 # define TEST_VECT 0xa8c5a5c655357553
49 # else
50 # define TEST_VECT 0x55357553a8c5a5c6
51 # endif
52 #endif
54 TYPE rol1(TYPE s){ return (s<<1) | (s>>(SIZE-1)); }
55 TYPE rol2(TYPE s){ return (s<<2) | (s>>(SIZE-2)); }
56 TYPE rol3(TYPE s){ return (s<<3) | (s>>(SIZE-3)); }
57 TYPE rol4(TYPE s){ return (s<<4) | (s>>(SIZE-4)); }
58 TYPE rol5(TYPE s){ return (s<<5) | (s>>(SIZE-5)); }
59 TYPE rol6(TYPE s){ return (s<<6) | (s>>(SIZE-6)); }
60 TYPE rol7(TYPE s){ return (s<<7) | (s>>(SIZE-7)); }
62 #if SIZE >=16
63 TYPE rol8 (TYPE s){ return (s<<8 ) | (s>>(SIZE-8 )); }
64 TYPE rol9 (TYPE s){ return (s<<9 ) | (s>>(SIZE-9 )); }
65 TYPE rol10(TYPE s){ return (s<<10) | (s>>(SIZE-10)); }
66 TYPE rol11(TYPE s){ return (s<<11) | (s>>(SIZE-11)); }
67 TYPE rol12(TYPE s){ return (s<<12) | (s>>(SIZE-12)); }
68 TYPE rol13(TYPE s){ return (s<<13) | (s>>(SIZE-13)); }
69 TYPE rol14(TYPE s){ return (s<<14) | (s>>(SIZE-14)); }
70 TYPE rol15(TYPE s){ return (s<<15) | (s>>(SIZE-15)); }
71 #endif
73 #if SIZE >=32
74 TYPE rol16(TYPE s){ return (s<<16) | (s>>(SIZE-16)); }
75 TYPE rol17(TYPE s){ return (s<<17) | (s>>(SIZE-17)); }
77 TYPE rol23(TYPE s){ return (s<<23) | (s>>(SIZE-23)); }
78 TYPE rol24(TYPE s){ return (s<<24) | (s>>(SIZE-24)); }
79 TYPE rol25(TYPE s){ return (s<<25) | (s>>(SIZE-25)); }
81 TYPE rol30(TYPE s){ return (s<<30) | (s>>(SIZE-30)); }
82 TYPE rol31(TYPE s){ return (s<<31) | (s>>(SIZE-31)); }
83 #endif
84 #endif
85 #endif
87 void
88 testRol(void)
90 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
91 volatile TYPE t = TEST_VECT;
92 TYPE u;
94 u = t;
96 ASSERT( rol1(u) == (TYPE)((TEST_VECT<<1) | (TEST_VECT>>(SIZE-1))) );
97 ASSERT( rol2(u) == (TYPE)((TEST_VECT<<2) | (TEST_VECT>>(SIZE-2))) );
98 ASSERT( rol3(u) == (TYPE)((TEST_VECT<<3) | (TEST_VECT>>(SIZE-3))) );
99 ASSERT( rol4(u) == (TYPE)((TEST_VECT<<4) | (TEST_VECT>>(SIZE-4))) );
100 ASSERT( rol5(u) == (TYPE)((TEST_VECT<<5) | (TEST_VECT>>(SIZE-5))) );
101 ASSERT( rol6(u) == (TYPE)((TEST_VECT<<6) | (TEST_VECT>>(SIZE-6))) );
102 ASSERT( rol7(u) == (TYPE)((TEST_VECT<<7) | (TEST_VECT>>(SIZE-7))) );
104 #if SIZE >=16
105 ASSERT( rol8 (u) == (TYPE)((TEST_VECT<<8 ) | (TEST_VECT>>(SIZE-8 ))) );
106 ASSERT( rol9 (u) == (TYPE)((TEST_VECT<<9 ) | (TEST_VECT>>(SIZE-9 ))) );
107 ASSERT( rol10(u) == (TYPE)((TEST_VECT<<10) | (TEST_VECT>>(SIZE-10))) );
108 ASSERT( rol11(u) == (TYPE)((TEST_VECT<<11) | (TEST_VECT>>(SIZE-11))) );
109 ASSERT( rol12(u) == (TYPE)((TEST_VECT<<12) | (TEST_VECT>>(SIZE-12))) );
110 ASSERT( rol13(u) == (TYPE)((TEST_VECT<<13) | (TEST_VECT>>(SIZE-13))) );
111 ASSERT( rol14(u) == (TYPE)((TEST_VECT<<14) | (TEST_VECT>>(SIZE-14))) );
112 ASSERT( rol15(u) == (TYPE)((TEST_VECT<<15) | (TEST_VECT>>(SIZE-15))) );
113 #endif
115 #if SIZE >=32
116 ASSERT( rol16(u) == (TYPE)((TEST_VECT<<16) | (TEST_VECT>>(SIZE-16))) );
117 ASSERT( rol17(u) == (TYPE)((TEST_VECT<<17) | (TEST_VECT>>(SIZE-17))) );
119 ASSERT( rol23(u) == (TYPE)((TEST_VECT<<23) | (TEST_VECT>>(SIZE-23))) );
120 ASSERT( rol24(u) == (TYPE)((TEST_VECT<<24) | (TEST_VECT>>(SIZE-24))) );
121 ASSERT( rol25(u) == (TYPE)((TEST_VECT<<25) | (TEST_VECT>>(SIZE-25))) );
123 ASSERT( rol30(u) == (TYPE)((TEST_VECT<<30) | (TEST_VECT>>(SIZE-30))) );
124 ASSERT( rol31(u) == (TYPE)((TEST_VECT<<31) | (TEST_VECT>>(SIZE-31))) );
125 #endif
126 #endif