OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [hwtests/] [brtest/] [mkbrtest.c] - Blame information for rev 299

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 hellwig
/*
2
 * mkbrtest.c -- generate branch test program
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
 
11
typedef int Bool;
12
 
13
 
14
Bool eq(unsigned x, unsigned y) {
15
  return x == y;
16
}
17
 
18
 
19
Bool ne(unsigned x, unsigned y) {
20
  return x != y;
21
}
22
 
23
 
24
Bool gt(unsigned x, unsigned y) {
25
  return (signed) x > (signed) y;
26
}
27
 
28
 
29
Bool ge(unsigned x, unsigned y) {
30
  return (signed) x >= (signed) y;
31
}
32
 
33
 
34
Bool lt(unsigned x, unsigned y) {
35
  return (signed) x < (signed) y;
36
}
37
 
38
 
39
Bool le(unsigned x, unsigned y) {
40
  return (signed) x <= (signed) y;
41
}
42
 
43
 
44
Bool gtu(unsigned x, unsigned y) {
45
  return x > y;
46
}
47
 
48
 
49
Bool geu(unsigned x, unsigned y) {
50
  return x >= y;
51
}
52
 
53
 
54
Bool ltu(unsigned x, unsigned y) {
55
  return x < y;
56
}
57
 
58
 
59
Bool leu(unsigned x, unsigned y) {
60
  return x <= y;
61
}
62
 
63
 
64
unsigned nums[] = {
65
  0x00000000,
66
  0x00000001,
67
  0x00000002,
68
  0x00000003,
69
  0x7FFFFFFC,
70
  0x7FFFFFFD,
71
  0x7FFFFFFE,
72
  0x7FFFFFFF,
73
  0x80000000,
74
  0x80000001,
75
  0x80000002,
76
  0x80000003,
77
  0xFFFFFFFC,
78
  0xFFFFFFFD,
79
  0xFFFFFFFE,
80
  0xFFFFFFFF,
81
};
82
 
83
int snums = sizeof(nums) / sizeof(nums[0]);
84
 
85
 
86
struct {
87
  char *name;
88
  Bool (*func)(unsigned x, unsigned y);
89
} ops[] = {
90
  { "eq",  eq  },
91
  { "ne",  ne  },
92
  { "gt",  gt  },
93
  { "ge",  ge  },
94
  { "lt",  lt  },
95
  { "le",  le  },
96
  { "gtu", gtu },
97
  { "geu", geu },
98
  { "ltu", ltu },
99
  { "leu", leu },
100
};
101
 
102
int sops = sizeof(ops) / sizeof(ops[0]);
103
 
104
 
105
int chooseReg(void) {
106
  int r;
107
 
108
  r = (rand() >> 8) % 16;
109
  return r + 8;
110
}
111
 
112
 
113
void chooseRegs(int *r1, int *r2) {
114
  *r1 = chooseReg();
115
  do {
116
    *r2 = chooseReg();
117
  } while (*r2 == *r1);
118
}
119
 
120
 
121
int newLabel(void) {
122
  static int lbl = 1000;
123
  return lbl++;
124
}
125
 
126
 
127
int main(void) {
128
  int i, j, k;
129
  Bool res;
130
  int r1, r2;
131
  int lbl1, lbl2;
132
 
133
  printf("\tadd\t$7,$0,'.'\n");
134
  for (i = 0; i < snums; i++) {
135
    for (j = 0; j < snums; j++) {
136
      for (k = 0; k < sops; k++) {
137
        res = ops[k].func(nums[i], nums[j]);
138
        chooseRegs(&r1, &r2);
139
        lbl1 = newLabel();
140
        printf("\tadd\t$%d,$0,0x%08X\n", r1, nums[i]);
141
        printf("\tadd\t$%d,$0,0x%08X\n", r2, nums[j]);
142
        printf("\tb%s\t$%d,$%d,L%d\n", ops[k].name, r1, r2, lbl1);
143
        if (res) {
144
          printf("\tadd\t$7,$0,'?'\n");
145
          printf("L%d:\n", lbl1);
146
        } else {
147
          lbl2 = newLabel();
148
          printf("\tj\tL%d\n", lbl2);
149
          printf("L%d:\n", lbl1);
150
          printf("\tadd\t$7,$0,'?'\n");
151
          printf("L%d:\n", lbl2);
152
        }
153
      }
154
    }
155
  }
156
  printf("out:\n");
157
  printf("\tadd\t$6,$0,0xF0300000\n");
158
  printf("out1:\n");
159
  printf("\tldw\t$5,$6,8\n");
160
  printf("\tand\t$5,$5,1\n");
161
  printf("\tbeq\t$5,$0,out1\n");
162
  printf("\tstw\t$7,$6,12\n");
163
  printf("halt:\n");
164
  printf("\tj\thalt\n");
165
  return 0;
166
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.