generate_alpha_misc.c Source File

Back to the index.

generate_alpha_misc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2011 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <stdio.h>
29 #include <string.h>
30 
31 
32 char *sizechar[4] = { "b", "w", "l", "q" };
33 
34 #define N_CMPS 5
35 char *cmps[N_CMPS] = { "ult", "eq", "ule", "lt", "le" /*bge*/ };
36 #define N_CMOV 8
37 char *cmov[N_CMOV] = { "lbs", "lbc", "eq", "ne", "lt", "ge", "le", "gt" };
38 
39 
40 int main(int argc, char *argv[])
41 {
42  int load, size, zero, n, msk, llsc;
43  int ra, rc, lo, scale, imm, not, op, quad;
44 
45  printf("\n/* AUTOMATICALLY GENERATED! Do not edit. */\n\n");
46 
47  n = 0;
48  /* add and sub: */
49  for (imm = 0; imm <= 1; imm ++)
50  for (quad = 0; quad <= 1; quad ++)
51  for (scale = 0; scale <= 8; scale += 4)
52  for (op = 0; op <= 1; op ++) {
53  printf("#define ALU_N alpha_instr_");
54  if (scale)
55  printf("s%i", scale);
56  printf("%s%s", op? "sub" : "add", quad? "q" : "l");
57  if (imm)
58  printf("_imm");
59  printf("\n");
60 
61  if (imm)
62  printf("#define ALU_IMM\n");
63  if (!quad)
64  printf("#define ALU_LONG\n");
65  if (op)
66  printf("#define ALU_SUB\n");
67  else
68  printf("#define ALU_ADD\n");
69  if (scale)
70  printf("#define ALU_S%i\n", scale);
71 
72  printf("#include \"cpu_alpha_instr_alu.cc\"\n");
73 
74  if (imm)
75  printf("#undef ALU_IMM\n");
76  if (!quad)
77  printf("#undef ALU_LONG\n");
78  if (op)
79  printf("#undef ALU_SUB\n");
80  else
81  printf("#undef ALU_ADD\n");
82  if (scale)
83  printf("#undef ALU_S%i\n", scale);
84 
85  printf("#undef ALU_N\n");
86  }
87 
88  /* and, or, xor, zap, sll, srl, sra: */
89  for (imm = 0; imm <= 1; imm ++)
90  for (not = 0; not <= 1; not ++)
91  for (op = 0; op < 7; op ++) {
92  if (op >= 4 && not)
93  continue;
94  printf("#define ALU_N alpha_instr_");
95  switch (op) {
96  case 0: printf("and"); break;
97  case 1: printf("or"); break;
98  case 2: printf("xor"); break;
99  case 3: printf("zap"); break;
100  case 4: printf("sll"); break;
101  case 5: printf("srl"); break;
102  case 6: printf("sra"); break;
103  }
104  if (not)
105  printf("not");
106  if (imm)
107  printf("_imm");
108  printf("\n");
109  if (imm)
110  printf("#define ALU_IMM\n");
111  switch (op) {
112  case 0: printf("#define ALU_AND\n"); break;
113  case 1: printf("#define ALU_OR\n"); break;
114  case 2: printf("#define ALU_XOR\n"); break;
115  case 3: printf("#define ALU_ZAP\n"); break;
116  case 4: printf("#define ALU_SLL\n"); break;
117  case 5: printf("#define ALU_SRL\n"); break;
118  case 6: printf("#define ALU_SRA\n"); break;
119  }
120  if (not)
121  printf("#define ALU_NOT\n");
122  printf("#include \"cpu_alpha_instr_alu.cc\"\n");
123 
124  if (imm)
125  printf("#undef ALU_IMM\n");
126  if (not)
127  printf("#undef ALU_NOT\n");
128  switch (op) {
129  case 0: printf("#undef ALU_AND\n"); break;
130  case 1: printf("#undef ALU_OR\n"); break;
131  case 2: printf("#undef ALU_XOR\n"); break;
132  case 3: printf("#undef ALU_ZAP\n"); break;
133  case 4: printf("#undef ALU_SLL\n"); break;
134  case 5: printf("#undef ALU_SRL\n"); break;
135  case 6: printf("#undef ALU_SRA\n"); break;
136  }
137 
138  printf("#undef ALU_N\n");
139  }
140 
141  printf("#define ALU_CMP\n");
142  for (imm = 0; imm <= 1; imm ++)
143  for (op = 0; op < N_CMPS; op ++) {
144  printf("#define ALU_N alpha_instr_cmp%s", cmps[op]);
145  if (imm)
146  printf("_imm");
147  printf("\n");
148 
149  if (imm)
150  printf("#define ALU_IMM\n");
151 
152  if (cmps[op][0] == 'u')
153  printf("#define ALU_UNSIGNED\n");
154  if (strcmp(cmps[op]+strlen(cmps[op])-2,"lt") == 0)
155  printf("#define ALU_CMP_LT\n");
156  if (strcmp(cmps[op]+strlen(cmps[op])-2,"le") == 0)
157  printf("#define ALU_CMP_LE\n");
158  if (strcmp(cmps[op]+strlen(cmps[op])-2,"eq") == 0)
159  printf("#define ALU_CMP_EQ\n");
160 
161  printf("#include \"cpu_alpha_instr_alu.cc\"\n");
162 
163  if (cmps[op][0] == 'u')
164  printf("#undef ALU_UNSIGNED\n");
165  if (strcmp(cmps[op]+strlen(cmps[op])-2,"lt") == 0)
166  printf("#undef ALU_CMP_LT\n");
167  if (strcmp(cmps[op]+strlen(cmps[op])-2,"le") == 0)
168  printf("#undef ALU_CMP_LE\n");
169  if (strcmp(cmps[op]+strlen(cmps[op])-2,"eq") == 0)
170  printf("#undef ALU_CMP_EQ\n");
171  if (imm)
172  printf("#undef ALU_IMM\n");
173  printf("#undef ALU_N\n");
174  }
175  printf("#undef ALU_CMP\n");
176 
177  printf("#define ALU_CMOV\n");
178  for (imm = 0; imm <= 1; imm ++)
179  for (op = 0; op < N_CMOV; op ++) {
180  printf("#define ALU_N alpha_instr_cmov%s", cmov[op]);
181  if (imm)
182  printf("_imm");
183  printf("\n");
184  if (imm)
185  printf("#define ALU_IMM\n");
186  printf("#define ALU_CMOV_%s\n", cmov[op]);
187  printf("#include \"cpu_alpha_instr_alu.cc\"\n");
188  printf("#undef ALU_CMOV_%s\n", cmov[op]);
189  if (imm)
190  printf("#undef ALU_IMM\n");
191  printf("#undef ALU_N\n");
192  }
193  printf("#undef ALU_CMOV\n");
194 
195  printf("#define ALU_CMPBGE\n");
196  for (imm = 0; imm <= 1; imm ++) {
197  printf("#define ALU_N alpha_instr_cmpbge");
198  if (imm)
199  printf("_imm");
200  printf("\n");
201  if (imm)
202  printf("#define ALU_IMM\n");
203  printf("#include \"cpu_alpha_instr_alu.cc\"\n");
204  if (imm)
205  printf("#undef ALU_IMM\n");
206  printf("#undef ALU_N\n");
207  }
208  printf("#undef ALU_CMPBGE\n");
209 
210  for (imm = 0; imm <= 1; imm ++)
211  for (lo = 0; lo <= 1; lo ++)
212  for (msk = 0; msk <= 2; msk ++)
213  for (size=0; size<4; size++) {
214  if (size==0 && lo==0)
215  continue;
216  switch (msk) {
217  case 0: printf("#define ALU_MSK\n"); break;
218  case 1: printf("#define ALU_EXT\n"); break;
219  case 2: printf("#define ALU_INS\n"); break;
220  }
221  switch (msk) {
222  case 0: printf("#define ALU_N alpha_instr_msk"); break;
223  case 1: printf("#define ALU_N alpha_instr_ext"); break;
224  case 2: printf("#define ALU_N alpha_instr_ins"); break;
225  }
226  printf("%s", sizechar[size]);
227  if (lo)
228  printf("l");
229  else
230  printf("h");
231  if (imm)
232  printf("_imm");
233  printf("\n");
234  if (imm)
235  printf("#define ALU_IMM\n");
236  switch (size) {
237  case 0: printf("#define ALU_B\n"); break;
238  case 1: printf("#define ALU_W\n"); break;
239  case 2: printf("#define ALU_L\n"); break;
240  case 3: printf("#define ALU_Q\n"); break;
241  }
242  if (lo)
243  printf("#define ALU_LO\n");
244  printf("#include \"cpu_alpha_instr_alu.cc\"\n");
245  switch (size) {
246  case 0: printf("#undef ALU_B\n"); break;
247  case 1: printf("#undef ALU_W\n"); break;
248  case 2: printf("#undef ALU_L\n"); break;
249  case 3: printf("#undef ALU_Q\n"); break;
250  }
251  switch (msk) {
252  case 0: printf("#undef ALU_MSK\n"); break;
253  case 1: printf("#undef ALU_EXT\n"); break;
254  case 2: printf("#undef ALU_INS\n"); break;
255  }
256  if (lo)
257  printf("#undef ALU_LO\n");
258  if (imm)
259  printf("#undef ALU_IMM\n");
260  printf("#undef ALU_N\n");
261  }
262 
263  /*
264  * Normal load/store:
265  */
266  for (llsc=0; llsc<=1; llsc++)
267  for (load=0; load<=1; load++)
268  for (zero=0; zero<=1; zero++)
269  for (size=0; size<4; size++) {
270  if (llsc && size < 2)
271  continue;
272  if (zero)
273  printf("#define LS_IGNORE_OFFSET\n");
274  if (load)
275  printf("#define LS_LOAD\n");
276  if (llsc)
277  printf("#define LS_LLSC\n");
278  switch (size) {
279  case 0: printf("#define LS_B\n"); break;
280  case 1: printf("#define LS_W\n"); break;
281  case 2: printf("#define LS_L\n"); break;
282  case 3: printf("#define LS_Q\n"); break;
283  }
284  printf("#define LS_GENERIC_N alpha_generic_");
285  if (load)
286  printf("ld");
287  else
288  printf("st");
289  printf("%s", sizechar[size]);
290  if (llsc)
291  printf("_llsc");
292  printf("\n");
293  printf("#define LS_N alpha_instr_");
294  if (load)
295  printf("ld");
296  else
297  printf("st");
298  printf("%s", sizechar[size]);
299  if (zero)
300  printf("_0");
301  if (llsc)
302  printf("_llsc");
303  printf("\n");
304  printf("#include \"cpu_alpha_instr_loadstore.cc\"\n");
305  printf("#undef LS_N\n");
306  printf("#undef LS_GENERIC_N\n");
307  switch (size) {
308  case 0: printf("#undef LS_B\n"); break;
309  case 1: printf("#undef LS_W\n"); break;
310  case 2: printf("#undef LS_L\n"); break;
311  case 3: printf("#undef LS_Q\n"); break;
312  }
313  if (load)
314  printf("#undef LS_LOAD\n");
315  if (llsc)
316  printf("#undef LS_LLSC\n");
317  if (zero)
318  printf("#undef LS_IGNORE_OFFSET\n");
319  }
320 
321  /*
322  * Unaligned load/store:
323  */
324  printf("#define LS_UNALIGNED\n");
325  for (load=0; load<=1; load++) {
326  size = 3;
327  if (load)
328  printf("#define LS_LOAD\n");
329  printf("#define LS_Q\n");
330  printf("#define LS_GENERIC_N alpha_generic_");
331  if (load)
332  printf("ld");
333  else
334  printf("st");
335  printf("%s", sizechar[size]);
336  printf("_u"); /* NOTE: unaligned */
337  printf("\n");
338  printf("#define LS_N alpha_instr_");
339  if (load)
340  printf("ld");
341  else
342  printf("st");
343  printf("%s", sizechar[size]);
344  printf("_u"); /* NOTE: unaligned */
345  printf("\n");
346  printf("#include \"cpu_alpha_instr_loadstore.cc\"\n");
347  printf("#undef LS_N\n");
348  printf("#undef LS_GENERIC_N\n");
349  printf("#undef LS_Q\n");
350  if (load)
351  printf("#undef LS_LOAD\n");
352  }
353  printf("#undef LS_UNALIGNED\n");
354 
355  /* Lookup table for most normal loads/stores: */
356  printf("\n\nvoid (*alpha_loadstore[32])(struct cpu *, struct "
357  "alpha_instr_call *) = {\n");
358 
359  for (llsc = 0; llsc <= 1; llsc ++)
360  for (load=0; load<=1; load++)
361  for (zero=0; zero<=1; zero++)
362  for (size=0; size<4; size++) {
363  printf("\talpha_instr_");
364  if (llsc && (size != 2 && size != 3)) {
365  printf("nop");
366  } else {
367  if (load)
368  printf("ld");
369  else
370  printf("st");
371  printf("%s", sizechar[size]);
372  if (zero)
373  printf("_0");
374  if (llsc)
375  printf("_llsc");
376  }
377  if (++n < 64)
378  printf(",");
379  printf("\n");
380  }
381 
382  printf("};\n\n");
383 
384  for (ra = 0; ra < 32; ra ++)
385  for (rc = 0; rc < 31; rc ++)
386  if (ra != rc) {
387  printf("static void alpha_instr_mov_%i_%i(struct cpu"
388  " *cpu, struct alpha_instr_call *ic)\n", ra, rc);
389  printf("{ cpu->cd.alpha.r[%i] = ", rc);
390  if (ra == 31)
391  printf("0");
392  else
393  printf("cpu->cd.alpha.r[%i]", ra);
394  printf("; }\n");
395  }
396 
397  printf("\n\nvoid (*alpha_mov_r_r[32*31])(struct cpu *, struct "
398  "alpha_instr_call *) = {\n");
399  n = 0;
400  for (rc = 0; rc < 31; rc ++)
401  for (ra = 0; ra < 32; ra ++) {
402  if (ra == rc)
403  printf("\talpha_instr_nop");
404  else
405  printf("\talpha_instr_mov_%i_%i", ra, rc);
406  if (++n < 31*32)
407  printf(",");
408  printf("\n");
409  }
410 
411  printf("};\n\n");
412 
413  return 0;
414 }
415 
#define N_CMOV
char * sizechar[4]
char * cmps[N_CMPS]
#define N_CMPS
void COMBINE() strlen(struct cpu *cpu, struct arm_instr_call *ic, int low_addr)
void load(FILE *fh, unsigned char *ptr, unsigned long sz)
int main(int argc, char *argv[])
char * cmov[N_CMOV]
char * op[16]

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13