1 /** Tests covering RRC, RLC & SWAP operations
24 #define AND_CASE ({andCase})
25 #define XOR_LITERAL ({xorLiteral})
26 #define ROTATE_LEFT ({rotateLeft})
27 #define STRUCT_VAR ({structVar})
31 #define TEST_VALUE 0x5B
33 #define AND_VALUE 0xFE
35 #define AND_VALUE 0xEF
43 #define TEST_VALUE 0x3579
45 #define AND_VALUE 0xFEFF
47 #define AND_VALUE 0xFFEF
55 #define TEST_VALUE 0x13579BDF
57 #define AND_VALUE 0xFEFFFEFF
59 #define AND_VALUE 0xFFEFFFEF
66 #define SHIFT_R (SIZE - 1)
69 #elif ROTATE_LEFT == -1
71 #define SHIFT_L (SIZE - 1)
72 #elif ROTATE_LEFT == 0
73 #define SHIFT_R (SIZE / 2)
74 #define SHIFT_L (SIZE / 2)
76 #error "UNKNOWN SHIFT CASE"
80 #define AND_OPERATION & AND_VALUE
85 #define XOR_VALUE 0x24
88 #define rotate_test_value_xor XOR_VALUE
90 volatile TYPE rotate_test_value_xor
= XOR_VALUE
;
93 #define ROTATE_RESULT ((TYPE)(((TEST_VALUE << SHIFT_L) | (TEST_VALUE >> SHIFT_R)) AND_OPERATION))
94 #define ROTATE_RESULT_XOR ((TYPE)((((TEST_VALUE ^ XOR_VALUE) << SHIFT_L) | ((TEST_VALUE ^ XOR_VALUE) >> SHIFT_R)) AND_OPERATION))
99 TYPE rotate_test_value1
;
100 TYPE rotate_test_value2
;
101 }rotate_test_struct_
;
103 rotate_test_struct_ rotate_test_struct
;
104 #define rotate_test_value rotate_test_struct.rotate_test_value2
106 TYPE rotate_test_value
;
109 TYPE
rotate_test_1(TYPE value
)
111 return ((value
<< SHIFT_L
) | (value
>> SHIFT_R
)) AND_OPERATION
;
114 TYPE
rotate_test_1_xor1(TYPE value
)
116 value
= value
^ rotate_test_value_xor
;
117 return ((value
<< SHIFT_L
) | (value
>> SHIFT_R
)) AND_OPERATION
;
120 TYPE
rotate_test_1_xor2(TYPE value
)
122 return (((value
^ rotate_test_value_xor
) << SHIFT_L
) | ((value
^ rotate_test_value_xor
) >> SHIFT_R
)) AND_OPERATION
;
125 #if !(defined(__SDCC_pdk14) || defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of memory
127 TYPE
rotate_test_2(TYPE value
)
130 return ((value2
<< SHIFT_L
) | (value2
>> SHIFT_R
)) AND_OPERATION
;
133 TYPE
rotate_test_2_xor1(TYPE value
)
135 TYPE value2
= value
^ rotate_test_value_xor
;
136 return ((value2
<< SHIFT_L
) | (value2
>> SHIFT_R
)) AND_OPERATION
;
139 TYPE
rotate_test_2_xor2(TYPE value
)
142 return (((value2
^ rotate_test_value_xor
) << SHIFT_L
) | ((value2
^ rotate_test_value_xor
) >> SHIFT_R
)) AND_OPERATION
;
145 TYPE
rotate_test_3(TYPE value
)
147 volatile TYPE value2
= value
;
148 value2
= ((value2
<< SHIFT_L
) | (value2
>> SHIFT_R
)) AND_OPERATION
;
152 TYPE
rotate_test_3_xor1(TYPE value
)
154 volatile TYPE value2
= value
^ rotate_test_value_xor
;
155 value2
= ((value2
<< SHIFT_L
) | (value2
>> SHIFT_R
)) AND_OPERATION
;
159 TYPE
rotate_test_3_xor2(TYPE value
)
161 volatile TYPE value2
= value
;
162 value2
= (((value2
^ rotate_test_value_xor
) << SHIFT_L
) | ((value2
^ rotate_test_value_xor
) >> SHIFT_R
)) AND_OPERATION
;
166 #ifndef __SDCC_pdk15 // Lack of memory
168 TYPE
rotate_test_4(TYPE value
)
170 rotate_test_value
= value
;
171 rotate_test_value
= ((rotate_test_value
<< SHIFT_L
) | (rotate_test_value
>> SHIFT_R
)) AND_OPERATION
;
172 return rotate_test_value
;
175 TYPE
rotate_test_4_xor1(TYPE value
)
177 rotate_test_value
= value
^ rotate_test_value_xor
;
178 rotate_test_value
= ((rotate_test_value
<< SHIFT_L
) | (rotate_test_value
>> SHIFT_R
)) AND_OPERATION
;
179 return rotate_test_value
;
182 TYPE
rotate_test_4_xor2(TYPE value
)
184 rotate_test_value
= value
;
185 rotate_test_value
= (((rotate_test_value
^ rotate_test_value_xor
) << SHIFT_L
) | ((rotate_test_value
^ rotate_test_value_xor
) >> SHIFT_R
)) AND_OPERATION
;
186 return rotate_test_value
;
189 void rotate_test_load(TYPE value
)
191 rotate_test_value
= value
;
194 TYPE
rotate_test_5(TYPE value
)
196 rotate_test_load (value
);
197 rotate_test_value
= ((rotate_test_value
<< SHIFT_L
) | (rotate_test_value
>> SHIFT_R
)) AND_OPERATION
;
198 return rotate_test_value
;
201 TYPE
rotate_test_5_xor1(TYPE value
)
203 rotate_test_load (value
^ rotate_test_value_xor
);
204 rotate_test_value
= ((rotate_test_value
<< SHIFT_L
) | (rotate_test_value
>> SHIFT_R
)) AND_OPERATION
;
205 return rotate_test_value
;
208 TYPE
rotate_test_5_xor2(TYPE value
)
210 rotate_test_load (value
);
211 rotate_test_value
= (((rotate_test_value
^ rotate_test_value_xor
) << SHIFT_L
) | ((rotate_test_value
^ rotate_test_value_xor
) >> SHIFT_R
)) AND_OPERATION
;
212 return rotate_test_value
;
220 #if !(defined(__SDCC_pdk14) || defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of memory
221 volatile TYPE t
= TEST_VALUE
;
226 ASSERT( rotate_test_1(u
) == ROTATE_RESULT
);
227 ASSERT( rotate_test_1_xor1(u
) == ROTATE_RESULT_XOR
);
228 ASSERT( rotate_test_1_xor2(u
) == ROTATE_RESULT_XOR
);
230 ASSERT( rotate_test_2(u
) == ROTATE_RESULT
);
231 ASSERT( rotate_test_2_xor1(u
) == ROTATE_RESULT_XOR
);
232 ASSERT( rotate_test_2_xor2(u
) == ROTATE_RESULT_XOR
);
234 ASSERT( rotate_test_3(u
) == ROTATE_RESULT
);
235 ASSERT( rotate_test_3_xor1(u
) == ROTATE_RESULT_XOR
);
236 ASSERT( rotate_test_3_xor2(u
) == ROTATE_RESULT_XOR
);
238 #ifndef __SDCC_pdk15 // Lack of memory
239 ASSERT( rotate_test_4(u
) == ROTATE_RESULT
);
240 ASSERT( rotate_test_4_xor1(u
) == ROTATE_RESULT_XOR
);
241 ASSERT( rotate_test_4_xor2(u
) == ROTATE_RESULT_XOR
);
243 ASSERT( rotate_test_5(u
) == ROTATE_RESULT
);
244 ASSERT( rotate_test_5_xor1(u
) == ROTATE_RESULT_XOR
);
245 ASSERT( rotate_test_5_xor2(u
) == ROTATE_RESULT_XOR
);