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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [hwtests/] [divtest/] [mkdivtest.c] - Blame information for rev 227

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

Line No. Rev Author Line
1 14 hellwig
/*
2
 * mkdivtest.c -- generate divide test program
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
 
10
 
11
unsigned mydiv(unsigned x, unsigned y) {
12
  return (unsigned) ((signed) x / (signed) y);
13
}
14
 
15
 
16
unsigned mydivu(unsigned x, unsigned y) {
17
  return x / y;
18
}
19
 
20
 
21
unsigned nums[] = {
22
  0x00000000,
23
  0x00000001,
24
  0x00000002,
25
  0x00000003,
26
  0x0000FFFC,
27
  0x0000FFFD,
28
  0x0000FFFE,
29
  0x0000FFFF,
30
  0x00010000,
31
  0x00010001,
32
  0x00010002,
33
  0x00010003,
34
  0x7FFFFFFC,
35
  0x7FFFFFFD,
36
  0x7FFFFFFE,
37
  0x7FFFFFFF,
38
  0x80000000,
39
  0x80000001,
40
  0x80000002,
41
  0x80000003,
42
  0x8000FFFC,
43
  0x8000FFFD,
44
  0x8000FFFE,
45
  0x8000FFFF,
46
  0x80010000,
47
  0x80010001,
48
  0x80010002,
49
  0x80010003,
50
  0xFFFFFFFC,
51
  0xFFFFFFFD,
52
  0xFFFFFFFE,
53
  0xFFFFFFFF,
54
};
55
 
56
int snums = sizeof(nums) / sizeof(nums[0]);
57
 
58
 
59
struct {
60
  char *name;
61
  unsigned (*func)(unsigned x, unsigned y);
62
} ops[] = {
63
  { "div",  mydiv  },
64
  { "divu", mydivu },
65
};
66
 
67
int sops = sizeof(ops) / sizeof(ops[0]);
68
 
69
 
70
int chooseReg(void) {
71
  int r;
72
 
73
  r = (rand() >> 8) % 16;
74
  return r + 8;
75
}
76
 
77
 
78
void chooseRegs(int *r1, int *r2, int *r3, int *r4) {
79
  *r1 = chooseReg();
80
  do {
81
    *r2 = chooseReg();
82
  } while (*r2 == *r1);
83
  do {
84
    *r3 = chooseReg();
85
  } while (*r3 == *r2 || *r3 == *r1);
86
  do {
87
    *r4 = chooseReg();
88
  } while (*r4 == *r3 || *r4 == *r2 || *r4 == *r1);
89
}
90
 
91
 
92
int newLabel(void) {
93
  static int lbl = 1000;
94
  return lbl++;
95
}
96
 
97
 
98
int main(void) {
99
  int i, j, k;
100
  unsigned res;
101
  int r1, r2, r3, r4;
102
  int lbl;
103
 
104
  printf("\tadd\t$7,$0,'.'\n");
105
  for (i = 0; i < snums; i++) {
106
    for (j = 0; j < snums; j++) {
107
      if (nums[j] == 0) {
108
        continue;
109
      }
110
      for (k = 0; k < sops; k++) {
111
        if (nums[i] == 0x80000000 && nums[j] == 0xFFFFFFFF && k == 0) {
112
          continue;
113
        }
114
        res = ops[k].func(nums[i], nums[j]);
115
        chooseRegs(&r1, &r2, &r3, &r4);
116
        lbl = newLabel();
117
        printf("\tadd\t$%d,$0,0x%08X\n", r1, nums[i]);
118
        printf("\tadd\t$%d,$0,0x%08X\n", r2, nums[j]);
119
        printf("\t%s\t$%d,$%d,$%d\n", ops[k].name, r3, r1, r2);
120
        printf("\tadd\t$%d,$0,0x%08X\n", r4, res);
121
        printf("\tbeq\t$%d,$%d,L%d\n", r3, r4, lbl);
122
        printf("\tadd\t$7,$0,'?'\n");
123
        printf("L%d:\n", lbl);
124
      }
125
    }
126
  }
127
  printf("out:\n");
128
  printf("\tadd\t$6,$0,0xF0300000\n");
129
  printf("out1:\n");
130
  printf("\tldw\t$5,$6,8\n");
131
  printf("\tand\t$5,$5,1\n");
132
  printf("\tbeq\t$5,$0,out1\n");
133
  printf("\tstw\t$7,$6,12\n");
134
  printf("halt:\n");
135
  printf("\tj\thalt\n");
136
  return 0;
137
}

powered by: WebSVN 2.1.0

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