struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / and_survive.c
blobb56049c6cdb44690ebb57a0b2fb5487076d18b1c
1 /*
2 This test is meant to test the backend's generation of
3 non-destructive and available on some architectures.
4 Also serves as a regression test for bug #3534833.
5 */
7 #include <testfwk.h>
9 /* Some architectures have non-destructive and when one operand is a literal with exactly one bit set (e.g. all Z80-related ) */
10 int litbitchar (unsigned char a)
12 register unsigned char b = a + 1; /* Suggest allocating b to accumulator */
14 if (b & 0x01)
15 return(0);
16 else if (b & 0x04)
17 return(1);
18 else if (b & 0x20)
19 return(2);
20 else
21 return(3);
24 /* Some architectures have non-destructive and when one operand is a literal with exactly one bit set, and the other operand can be in any register or even spilt (e.g. S08) */
25 int litbitchar2 (unsigned char a, unsigned char c, unsigned char e)
27 unsigned char b = a + 1;
28 unsigned char d = c + 1;
30 if (b & 0x01)
32 if (d & 0x01)
33 return(8);
34 else if (d & 0x04)
35 return(9);
36 else
37 return(10);
39 else if (b & 0x04)
40 return(1);
41 else if (b & 0x20)
43 if (e & 0x01)
44 return(4);
45 else if (e & 0x04)
46 return(5);
47 else
48 return(6);
50 else
51 return(3);
54 /* Some architectures have non-destructive and when one operand is a literal with at most one bit per byte set (e.g. Z80) */
55 int litbitint (unsigned int a)
57 register unsigned int b = a + 1; /* Suggest allocating b to accumulator */
59 if (b & 0x0001)
60 return(0);
61 else if (b & 0x0004)
62 return(1);
63 else if (b & 0x2010)
64 return(2);
65 else
66 return(3);
69 /* Some architectures have non-destructive and when one operand is a one-byte literal (e.g. Z180) */
70 int litchar (unsigned char a)
72 register unsigned char b = a + 1; /* Suggest allocating b to accumulator */
74 if (b & 0x33)
75 return(0);
76 else if (b & 0x44)
77 return(1);
78 else if (b & 0x1f)
79 return(2);
80 else
81 return(3);
84 /* Some architectures have non-destructive and when one operand is in a register (e.g. Z180) */
85 int regchar (unsigned char a, unsigned char c)
87 register unsigned char b = a + 1; /* Suggest allocating b to accumulator */
88 register unsigned char d = c + 1;
90 if (b & 0x11)
91 return(0);
92 else if (b & d)
93 return(1);
94 else if (b & 0x33)
95 return(2);
96 else
97 return(3);
100 void testAndSurvive (void)
102 ASSERT (litbitchar (0x77u - 1) == 0);
103 ASSERT (litbitchar (0x74u - 1) == 1);
104 ASSERT (litbitchar (0x70u - 1) == 2);
105 ASSERT (litbitchar (0x80u - 1) == 3);
107 ASSERT (litbitchar2 (0x01u - 1, 0x01u - 1, 0x01u) == 8);
108 ASSERT (litbitchar2 (0x01u - 1, 0x80u - 1, 0x01u) == 10);
109 ASSERT (litbitchar2 (0x74u - 1, 0x01u - 1, 0x01u) == 1);
110 ASSERT (litbitchar2 (0x80u - 1, 0x01u - 1, 0x01u) == 3);
111 ASSERT (litbitchar2 (0x20u - 1, 0x01u - 1, 0x04u) == 5);
113 ASSERT (litbitint (0x0001u - 1) == 0);
114 ASSERT (litbitint (0x8fe8u - 1) == 3);
115 ASSERT (litbitint (0x3030u - 1) == 2);
117 ASSERT (litchar (0x77u - 1) == 0);
118 ASSERT (litchar (0x88u - 1) == 2);
119 ASSERT (litchar (0x48u - 1) == 1);
120 ASSERT (litchar (0x80u - 1) == 3);
122 ASSERT (regchar (0x77u - 1, 0x00u - 1) == 0);
123 ASSERT (regchar (0x88u - 1, 0x08u - 1) == 1);
124 #ifndef __SDCC_pdk14 // Those tests would pass, we just don't have enough space in code memory to fit them in together with the others.
125 ASSERT (regchar (0x80u - 1, 0x88u - 1) == 1);
126 ASSERT (regchar (0x80u - 1, 0x08u - 1) == 3);
127 #endif