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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
|
/* Subroutines for insn-output.c for Tahoe.
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "rtl.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "real.h"
#include "insn-config.h"
#include "conditions.h"
#include "insn-flags.h"
#include "output.h"
#include "insn-attr.h"
/*
* File: output-tahoe.c
*
* Original port made at the University of Buffalo by Devon Bowen,
* Dale Wiles and Kevin Zachmann.
*
* Changes for HCX by Piet van Oostrum,
* University of Utrecht, The Netherlands (piet@cs.ruu.nl)
*
* Speed tweaks by Michael Tiemann (tiemann@lurch.stanford.edu).
*
* Mail bugs reports or fixes to: gcc@cs.buffalo.edu
*/
/* On tahoe, you have to go to memory to convert a register
from sub-word to word. */
rtx tahoe_reg_conversion_loc;
int
extendable_operand (op, mode)
rtx op;
enum machine_mode mode;
{
if ((GET_CODE (op) == REG
|| (GET_CODE (op) == SUBREG
&& GET_CODE (SUBREG_REG (op)) == REG))
&& tahoe_reg_conversion_loc == 0)
tahoe_reg_conversion_loc = assign_stack_local (SImode, GET_MODE_SIZE (SImode));
return general_operand (op, mode);
}
/* most of the print_operand_address function was taken from the vax */
/* since the modes are basically the same. I had to add a special case, */
/* though, for symbol references with offsets. */
#include <stdio.h>
print_operand_address (file, addr)
FILE *file;
register rtx addr;
{
register rtx reg1, reg2, breg, ireg;
rtx offset;
static char *reg_name[] = REGISTER_NAMES;
retry:
switch (GET_CODE (addr))
{
case MEM:
fprintf (file, "*");
addr = XEXP (addr, 0);
goto retry;
case REG:
fprintf (file, "(%s)", reg_name [REGNO (addr)]);
break;
case PRE_DEC:
fprintf (file, "-(%s)", reg_name [REGNO (XEXP (addr, 0))]);
break;
case POST_INC:
fprintf (file, "(%s)+", reg_name [REGNO (XEXP (addr, 0))]);
break;
case PLUS:
reg1 = 0; reg2 = 0;
ireg = 0; breg = 0;
offset = 0;
if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
&& GET_CODE (XEXP (addr, 1)) == CONST_INT)
output_addr_const (file, addr);
if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
&& GET_CODE (XEXP (addr, 0)) == CONST_INT)
output_addr_const (file, addr);
if (CONSTANT_ADDRESS_P (XEXP (addr, 0))
|| GET_CODE (XEXP (addr, 0)) == MEM)
{
offset = XEXP (addr, 0);
addr = XEXP (addr, 1);
}
else if (CONSTANT_ADDRESS_P (XEXP (addr, 1))
|| GET_CODE (XEXP (addr, 1)) == MEM)
{
offset = XEXP (addr, 1);
addr = XEXP (addr, 0);
}
if (GET_CODE (addr) != PLUS)
;
else if (GET_CODE (XEXP (addr, 0)) == MULT)
{
reg1 = XEXP (addr, 0);
addr = XEXP (addr, 1);
}
else if (GET_CODE (XEXP (addr, 1)) == MULT)
{
reg1 = XEXP (addr, 1);
addr = XEXP (addr, 0);
}
else if (GET_CODE (XEXP (addr, 0)) == REG)
{
reg1 = XEXP (addr, 0);
addr = XEXP (addr, 1);
}
else if (GET_CODE (XEXP (addr, 1)) == REG)
{
reg1 = XEXP (addr, 1);
addr = XEXP (addr, 0);
}
if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT)
{
if (reg1 == 0)
reg1 = addr;
else
reg2 = addr;
addr = 0;
}
if (offset != 0)
{
if (addr != 0) abort ();
addr = offset;
}
if (reg1 != 0 && GET_CODE (reg1) == MULT)
{
breg = reg2;
ireg = reg1;
}
else if (reg2 != 0 && GET_CODE (reg2) == MULT)
{
breg = reg1;
ireg = reg2;
}
else if (reg2 != 0 || GET_CODE (addr) == MEM)
{
breg = reg2;
ireg = reg1;
}
else
{
breg = reg1;
ireg = reg2;
}
if (addr != 0)
output_address (offset);
if (breg != 0)
{
if (GET_CODE (breg) != REG)
abort ();
fprintf (file, "(%s)", reg_name[REGNO (breg)]);
}
if (ireg != 0)
{
if (GET_CODE (ireg) == MULT)
ireg = XEXP (ireg, 0);
if (GET_CODE (ireg) != REG)
abort ();
fprintf (file, "[%s]", reg_name[REGNO (ireg)]);
}
break;
default:
output_addr_const (file, addr);
}
}
/* Do a quick check and find out what the best way to do the */
/* mini-move is. Could be a push or a move..... */
static char *
singlemove_string (operands)
rtx *operands;
{
if (operands[1] == const0_rtx)
return "clrl %0";
if (push_operand (operands[0], SImode))
return "pushl %1";
return "movl %1,%0";
}
/* given the rtx for an address, return true if the given */
/* register number is used in the address somewhere. */
regisused(addr,regnum)
rtx addr;
int regnum;
{
if (GET_CODE(addr) == REG)
if (REGNO(addr) == regnum)
return (1);
else
return (0);
if (GET_CODE(addr) == MEM)
return regisused(XEXP(addr,0),regnum);
if ((GET_CODE(addr) == MULT) || (GET_CODE(addr) == PLUS))
return ((regisused(XEXP(addr,0),regnum)) ||
(regisused(XEXP(addr,1),regnum)));
return 0;
}
/* Given some rtx, traverse it and return the register used in a */
/* index. If no index is found, return 0. */
rtx
index_reg(addr)
rtx addr;
{
rtx temp;
if (GET_CODE(addr) == MEM)
return index_reg(XEXP(addr,0));
if (GET_CODE(addr) == MULT)
if (GET_CODE(XEXP(addr,0)) == REG)
return XEXP(addr,0);
else
return XEXP(addr,1);
if (GET_CODE(addr) == PLUS)
if (temp = index_reg(XEXP(addr,0)))
return temp;
else
return index_reg(XEXP(addr,1));
return 0;
}
/* simulate the move double by generating two movl's. You have */
/* to be careful about mixing modes here. */
char *
output_move_double (operands)
rtx *operands;
{
enum { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, INDOP, CNSTOP, RNDOP }
optype0, optype1;
rtx latehalf[2];
rtx shftreg0 = 0, shftreg1 = 0;
rtx temp0 = 0, temp1 = 0;
rtx addreg0 = 0, addreg1 = 0;
int dohighfirst = 0;
/* First classify both operands. */
if (REG_P (operands[0]))
optype0 = REGOP;
else if ((GET_CODE(operands[0])==MEM) && (shftreg0=index_reg(operands[0])))
optype0 = INDOP;
else if (offsettable_memref_p (operands[0]))
optype0 = OFFSOP;
else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC) {
optype0 = PUSHOP;
dohighfirst++;
} else if (GET_CODE (operands[0]) == MEM)
optype0 = MEMOP;
else
optype0 = RNDOP;
if (REG_P (operands[1]))
optype1 = REGOP;
else if ((GET_CODE(operands[1])==MEM) && (shftreg1=index_reg(operands[1])))
optype1 = INDOP;
else if (offsettable_memref_p (operands[1]))
optype1 = OFFSOP;
else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
optype1 = POPOP;
else if (GET_CODE (operands[1]) == MEM)
optype1 = MEMOP;
else if (CONSTANT_P (operands[1]))
optype1 = CNSTOP;
else
optype1 = RNDOP;
/* set up for the high byte move for operand zero */
switch (optype0) {
/* if it's a register, just use the next highest in the */
/* high address move. */
case REGOP : latehalf[0] = gen_rtx (REG,SImode,REGNO(operands[0])+1);
break;
/* for an offsettable address, use the gcc function to */
/* modify the operand to get an offset of 4 higher for */
/* the second move. */
case OFFSOP : latehalf[0] = adj_offsettable_operand (operands[0], 4);
break;
/* if the operand is MEMOP type, it must be a pointer */
/* to a pointer. So just remember to increase the mem */
/* location and use the same operand. */
case MEMOP : latehalf[0] = operands[0];
addreg0 = XEXP(operands[0],0);
break;
/* if we're dealing with a push instruction, just leave */
/* the operand alone since it auto-increments. */
case PUSHOP : latehalf[0] = operands[0];
break;
/* YUCK! Indexed addressing!! If the address is considered */
/* offsettable, go use the offset in the high part. Otherwise */
/* find what exactly is being added to the multiplication. If */
/* it's a mem reference, increment that with the high part */
/* being unchanged to cause the shift. If it's a reg, do the */
/* same. If you can't identify it, abort. Remember that the */
/* shift register was already set during identification. */
case INDOP : if (offsettable_memref_p(operands[0])) {
latehalf[0] = adj_offsettable_operand(operands[0],4);
break;
}
latehalf[0] = operands[0];
temp0 = XEXP(XEXP(operands[0],0),0);
if (GET_CODE(temp0) == MULT) {
temp1 = temp0;
temp0 = XEXP(XEXP(operands[0],0),1);
} else {
temp1 = XEXP(XEXP(operands[0],0),1);
if (GET_CODE(temp1) != MULT)
abort();
}
if (GET_CODE(temp0) == MEM)
addreg0 = temp0;
else if (GET_CODE(temp0) == REG)
addreg0 = temp0;
else
abort();
break;
/* if we don't know the operand type, print a friendly */
/* little error message... 8-) */
case RNDOP :
default : abort();
}
/* do the same setup for operand one */
switch (optype1) {
case REGOP : latehalf[1] = gen_rtx(REG,SImode,REGNO(operands[1])+1);
break;
case OFFSOP : latehalf[1] = adj_offsettable_operand (operands[1], 4);
break;
case MEMOP : latehalf[1] = operands[1];
addreg1 = XEXP(operands[1],0);
break;
case POPOP : latehalf[1] = operands[1];
break;
case INDOP : if (offsettable_memref_p(operands[1])) {
latehalf[1] = adj_offsettable_operand(operands[1],4);
break;
}
latehalf[1] = operands[1];
temp0 = XEXP(XEXP(operands[1],0),0);
if (GET_CODE(temp0) == MULT) {
temp1 = temp0;
temp0 = XEXP(XEXP(operands[1],0),1);
} else {
temp1 = XEXP(XEXP(operands[1],0),1);
if (GET_CODE(temp1) != MULT)
abort();
}
if (GET_CODE(temp0) == MEM)
addreg1 = temp0;
else if (GET_CODE(temp0) == REG)
addreg1 = temp0;
else
abort();
break;
case CNSTOP :
if (GET_CODE (operands[1]) == CONST_DOUBLE)
split_double (operands[1], &operands[1], &latehalf[1]);
else if (CONSTANT_P (operands[1]))
latehalf[1] = const0_rtx;
else abort ();
break;
case RNDOP :
default : abort();
}
/* double the register used for shifting in both of the operands */
/* but make sure the same register isn't doubled twice! */
if (shftreg0 && shftreg1 && (rtx_equal_p(shftreg0,shftreg1)))
output_asm_insn("addl2 %0,%0", &shftreg0);
else {
if (shftreg0)
output_asm_insn("addl2 %0,%0", &shftreg0);
if (shftreg1)
output_asm_insn("addl2 %0,%0", &shftreg1);
}
/* if the destination is a register and that register is needed in */
/* the source addressing mode, swap the order of the moves since we */
/* don't want this destroyed til last. If both regs are used, not */
/* much we can do, so abort. If these becomes a problem, maybe we */
/* can do it on the stack? */
if (GET_CODE(operands[0])==REG && regisused(operands[1],REGNO(operands[0])))
if (regisused(latehalf[1],REGNO(latehalf[0])))
8;
else
dohighfirst++;
/* if we're pushing, do the high address part first. */
if (dohighfirst) {
if (addreg0 && addreg1 && (rtx_equal_p(addreg0,addreg1)))
output_asm_insn("addl2 $4,%0", &addreg0);
else {
if (addreg0)
output_asm_insn("addl2 $4,%0", &addreg0);
if (addreg1)
output_asm_insn("addl2 $4,%0", &addreg1);
}
output_asm_insn(singlemove_string(latehalf), latehalf);
if (addreg0 && addreg1 && (rtx_equal_p(addreg0,addreg1)))
output_asm_insn("subl2 $4,%0", &addreg0);
else {
if (addreg0)
output_asm_insn("subl2 $4,%0", &addreg0);
if (addreg1)
output_asm_insn("subl2 $4,%0", &addreg1);
}
return singlemove_string(operands);
}
output_asm_insn(singlemove_string(operands), operands);
if (addreg0 && addreg1 && (rtx_equal_p(addreg0,addreg1)))
output_asm_insn("addl2 $4,%0", &addreg0);
else {
if (addreg0)
output_asm_insn("addl2 $4,%0", &addreg0);
if (addreg1)
output_asm_insn("addl2 $4,%0", &addreg1);
}
output_asm_insn(singlemove_string(latehalf), latehalf);
if (addreg0 && addreg1 && (rtx_equal_p(addreg0,addreg1)))
output_asm_insn("subl2 $4,%0", &addreg0);
else {
if (addreg0)
output_asm_insn("subl2 $4,%0", &addreg0);
if (addreg1)
output_asm_insn("subl2 $4,%0", &addreg1);
}
if (shftreg0 && shftreg1 && (rtx_equal_p(shftreg0,shftreg1)))
output_asm_insn("shar $1,%0,%0", &shftreg0);
else {
if (shftreg0)
output_asm_insn("shar $1,%0,%0", &shftreg0);
if (shftreg1)
output_asm_insn("shar $1,%0,%0", &shftreg1);
}
return "";
}
/* This checks if a zero_extended cmp[bw] can be replaced by a sign_extended
cmp[bw]. This can be done if the operand is a constant that fits in a
byte/word or a memory operand. Besides that the next instruction must be an
unsigned compare. Some of these tests are done by the machine description */
int
tahoe_cmp_check (insn, op, max)
rtx insn, op; int max;
{
if (GET_CODE (op) == CONST_INT
&& ( INTVAL (op) < 0 || INTVAL (op) > max ))
return 0;
{
register rtx next = NEXT_INSN (insn);
if ((GET_CODE (next) == JUMP_INSN
|| GET_CODE (next) == INSN
|| GET_CODE (next) == CALL_INSN))
{
next = PATTERN (next);
if (GET_CODE (next) == SET
&& SET_DEST (next) == pc_rtx
&& GET_CODE (SET_SRC (next)) == IF_THEN_ELSE)
switch (GET_CODE (XEXP (SET_SRC (next), 0)))
{
case EQ:
case NE:
case LTU:
case GTU:
case LEU:
case GEU:
return 1;
}
}
}
return 0;
}
|