Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / bug-2866.c
blobd79c6402f20cbf6d79c2977a14cc33977eac96cf
1 /* bug-2866.c
2 A bug in rematerialization in the z80 backend.
3 */
5 #include <testfwk.h>
7 typedef unsigned char uint8;
8 typedef int int16;
10 #define COL_MAX_HEIGHT 64
11 #define COL_TEX_HEIGHT 32
13 #ifndef __SDCC_pdk14 // Lack of memory
14 uint8 single_column[COL_MAX_HEIGHT];
16 void initSingleColumn(int16 height)
18 int16 y;
19 int16 y0;
20 int16 y1;
21 int16 dy;
22 int16 dv;
23 int16 v;
25 y0 = (COL_MAX_HEIGHT - height) >> 1;
26 y1 = COL_MAX_HEIGHT - y0;
28 dy = y1 - y0 - 1;
29 if (dy < 1) dy = 1;
30 dv = (COL_TEX_HEIGHT << 8) / dy;
31 v = 0;
33 if (y0 < 0)
35 v -= y0 * dv;
36 y0 = 0;
38 if (y1 > COL_MAX_HEIGHT) y1 = COL_MAX_HEIGHT;
40 for (y = 0; y<y0; y++)
42 single_column[y] = 128;
43 single_column[COL_MAX_HEIGHT - y - 1] = 64; // Bug resulted in wrong address calculation here.
46 for (y = y0; y < y1; y++)
48 if (v > (31 << 8)) v = 31 << 8;
49 single_column[y] = (v >> 8);
50 v+=dv;
53 #endif
55 void testBug(void)
57 #ifndef __SDCC_pdk14 // Lack of memory
58 initSingleColumn (0);
60 ASSERT (single_column[0x00] == 0x80);
61 ASSERT (single_column[0x1f] == 0x80);
62 ASSERT (single_column[0x20] == 0x40);
63 ASSERT (single_column[0x3f] == 0x40);
64 #endif