summaryrefslogtreecommitdiff
path: root/support/regression/tests/regtrack.c
blob: 77aaec374f7a7c9a7e3c38776323eacf3ac2c106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
   regtrack.c - testing register tracking
*/

#include <testfwk.h>
#include <string.h>

volatile unsigned char __xdata t;

__pdata      unsigned char ta[] = {0x00,0x01,0x01,0x02,0x01,0xfe,0x7f,0xfe,0xef};
__code const unsigned char tb[] = {0x00,0x01,0x01,0x02,0x01,0xfe,0x7f,0xfe,0xef};

static void 
foo (unsigned char which)
{
  unsigned char i, k;  // should be allocated to registers
  volatile unsigned char m = 1;

  k = 2;
  do
    {
      t = 0xab;
      i = 2;
      do
        {
          switch( which )
            {
            case 1:
              k = 1;
              t = 1;    // mov
              break;

            case 2:
              t = 0x01; 
              t = 0x02; // inc
              break;

            case 3:
              t = 0x05;
              t = 0x04;
              t = 0x03; // dec
              break;

            case 4:
              t = ~0x04;
              t = 0x04; // cpl
              break;

            case 5:
              t = 0x05 << 1;
              t = 0x05; // rr
              break;

            case 6:
              t = 0x06 >> 1;
              t = 0x06; // rl
              break;

            case 7:
              t = 0x70;
              t = 0x07; // swap
              break;

            case 0x08: 
              t = 0x0a;
              k = 0x02;
              t = 0x08; // xrl
              break;

            case 0x09: 
              t = 0x0f;
              k = 0xf9;
              t = 0x09; // anl
              break;

            case 0x0a: 
              t = 0x08;
              k = 0x02;
              t = 0x0a; // orl
              break;

            case 0x0b: 
              t = 0x0b * 7;
              k = 7;
              t = t/7;  // div
              break;

            case 0x0c: 
              t = 4;
              k = 3;
              t = t * 3;  // mul
              break;
            }
        }
      while (--i);
      
      if (!i)
        k = m; // prepare to exit outer loop
    }
  while (--k);

}




void 
testRegTrack (void)
{
  ASSERT (0 == (char)memcmp (ta, tb, sizeof tb));

  foo (1); ASSERT (t == 1);
  foo (2); ASSERT (t == 2);
  foo (3); ASSERT (t == 3);
  foo (4); ASSERT (t == 4);
#if 1  
  /* various checks for equality */
  foo (5); ASSERT (!(t ^ 5));
  foo (6); ASSERT (0 == (t ^ 6));
  foo (7); ASSERT (!(t - 7));
  foo (8); ASSERT (0 == (t - 8));
  foo (9); ASSERT (0 == ((unsigned char)(t + (0x100 - 9))));
  foo (10); ASSERT (!((unsigned char)(t + (0x100 - 10))));
  foo (11); ASSERT (t >= 11 && t <= 11);
  foo (12); ASSERT (t > 11 && t < 13);
#else  
  foo (5); ASSERT (t == 5);
  foo (6); ASSERT (t == 6);
  foo (7); ASSERT (t == 7);
  foo (8); ASSERT (t == 8);
  foo (9); ASSERT (t == 9);
  foo (10); ASSERT (t == 10);
  foo (11); ASSERT (t == 11);
  foo (12); ASSERT (t == 12);
#endif
}