1 /** Operations with 4bit-sized bitfields
2 operation: 0, 1, 2, 3, 4
4 varType: 0, 1, 2, 3, 4, 5, 6
7 // Uncomment this line to run the full test
10 #pragma disable_warning 88 // cast of LITERAL value to 'generic' pointer
12 // Absolute addressing has some issues for pdk. And if those are fixed, there might be a lack of memory, still.
13 #if defined(__SDCC_pdk14) || defined(__SDCC_pdk15)
26 #define OPERATION ({operation})
27 #define PATTERN ({pattern})
28 #define VAR_TYPE ({varType})
30 #define OPERATION_ASSING 0
31 #define OPERATION_OR 1
32 #define OPERATION_AND 2
33 #define OPERATION_XOR 3
34 #define OPERATION_COM 4
39 unsigned int high
: 4;
42 #if defined(__SDCC_pic16)
43 #define ABS_ADDR1 0x0200
44 #define ABS_ADDR2 0x0204
45 #elif defined(__SDCC_pic14)
46 #define ABS_ADDR1 0x0100
47 #define ABS_ADDR2 0x0104
48 #elif defined(__SDCC_stm8)
49 #define ABS_ADDR1 0x1000
50 #define ABS_ADDR2 0x1004
51 #elif defined(__SDCC_f8)
52 #define ABS_ADDR1 0x3000
53 #define ABS_ADDR2 0x3004
55 // TODO: Make test suitable for pdk
56 // mcs51 creates invalid assembler. Don't know if that is a bug or just a bad choice for ABS_ADDR1 and ABS_ADDR2 below.
57 // Disable for ds390: bug #3211
58 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_mcs51) && !defined(__SDCC_ds390)
59 #if !defined(PORT_HOST) // Never do absolute address test with host
60 #define ABS_ADDR1 0xCA00
61 #define ABS_ADDR2 0xCA04
67 volatile struct_nibbles volatileBits
;
70 #define volatileBits (*(volatile struct_nibbles*)ABS_ADDR1)
76 #define volatileBits (*(volatile struct_nibbles*)ABS_ADDR2)
81 #define VOLATILE_BITS_DEF volatile struct_nibbles volatileBits
83 #define VOLATILE_BITS_DEF static volatile struct_nibbles volatileBits
86 #define VOLATILE_BITS_DEF static volatile struct_nibbles __at(ABS_ADDR1) volatileBits
92 #define VOLATILE_BITS_DEF static volatile struct_nibbles __at(ABS_ADDR2) volatileBits
93 #define USE_ONLY_1_BYTE
98 #error "Unknown VAR_TYPE case"
101 #ifndef VOLATILE_BITS_DEF
102 #define VOLATILE_BITS_DEF
107 #define OTHER_FIELD_VALUE 0x00
109 #define OTHER_FIELD_VALUE 0x0F
110 #if OPERATION == OPERATION_COM
112 // No need to test case, because we have only one case for complement operation
118 #define OTHER_FIELD_high low
119 #define OTHER_FIELD_low high
121 #define OTHER_FIELD_(x) OTHER_FIELD_##x
122 #define OTHER_FIELD(x) OTHER_FIELD_(x)
127 static bool success
= false;
129 #if OPERATION == OPERATION_ASSING
131 #define TEST(field, value) \
133 volatileBits.OTHER_FIELD(field) = OTHER_FIELD_VALUE; \
134 volatileBits.field = value; \
135 if((volatileBits.field != (value & 0x0F)) || (volatileBits.OTHER_FIELD(field) != OTHER_FIELD_VALUE)) success = false; \
137 #elif OPERATION == OPERATION_OR
139 #elif OPERATION == OPERATION_AND
141 #elif OPERATION == OPERATION_XOR
143 #elif OPERATION == OPERATION_COM
145 #define TEST(valueLow, valueHigh) \
146 volatileBits.low = valueLow; \
147 volatileBits.high = valueHigh; \
149 volatileBits.low = ~volatileBits.low; \
150 ASSERT(volatileBits.low == ((~valueLow) & 0x0F)); \
151 ASSERT(volatileBits.high == (valueHigh & 0x0F)); \
153 volatileBits.high = ~volatileBits.high; \
154 ASSERT(volatileBits.low == ((~valueLow) & 0x0F)); \
155 ASSERT(volatileBits.high == ((~valueHigh) & 0x0F))
158 #error "Unknown OPERATION case"
161 #ifndef TEST // GENERIC CASE FOR 'AND', 'OR' & 'XOR'
162 #define OP_EQUALS__(x) x##=
163 #define OP_EQUALS_(x) OP_EQUALS__(x)
164 #define OP_EQUALS OP_EQUALS_(OP)
166 #define TEST(field, value) \
168 volatileBits.field = 0x00; \
169 volatileBits.OTHER_FIELD(field) = OTHER_FIELD_VALUE; \
170 if((volatileBits.field != 0x00) || (volatileBits.OTHER_FIELD(field) != OTHER_FIELD_VALUE)) success = false; \
172 volatileBits.field OP_EQUALS value; \
173 if((volatileBits.field != ((value OP 0x00) & 0x0F)) || (volatileBits.OTHER_FIELD(field) != OTHER_FIELD_VALUE)) success = false; \
175 volatileBits.field = 0x0F; \
176 if((volatileBits.field != 0x0F) || (volatileBits.OTHER_FIELD(field) != OTHER_FIELD_VALUE)) success = false; \
178 volatileBits.field OP_EQUALS value; \
179 if((volatileBits.field != ((value OP 0x0F) & 0x0F)) || (volatileBits.OTHER_FIELD(field) != OTHER_FIELD_VALUE)) success = false; \
183 #if OPERATION == OPERATION_COM
185 nibble_com_test1(void)
195 nibble_com_test2_1(void)
204 nibble_com_test2_2(void)
213 nibble_com_test2_3(void)
222 nibble_com_test2_4(void)
232 nibble_com_test3_1(void)
241 nibble_com_test3_2(void)
250 nibble_com_test3_3(void)
259 nibble_com_test3_4(void)
269 nibble_com_test4_1(void)
277 nibble_com_test4_2(void)
285 nibble_com_test4_3(void)
294 nibble_op_test_low1_1(void)
301 nibble_op_test_low1_2(void)
308 nibble_op_test_low2_1(void)
316 nibble_op_test_low2_2(void)
324 nibble_op_test_low3_1(void)
332 nibble_op_test_low3_2(void)
340 nibble_op_test_low4_1(void)
348 nibble_op_test_low4_2(void)
357 nibble_op_test_high1_1(void)
364 nibble_op_test_high1_2(void)
371 nibble_op_test_high2_1(void)
379 nibble_op_test_high2_2(void)
387 nibble_op_test_high3_1(void)
395 nibble_op_test_high3_2(void)
403 nibble_op_test_high4_1(void)
411 nibble_op_test_high4_2(void)
426 #if OPERATION == OPERATION_COM
429 nibble_com_test2_1();
430 nibble_com_test2_2();
431 nibble_com_test2_3();
432 nibble_com_test2_4();
434 nibble_com_test3_1();
435 nibble_com_test3_2();
436 nibble_com_test3_3();
437 nibble_com_test3_4();
439 nibble_com_test4_1();
440 nibble_com_test4_2();
441 nibble_com_test4_3();
443 nibble_op_test_low1_1();
444 nibble_op_test_low1_2();
445 nibble_op_test_low2_1();
447 nibble_op_test_low2_2();
449 nibble_op_test_low3_1();
451 nibble_op_test_low3_2();
453 nibble_op_test_low4_1();
455 nibble_op_test_low4_2();
458 nibble_op_test_high1_1();
459 nibble_op_test_high1_2();
460 nibble_op_test_high2_1();
462 nibble_op_test_high2_2();
464 nibble_op_test_high3_1();
466 nibble_op_test_high3_2();
468 nibble_op_test_high4_1();
470 nibble_op_test_high4_2();