struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / shifts2.c.in
blobca1a3cecb07826672ed7d689d86468cee1a870ec
1 /** extended tests for shift operations, added by
2 Frieder Ferlemann to check for bugs related to bug 1533966
4 size: 8,16,32,64
5 right: 0,1
6 vol: 0,1
7 sign: u,
8 goal: 0, 1, 2
9 */
10 #include <testfwk.h>
11 #ifdef __sun__
12 # include <inttypes.h>
13 #else
14 # include <stdint.h>
15 #endif
17 #define SIZE ({size})
18 #define RIGHT ({right})
19 #define VOL ({vol})
20 #define GOAL ({goal})
22 #if SIZE == 8
23 # define TYPE {sign}int8_t
24 # define TEST_VECT 0xa4
25 #endif
27 #if SIZE == 16
28 # define TYPE {sign}int16_t
29 # define TEST_VECT 0xa8ce
30 #endif
32 #if SIZE == 32
33 # define TYPE {sign}int32_t
34 # define TEST_VECT 0xa8b5c4d6
35 #endif
37 #if SIZE == 64
38 # define TYPE {sign}int64_t
39 # define TEST_VECT 0x8091a2b3c4d5e6f7
40 #endif
42 #if RIGHT == 0
43 # define SHIFT(x,y) (TYPE)((TYPE)(x)<<(y))
44 #else
45 # define SHIFT(x,y) (TYPE)((TYPE)(x)>>(y))
46 #endif
48 #if GOAL == 1
49 #pragma opt_code_size
50 #elif GOAL == 2
51 #pragma opt_code_speed
52 #endif
54 #if VOL == 0
55 volatile TYPE s = TEST_VECT;
56 TYPE t;
57 #define TESTSHIFT(x) t=s; t = SHIFT (t,(x)); ASSERT( t == SHIFT (TEST_VECT, (x)));
58 #else
59 volatile TYPE t = TEST_VECT;
60 #define TESTSHIFT(x) t=TEST_VECT; t = SHIFT (t,(x)); ASSERT( t == SHIFT (TEST_VECT, (x)));
61 #endif
63 static void
64 testShift(void)
66 #ifndef __SDCC_pdk14 // Lack of memory
67 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
68 TESTSHIFT(0);
69 TESTSHIFT(1);
70 TESTSHIFT(2);
71 TESTSHIFT(3);
72 TESTSHIFT(4);
73 TESTSHIFT(5);
74 TESTSHIFT(6);
75 TESTSHIFT(7);
77 #if SIZE >= 16
78 TESTSHIFT(8);
79 TESTSHIFT(9);
80 TESTSHIFT(10);
81 TESTSHIFT(11);
82 TESTSHIFT(12);
83 TESTSHIFT(13);
84 TESTSHIFT(14);
85 TESTSHIFT(15);
86 #endif
88 #if !defined (__SDCC_pdk15) // Lack of code memory
89 #if SIZE >= 32
90 TESTSHIFT(16);
91 TESTSHIFT(17);
92 TESTSHIFT(18);
93 TESTSHIFT(19);
94 TESTSHIFT(20);
95 TESTSHIFT(21);
96 TESTSHIFT(22);
97 TESTSHIFT(23);
99 TESTSHIFT(24);
100 TESTSHIFT(25);
101 TESTSHIFT(26);
102 TESTSHIFT(27);
103 TESTSHIFT(28);
104 TESTSHIFT(29);
105 TESTSHIFT(30);
106 TESTSHIFT(31);
107 #endif
109 #if !(defined (__SDCC_mcs51) && (defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM))) // Lack of code memory
110 #if SIZE >= 48
111 TESTSHIFT(32);
112 TESTSHIFT(33);
113 TESTSHIFT(34);
114 TESTSHIFT(35);
115 TESTSHIFT(36);
116 TESTSHIFT(37);
117 TESTSHIFT(38);
118 TESTSHIFT(39);
120 TESTSHIFT(40);
121 TESTSHIFT(41);
122 TESTSHIFT(42);
123 TESTSHIFT(43);
124 TESTSHIFT(44);
125 TESTSHIFT(45);
126 TESTSHIFT(46);
127 TESTSHIFT(47);
128 #endif
130 #if SIZE >= 56
131 TESTSHIFT(48);
132 TESTSHIFT(49);
133 TESTSHIFT(50);
134 TESTSHIFT(51);
135 TESTSHIFT(52);
136 TESTSHIFT(53);
137 TESTSHIFT(54);
138 TESTSHIFT(55);
139 #endif
140 #endif
141 #endif
142 #endif
143 #endif