struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / swap_add.c
blob22aabb5212edcf545f1f4b3bb54e9c27049c4b96
1 /** Swap test using 'addition' instead of usual 'or'
2 */
4 #include <testfwk.h>
5 #ifdef __sun__
6 #include <inttypes.h>
7 #else
8 #include <stdint.h>
9 #endif
11 uint8_t
12 swap_add_8(uint8_t value)
14 value = (value << 4) + (value >> 4);
15 return value;
18 #define SWAP_ADD_8(value) (((value << 4) & 0xF0u) | ((value >> 4) & 0x0Fu))
19 #define SWAP_ADD_8_EQUALS(value) (swap_add_8(value) == SWAP_ADD_8(value))
20 static void
21 testSwapAdd(void)
23 #ifndef __SDCC_pdk15 // Bug
24 ASSERT(SWAP_ADD_8_EQUALS(0x01));
25 ASSERT(SWAP_ADD_8_EQUALS(0x02));
26 ASSERT(SWAP_ADD_8_EQUALS(0x04));
27 ASSERT(SWAP_ADD_8_EQUALS(0x08));
29 ASSERT(SWAP_ADD_8_EQUALS(0x10));
30 ASSERT(SWAP_ADD_8_EQUALS(0x20));
31 ASSERT(SWAP_ADD_8_EQUALS(0x40));
32 ASSERT(SWAP_ADD_8_EQUALS(0x80));
34 ASSERT(SWAP_ADD_8_EQUALS(0x0F));
35 ASSERT(SWAP_ADD_8_EQUALS(0xF0));
36 ASSERT(SWAP_ADD_8_EQUALS(0x3C));
37 ASSERT(SWAP_ADD_8_EQUALS(0xC3));
38 #endif