1 /* Subroutines for insn-output.c for Intel 80386.
2 Copyright (C) 1988, 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "hard-reg-set.h"
27 #include "insn-config.h"
28 #include "conditions.h"
29 #include "insn-flags.h"
31 #include "insn-attr.h"
35 #ifdef EXTRA_CONSTRAINT
36 /* If EXTRA_CONSTRAINT is defined, then the 'S'
37 constraint in REG_CLASS_FROM_LETTER will no longer work, and various
38 asm statements that need 'S' for class SIREG will break. */
39 error EXTRA_CONSTRAINT conflicts with S constraint letter
40 /* The previous line used to be #error, but some compilers barf
41 even if the conditional was untrue. */
44 #define AT_BP(mode) (gen_rtx (MEM, (mode), frame_pointer_rtx))
46 extern FILE *asm_out_file
;
47 extern char *strcat ();
49 char *singlemove_string ();
50 char *output_move_const_single ();
51 char *output_fp_cc0_set ();
53 char *hi_reg_name
[] = HI_REGISTER_NAMES
;
54 char *qi_reg_name
[] = QI_REGISTER_NAMES
;
55 char *qi_high_reg_name
[] = QI_HIGH_REGISTER_NAMES
;
57 /* Array of the smallest class containing reg number REGNO, indexed by
58 REGNO. Used by REGNO_REG_CLASS in i386.h. */
60 enum reg_class regclass_map
[FIRST_PSEUDO_REGISTER
] =
63 AREG
, DREG
, CREG
, BREG
,
65 SIREG
, DIREG
, INDEX_REGS
, GENERAL_REGS
,
67 FP_TOP_REG
, FP_SECOND_REG
, FLOAT_REGS
, FLOAT_REGS
,
68 FLOAT_REGS
, FLOAT_REGS
, FLOAT_REGS
, FLOAT_REGS
,
73 /* Test and compare insns in i386.md store the information needed to
74 generate branch and scc insns here. */
76 struct rtx_def
*i386_compare_op0
, *i386_compare_op1
;
77 struct rtx_def
*(*i386_compare_gen
)(), *(*i386_compare_gen_eq
)();
79 /* Output an insn whose source is a 386 integer register. SRC is the
80 rtx for the register, and TEMPLATE is the op-code template. SRC may
81 be either SImode or DImode.
83 The template will be output with operands[0] as SRC, and operands[1]
84 as a pointer to the top of the 386 stack. So a call from floatsidf2
87 output_op_from_reg (operands[1], AS1 (fild%z0,%1));
89 where %z0 corresponds to the caller's operands[1], and is used to
90 emit the proper size suffix.
92 ??? Extend this to handle HImode - a 387 can load and store HImode
96 output_op_from_reg (src
, template)
103 xops
[1] = AT_SP (Pmode
);
104 xops
[2] = GEN_INT (GET_MODE_SIZE (GET_MODE (src
)));
105 xops
[3] = stack_pointer_rtx
;
107 if (GET_MODE_SIZE (GET_MODE (src
)) > UNITS_PER_WORD
)
109 rtx high
= gen_rtx (REG
, SImode
, REGNO (src
) + 1);
110 output_asm_insn (AS1 (push
%L0
,%0), &high
);
112 output_asm_insn (AS1 (push
%L0
,%0), &src
);
114 output_asm_insn (template, xops
);
116 output_asm_insn (AS2 (add
%L3
,%2,%3), xops
);
119 /* Output an insn to pop an value from the 387 top-of-stack to 386
120 register DEST. The 387 register stack is popped if DIES is true. If
121 the mode of DEST is an integer mode, a `fist' integer store is done,
122 otherwise a `fst' float store is done. */
125 output_to_reg (dest
, dies
)
131 xops
[0] = AT_SP (Pmode
);
132 xops
[1] = stack_pointer_rtx
;
133 xops
[2] = GEN_INT (GET_MODE_SIZE (GET_MODE (dest
)));
136 output_asm_insn (AS2 (sub
%L1
,%2,%1), xops
);
138 if (GET_MODE_CLASS (GET_MODE (dest
)) == MODE_INT
)
141 output_asm_insn (AS1 (fistp
%z3
,%y0
), xops
);
143 output_asm_insn (AS1 (fist
%z3
,%y0
), xops
);
145 else if (GET_MODE_CLASS (GET_MODE (dest
)) == MODE_FLOAT
)
148 output_asm_insn (AS1 (fstp
%z3
,%y0
), xops
);
150 output_asm_insn (AS1 (fst
%z3
,%y0
), xops
);
155 output_asm_insn (AS1 (pop
%L0
,%0), &dest
);
157 if (GET_MODE_SIZE (GET_MODE (dest
)) > UNITS_PER_WORD
)
159 dest
= gen_rtx (REG
, SImode
, REGNO (dest
) + 1);
160 output_asm_insn (AS1 (pop
%L0
,%0), &dest
);
165 singlemove_string (operands
)
169 if (GET_CODE (operands
[0]) == MEM
170 && GET_CODE (x
= XEXP (operands
[0], 0)) == PRE_DEC
)
172 if (XEXP (x
, 0) != stack_pointer_rtx
)
176 else if (GET_CODE (operands
[1]) == CONST_DOUBLE
)
178 return output_move_const_single (operands
);
180 else if (GET_CODE (operands
[0]) == REG
|| GET_CODE (operands
[1]) == REG
)
181 return AS2 (mov
%L0
,%1,%0);
182 else if (CONSTANT_P (operands
[1]))
183 return AS2 (mov
%L0
,%1,%0);
186 output_asm_insn ("push%L1 %1", operands
);
191 /* Return a REG that occurs in ADDR with coefficient 1.
192 ADDR can be effectively incremented by incrementing REG. */
198 while (GET_CODE (addr
) == PLUS
)
200 if (GET_CODE (XEXP (addr
, 0)) == REG
)
201 addr
= XEXP (addr
, 0);
202 else if (GET_CODE (XEXP (addr
, 1)) == REG
)
203 addr
= XEXP (addr
, 1);
204 else if (CONSTANT_P (XEXP (addr
, 0)))
205 addr
= XEXP (addr
, 1);
206 else if (CONSTANT_P (XEXP (addr
, 1)))
207 addr
= XEXP (addr
, 0);
211 if (GET_CODE (addr
) == REG
)
216 /* Output an insn to add the constant N to the register X. */
227 xops
[0] = GEN_INT (-n
);
228 output_asm_insn (AS2 (sub
%L0
,%0,%1), xops
);
232 xops
[0] = GEN_INT (n
);
233 output_asm_insn (AS2 (add
%L0
,%0,%1), xops
);
237 /* Output assembler code to perform a doubleword move insn
238 with operands OPERANDS. */
241 output_move_double (operands
)
244 enum {REGOP
, OFFSOP
, MEMOP
, PUSHOP
, POPOP
, CNSTOP
, RNDOP
} optype0
, optype1
;
246 rtx addreg0
= 0, addreg1
= 0;
247 int dest_overlapped_low
= 0;
249 /* First classify both operands. */
251 if (REG_P (operands
[0]))
253 else if (offsettable_memref_p (operands
[0]))
255 else if (GET_CODE (XEXP (operands
[0], 0)) == POST_INC
)
257 else if (GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
)
259 else if (GET_CODE (operands
[0]) == MEM
)
264 if (REG_P (operands
[1]))
266 else if (CONSTANT_P (operands
[1]))
268 else if (offsettable_memref_p (operands
[1]))
270 else if (GET_CODE (XEXP (operands
[1], 0)) == POST_INC
)
272 else if (GET_CODE (XEXP (operands
[1], 0)) == PRE_DEC
)
274 else if (GET_CODE (operands
[1]) == MEM
)
279 /* Check for the cases that the operand constraints are not
280 supposed to allow to happen. Abort if we get one,
281 because generating code for these cases is painful. */
283 if (optype0
== RNDOP
|| optype1
== RNDOP
)
286 /* If one operand is decrementing and one is incrementing
287 decrement the former register explicitly
288 and change that operand into ordinary indexing. */
290 if (optype0
== PUSHOP
&& optype1
== POPOP
)
292 operands
[0] = XEXP (XEXP (operands
[0], 0), 0);
293 asm_add (-8, operands
[0]);
294 operands
[0] = gen_rtx (MEM
, DImode
, operands
[0]);
297 if (optype0
== POPOP
&& optype1
== PUSHOP
)
299 operands
[1] = XEXP (XEXP (operands
[1], 0), 0);
300 asm_add (-8, operands
[1]);
301 operands
[1] = gen_rtx (MEM
, DImode
, operands
[1]);
305 /* If an operand is an unoffsettable memory ref, find a register
306 we can increment temporarily to make it refer to the second word. */
308 if (optype0
== MEMOP
)
309 addreg0
= find_addr_reg (XEXP (operands
[0], 0));
311 if (optype1
== MEMOP
)
312 addreg1
= find_addr_reg (XEXP (operands
[1], 0));
314 /* Ok, we can do one word at a time.
315 Normally we do the low-numbered word first,
316 but if either operand is autodecrementing then we
317 do the high-numbered word first.
319 In either case, set up in LATEHALF the operands to use
320 for the high-numbered word and in some cases alter the
321 operands in OPERANDS to be suitable for the low-numbered word. */
323 if (optype0
== REGOP
)
324 latehalf
[0] = gen_rtx (REG
, SImode
, REGNO (operands
[0]) + 1);
325 else if (optype0
== OFFSOP
)
326 latehalf
[0] = adj_offsettable_operand (operands
[0], 4);
328 latehalf
[0] = operands
[0];
330 if (optype1
== REGOP
)
331 latehalf
[1] = gen_rtx (REG
, SImode
, REGNO (operands
[1]) + 1);
332 else if (optype1
== OFFSOP
)
333 latehalf
[1] = adj_offsettable_operand (operands
[1], 4);
334 else if (optype1
== CNSTOP
)
336 if (GET_CODE (operands
[1]) == CONST_DOUBLE
)
337 split_double (operands
[1], &operands
[1], &latehalf
[1]);
338 else if (CONSTANT_P (operands
[1]))
340 if (GET_CODE (operands
[1]) == CONST_INT
&& INTVAL (operands
[1]) < 0)
341 latehalf
[1] = constm1_rtx
;
343 latehalf
[1] = const0_rtx
;
347 latehalf
[1] = operands
[1];
349 /* If insn is effectively movd N (sp),-(sp) then we will do the
350 high word first. We should use the adjusted operand 1 (which is N+4 (sp))
351 for the low word as well, to compensate for the first decrement of sp. */
352 if (optype0
== PUSHOP
353 && REGNO (XEXP (XEXP (operands
[0], 0), 0)) == STACK_POINTER_REGNUM
354 && reg_overlap_mentioned_p (stack_pointer_rtx
, operands
[1]))
355 operands
[1] = latehalf
[1];
357 /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
358 if the upper part of reg N does not appear in the MEM, arrange to
359 emit the move late-half first. Otherwise, compute the MEM address
360 into the upper part of N and use that as a pointer to the memory
363 && (optype1
== OFFSOP
|| optype1
== MEMOP
))
365 if (reg_mentioned_p (operands
[0], XEXP (operands
[1], 0))
366 && reg_mentioned_p (latehalf
[0], XEXP (operands
[1], 0)))
368 /* If both halves of dest are used in the src memory address,
369 compute the address into latehalf of dest. */
371 xops
[0] = latehalf
[0];
372 xops
[1] = XEXP (operands
[1], 0);
373 output_asm_insn (AS2 (lea
%L0
,%a1
,%0), xops
);
374 operands
[1] = gen_rtx (MEM
, DImode
, latehalf
[0]);
375 latehalf
[1] = adj_offsettable_operand (operands
[1], 4);
377 else if (reg_mentioned_p (operands
[0], XEXP (operands
[1], 0)))
378 /* If the low half of dest is mentioned in the source memory
379 address, the arrange to emit the move late half first. */
380 dest_overlapped_low
= 1;
383 /* If one or both operands autodecrementing,
384 do the two words, high-numbered first. */
386 /* Likewise, the first move would clobber the source of the second one,
387 do them in the other order. This happens only for registers;
388 such overlap can't happen in memory unless the user explicitly
389 sets it up, and that is an undefined circumstance. */
391 if (optype0
== PUSHOP
|| optype1
== PUSHOP
392 || (optype0
== REGOP
&& optype1
== REGOP
393 && REGNO (operands
[0]) == REGNO (latehalf
[1]))
394 || dest_overlapped_low
)
396 /* Make any unoffsettable addresses point at high-numbered word. */
398 asm_add (4, addreg0
);
400 asm_add (4, addreg1
);
403 output_asm_insn (singlemove_string (latehalf
), latehalf
);
405 /* Undo the adds we just did. */
407 asm_add (-4, addreg0
);
409 asm_add (-4, addreg1
);
411 /* Do low-numbered word. */
412 return singlemove_string (operands
);
415 /* Normal case: do the two words, low-numbered first. */
417 output_asm_insn (singlemove_string (operands
), operands
);
419 /* Make any unoffsettable addresses point at high-numbered word. */
421 asm_add (4, addreg0
);
423 asm_add (4, addreg1
);
426 output_asm_insn (singlemove_string (latehalf
), latehalf
);
428 /* Undo the adds we just did. */
430 asm_add (-4, addreg0
);
432 asm_add (-4, addreg1
);
438 standard_80387_constant_p (x
)
441 #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
446 if (setjmp (handler
))
449 set_float_handler (handler
);
450 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
451 is0
= REAL_VALUES_EQUAL (d
, dconst0
);
452 is1
= REAL_VALUES_EQUAL (d
, dconst1
);
453 set_float_handler (NULL_PTR
);
461 /* Note that on the 80387, other constants, such as pi,
462 are much slower to load as standard constants
463 than to load from doubles in memory! */
470 output_move_const_single (operands
)
473 if (FP_REG_P (operands
[0]))
475 int conval
= standard_80387_constant_p (operands
[1]);
483 if (GET_CODE (operands
[1]) == CONST_DOUBLE
)
485 union { int i
[2]; double d
;} u1
;
486 union { int i
; float f
;} u2
;
487 u1
.i
[0] = CONST_DOUBLE_LOW (operands
[1]);
488 u1
.i
[1] = CONST_DOUBLE_HIGH (operands
[1]);
490 operands
[1] = GEN_INT (u2
.i
);
492 return singlemove_string (operands
);
495 /* Returns 1 if OP is either a symbol reference or a sum of a symbol
496 reference and a constant. */
499 symbolic_operand (op
, mode
)
501 enum machine_mode mode
;
503 switch (GET_CODE (op
))
510 return ((GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
511 || GET_CODE (XEXP (op
, 0)) == LABEL_REF
)
512 && GET_CODE (XEXP (op
, 1)) == CONST_INT
);
518 /* Test for a valid operand for a call instruction.
519 Don't allow the arg pointer register or virtual regs
520 since they may change into reg + const, which the patterns
524 call_insn_operand (op
, mode
)
526 enum machine_mode mode
;
528 if (GET_CODE (op
) == MEM
529 && ((CONSTANT_ADDRESS_P (XEXP (op
, 0))
530 /* This makes a difference for PIC. */
531 && general_operand (XEXP (op
, 0), Pmode
))
532 || (GET_CODE (XEXP (op
, 0)) == REG
533 && XEXP (op
, 0) != arg_pointer_rtx
534 && !(REGNO (XEXP (op
, 0)) >= FIRST_PSEUDO_REGISTER
535 && REGNO (XEXP (op
, 0)) <= LAST_VIRTUAL_REGISTER
))))
540 /* Like call_insn_operand but allow (mem (symbol_ref ...))
544 expander_call_insn_operand (op
, mode
)
546 enum machine_mode mode
;
548 if (GET_CODE (op
) == MEM
549 && (CONSTANT_ADDRESS_P (XEXP (op
, 0))
550 || (GET_CODE (XEXP (op
, 0)) == REG
551 && XEXP (op
, 0) != arg_pointer_rtx
552 && !(REGNO (XEXP (op
, 0)) >= FIRST_PSEUDO_REGISTER
553 && REGNO (XEXP (op
, 0)) <= LAST_VIRTUAL_REGISTER
))))
558 /* Returns 1 if OP contains a symbol reference */
561 symbolic_reference_mentioned_p (op
)
567 if (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == LABEL_REF
)
570 fmt
= GET_RTX_FORMAT (GET_CODE (op
));
571 for (i
= GET_RTX_LENGTH (GET_CODE (op
)) - 1; i
>= 0; i
--)
577 for (j
= XVECLEN (op
, i
) - 1; j
>= 0; j
--)
578 if (symbolic_reference_mentioned_p (XVECEXP (op
, i
, j
)))
581 else if (fmt
[i
] == 'e' && symbolic_reference_mentioned_p (XEXP (op
, i
)))
588 /* Return a legitimate reference for ORIG (an address) using the
589 register REG. If REG is 0, a new pseudo is generated.
591 There are three types of references that must be handled:
593 1. Global data references must load the address from the GOT, via
594 the PIC reg. An insn is emitted to do this load, and the reg is
597 2. Static data references must compute the address as an offset
598 from the GOT, whose base is in the PIC reg. An insn is emitted to
599 compute the address into a reg, and the reg is returned. Static
600 data objects have SYMBOL_REF_FLAG set to differentiate them from
603 3. Constant pool addresses must be handled special. They are
604 considered legitimate addresses, but only if not used with regs.
605 When printed, the output routines know to print the reference with the
606 PIC reg, even though the PIC reg doesn't appear in the RTL.
608 GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC
609 reg also appears in the address (except for constant pool references,
612 "switch" statements also require special handling when generating
613 PIC code. See comments by the `casesi' insn in i386.md for details. */
616 legitimize_pic_address (orig
, reg
)
623 if (GET_CODE (addr
) == SYMBOL_REF
|| GET_CODE (addr
) == LABEL_REF
)
625 if (GET_CODE (addr
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (addr
))
630 reg
= gen_reg_rtx (Pmode
);
632 if (GET_CODE (addr
) == SYMBOL_REF
&& SYMBOL_REF_FLAG (addr
))
633 new = gen_rtx (PLUS
, Pmode
, pic_offset_table_rtx
, orig
);
635 new = gen_rtx (MEM
, Pmode
,
636 gen_rtx (PLUS
, Pmode
,
637 pic_offset_table_rtx
, orig
));
639 emit_move_insn (reg
, new);
641 current_function_uses_pic_offset_table
= 1;
644 else if (GET_CODE (addr
) == CONST
|| GET_CODE (addr
) == PLUS
)
648 if (GET_CODE (addr
) == CONST
)
650 addr
= XEXP (addr
, 0);
651 if (GET_CODE (addr
) != PLUS
)
655 if (XEXP (addr
, 0) == pic_offset_table_rtx
)
659 reg
= gen_reg_rtx (Pmode
);
661 base
= legitimize_pic_address (XEXP (addr
, 0), reg
);
662 addr
= legitimize_pic_address (XEXP (addr
, 1),
663 base
== reg
? NULL_RTX
: reg
);
665 if (GET_CODE (addr
) == CONST_INT
)
666 return plus_constant (base
, INTVAL (addr
));
668 if (GET_CODE (addr
) == PLUS
&& CONSTANT_P (XEXP (addr
, 1)))
670 base
= gen_rtx (PLUS
, Pmode
, base
, XEXP (addr
, 0));
671 addr
= XEXP (addr
, 1);
673 return gen_rtx (PLUS
, Pmode
, base
, addr
);
678 /* Emit insns to move operands[1] into operands[0]. */
681 emit_pic_move (operands
, mode
)
683 enum machine_mode mode
;
685 rtx temp
= reload_in_progress
? operands
[0] : gen_reg_rtx (Pmode
);
687 if (GET_CODE (operands
[0]) == MEM
&& SYMBOLIC_CONST (operands
[1]))
688 operands
[1] = (rtx
) force_reg (SImode
, operands
[1]);
690 operands
[1] = legitimize_pic_address (operands
[1], temp
);
693 /* This function generates the assembly code for function entry.
694 FILE is an stdio stream to output the code to.
695 SIZE is an int: how many units of temporary storage to allocate. */
698 function_prologue (file
, size
)
705 int pic_reg_used
= flag_pic
&& (current_function_uses_pic_offset_table
706 || current_function_uses_const_pool
);
708 xops
[0] = stack_pointer_rtx
;
709 xops
[1] = frame_pointer_rtx
;
710 xops
[2] = GEN_INT (size
);
711 if (frame_pointer_needed
)
713 output_asm_insn ("push%L1 %1", xops
);
714 output_asm_insn (AS2 (mov
%L0
,%0,%1), xops
);
718 output_asm_insn (AS2 (sub
%L0
,%2,%0), xops
);
720 /* Note If use enter it is NOT reversed args.
721 This one is not reversed from intel!!
722 I think enter is slower. Also sdb doesn't like it.
723 But if you want it the code is:
725 xops[3] = const0_rtx;
726 output_asm_insn ("enter %2,%3", xops);
729 limit
= (frame_pointer_needed
? FRAME_POINTER_REGNUM
: STACK_POINTER_REGNUM
);
730 for (regno
= limit
- 1; regno
>= 0; regno
--)
731 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
732 || (regno
== PIC_OFFSET_TABLE_REGNUM
&& pic_reg_used
))
734 xops
[0] = gen_rtx (REG
, SImode
, regno
);
735 output_asm_insn ("push%L0 %0", xops
);
740 xops
[0] = pic_offset_table_rtx
;
741 xops
[1] = (rtx
) gen_label_rtx ();
743 output_asm_insn (AS1 (call
,%P1
), xops
);
744 ASM_OUTPUT_INTERNAL_LABEL (file
, "L", CODE_LABEL_NUMBER (xops
[1]));
745 output_asm_insn (AS1 (pop
%L0
,%0), xops
);
746 output_asm_insn ("addl $_GLOBAL_OFFSET_TABLE_+[.-%P1],%0", xops
);
750 /* Return 1 if it is appropriate to emit `ret' instructions in the
751 body of a function. Do this only if the epilogue is simple, needing a
752 couple of insns. Prior to reloading, we can't tell how many registers
753 must be saved, so return 0 then.
755 If NON_SAVING_SETJMP is defined and true, then it is not possible
756 for the epilogue to be simple, so return 0. This is a special case
757 since NON_SAVING_SETJMP will not cause regs_ever_live to change until
758 final, but jump_optimize may need to know sooner if a `return' is OK. */
761 simple_386_epilogue ()
765 int reglimit
= (frame_pointer_needed
766 ? FRAME_POINTER_REGNUM
: STACK_POINTER_REGNUM
);
767 int pic_reg_used
= flag_pic
&& (current_function_uses_pic_offset_table
768 || current_function_uses_const_pool
);
770 #ifdef NON_SAVING_SETJMP
771 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
775 if (! reload_completed
)
778 for (regno
= reglimit
- 1; regno
>= 0; regno
--)
779 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
780 || (regno
== PIC_OFFSET_TABLE_REGNUM
&& pic_reg_used
))
783 return nregs
== 0 || ! frame_pointer_needed
;
786 /* This function generates the assembly code for function exit.
787 FILE is an stdio stream to output the code to.
788 SIZE is an int: how many units of temporary storage to deallocate. */
791 function_epilogue (file
, size
)
796 register int nregs
, limit
;
799 int pic_reg_used
= flag_pic
&& (current_function_uses_pic_offset_table
800 || current_function_uses_const_pool
);
802 /* Compute the number of registers to pop */
804 limit
= (frame_pointer_needed
805 ? FRAME_POINTER_REGNUM
806 : STACK_POINTER_REGNUM
);
810 for (regno
= limit
- 1; regno
>= 0; regno
--)
811 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
812 || (regno
== PIC_OFFSET_TABLE_REGNUM
&& pic_reg_used
))
815 /* sp is often unreliable so we must go off the frame pointer,
818 /* In reality, we may not care if sp is unreliable, because we can
819 restore the register relative to the frame pointer. In theory,
820 since each move is the same speed as a pop, and we don't need the
821 leal, this is faster. For now restore multiple registers the old
824 offset
= -size
- (nregs
* UNITS_PER_WORD
);
826 xops
[2] = stack_pointer_rtx
;
828 if (nregs
> 1 || ! frame_pointer_needed
)
830 if (frame_pointer_needed
)
832 xops
[0] = adj_offsettable_operand (AT_BP (Pmode
), offset
);
833 output_asm_insn (AS2 (lea
%L2
,%0,%2), xops
);
836 for (regno
= 0; regno
< limit
; regno
++)
837 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
838 || (regno
== PIC_OFFSET_TABLE_REGNUM
&& pic_reg_used
))
840 xops
[0] = gen_rtx (REG
, SImode
, regno
);
841 output_asm_insn ("pop%L0 %0", xops
);
845 for (regno
= 0; regno
< limit
; regno
++)
846 if ((regs_ever_live
[regno
] && ! call_used_regs
[regno
])
847 || (regno
== PIC_OFFSET_TABLE_REGNUM
&& pic_reg_used
))
849 xops
[0] = gen_rtx (REG
, SImode
, regno
);
850 xops
[1] = adj_offsettable_operand (AT_BP (Pmode
), offset
);
851 output_asm_insn (AS2 (mov
%L0
,%1,%0), xops
);
855 if (frame_pointer_needed
)
857 /* On i486, mov & pop is faster than "leave". */
861 xops
[0] = frame_pointer_rtx
;
862 output_asm_insn (AS2 (mov
%L2
,%0,%2), xops
);
863 output_asm_insn ("pop%L0 %0", xops
);
866 output_asm_insn ("leave", xops
);
870 /* If there is no frame pointer, we must still release the frame. */
872 xops
[0] = GEN_INT (size
);
873 output_asm_insn (AS2 (add
%L2
,%0,%2), xops
);
876 if (current_function_pops_args
&& current_function_args_size
)
878 xops
[1] = GEN_INT (current_function_pops_args
);
880 /* i386 can only pop 32K bytes (maybe 64K? Is it signed?). If
881 asked to pop more, pop return address, do explicit add, and jump
882 indirectly to the caller. */
884 if (current_function_pops_args
>= 32768)
886 /* ??? Which register to use here? */
887 xops
[0] = gen_rtx (REG
, SImode
, 2);
888 output_asm_insn ("pop%L0 %0", xops
);
889 output_asm_insn (AS2 (add
%L2
,%1,%2), xops
);
890 output_asm_insn ("jmp %*%0", xops
);
893 output_asm_insn ("ret %1", xops
);
896 output_asm_insn ("ret", xops
);
899 /* Print an integer constant expression in assembler syntax. Addition
900 and subtraction are the only arithmetic that may appear in these
901 expressions. FILE is the stdio stream to write to, X is the rtx, and
902 CODE is the operand print code from the output string. */
905 output_pic_addr_const (file
, x
, code
)
912 switch (GET_CODE (x
))
923 if (GET_CODE (x
) == SYMBOL_REF
)
924 assemble_name (file
, XSTR (x
, 0));
927 ASM_GENERATE_INTERNAL_LABEL (buf
, "L",
928 CODE_LABEL_NUMBER (XEXP (x
, 0)));
929 assemble_name (asm_out_file
, buf
);
932 if (GET_CODE (x
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (x
))
933 fprintf (file
, "@GOTOFF(%%ebx)");
934 else if (code
== 'P')
935 fprintf (file
, "@PLT");
936 else if (GET_CODE (x
) == LABEL_REF
|| ! SYMBOL_REF_FLAG (x
))
937 fprintf (file
, "@GOT");
939 fprintf (file
, "@GOTOFF");
944 ASM_GENERATE_INTERNAL_LABEL (buf
, "L", CODE_LABEL_NUMBER (x
));
945 assemble_name (asm_out_file
, buf
);
949 fprintf (file
, "%d", INTVAL (x
));
953 /* This used to output parentheses around the expression,
954 but that does not work on the 386 (either ATT or BSD assembler). */
955 output_pic_addr_const (file
, XEXP (x
, 0), code
);
959 if (GET_MODE (x
) == VOIDmode
)
961 /* We can use %d if the number is <32 bits and positive. */
962 if (CONST_DOUBLE_HIGH (x
) || CONST_DOUBLE_LOW (x
) < 0)
963 fprintf (file
, "0x%x%08x",
964 CONST_DOUBLE_HIGH (x
), CONST_DOUBLE_LOW (x
));
966 fprintf (file
, "%d", CONST_DOUBLE_LOW (x
));
969 /* We can't handle floating point constants;
970 PRINT_OPERAND must handle them. */
971 output_operand_lossage ("floating constant misused");
975 /* Some assemblers need integer constants to appear last (eg masm). */
976 if (GET_CODE (XEXP (x
, 0)) == CONST_INT
)
978 output_pic_addr_const (file
, XEXP (x
, 1), code
);
979 if (INTVAL (XEXP (x
, 0)) >= 0)
981 output_pic_addr_const (file
, XEXP (x
, 0), code
);
985 output_pic_addr_const (file
, XEXP (x
, 0), code
);
986 if (INTVAL (XEXP (x
, 1)) >= 0)
988 output_pic_addr_const (file
, XEXP (x
, 1), code
);
993 output_pic_addr_const (file
, XEXP (x
, 0), code
);
995 output_pic_addr_const (file
, XEXP (x
, 1), code
);
999 output_operand_lossage ("invalid expression as operand");
1004 f -- float insn (print a CONST_DOUBLE as a float rather than in hex).
1005 D,L,W,B,Q,S -- print the opcode suffix for specified size of operand.
1006 R -- print the prefix for register names.
1007 z -- print the opcode suffix for the size of the current operand.
1008 * -- print a star (in certain assembler syntax)
1009 w -- print the operand as if it's a "word" (HImode) even if it isn't.
1010 c -- don't print special prefixes before constant operands.
1014 print_operand (file
, x
, code
)
1029 PUT_OP_SIZE (code
, 'l', file
);
1033 PUT_OP_SIZE (code
, 'w', file
);
1037 PUT_OP_SIZE (code
, 'b', file
);
1041 PUT_OP_SIZE (code
, 'l', file
);
1045 PUT_OP_SIZE (code
, 's', file
);
1049 /* 387 opcodes don't get size suffixes if the operands are
1052 if (STACK_REG_P (x
))
1055 /* this is the size of op from size of operand */
1056 switch (GET_MODE_SIZE (GET_MODE (x
)))
1059 PUT_OP_SIZE ('B', 'b', file
);
1063 PUT_OP_SIZE ('W', 'w', file
);
1067 if (GET_MODE (x
) == SFmode
)
1069 PUT_OP_SIZE ('S', 's', file
);
1073 PUT_OP_SIZE ('L', 'l', file
);
1077 if (GET_MODE_CLASS (GET_MODE (x
)) == MODE_INT
)
1079 #ifdef GAS_MNEMONICS
1080 PUT_OP_SIZE ('Q', 'q', file
);
1083 PUT_OP_SIZE ('Q', 'l', file
); /* Fall through */
1087 PUT_OP_SIZE ('Q', 'l', file
);
1103 sprintf (str
, "invalid operand code `%c'", code
);
1104 output_operand_lossage (str
);
1108 if (GET_CODE (x
) == REG
)
1110 PRINT_REG (x
, code
, file
);
1112 else if (GET_CODE (x
) == MEM
)
1114 PRINT_PTR (x
, file
);
1115 if (CONSTANT_ADDRESS_P (XEXP (x
, 0)))
1118 output_pic_addr_const (file
, XEXP (x
, 0), code
);
1120 output_addr_const (file
, XEXP (x
, 0));
1123 output_address (XEXP (x
, 0));
1125 else if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == SFmode
)
1127 union { double d
; int i
[2]; } u
;
1128 union { float f
; int i
; } u1
;
1129 u
.i
[0] = CONST_DOUBLE_LOW (x
);
1130 u
.i
[1] = CONST_DOUBLE_HIGH (x
);
1132 PRINT_IMMED_PREFIX (file
);
1133 fprintf (file
, "0x%x", u1
.i
);
1135 else if (GET_CODE (x
) == CONST_DOUBLE
&& GET_MODE (x
) == DFmode
)
1137 union { double d
; int i
[2]; } u
;
1138 u
.i
[0] = CONST_DOUBLE_LOW (x
);
1139 u
.i
[1] = CONST_DOUBLE_HIGH (x
);
1140 fprintf (file
, "%.22e", u
.d
);
1146 if (GET_CODE (x
) == CONST_INT
|| GET_CODE (x
) == CONST_DOUBLE
)
1147 PRINT_IMMED_PREFIX (file
);
1148 else if (GET_CODE (x
) == CONST
|| GET_CODE (x
) == SYMBOL_REF
1149 || GET_CODE (x
) == LABEL_REF
)
1150 PRINT_OFFSET_PREFIX (file
);
1153 output_pic_addr_const (file
, x
, code
);
1155 output_addr_const (file
, x
);
1159 /* Print a memory operand whose address is ADDR. */
1162 print_operand_address (file
, addr
)
1166 register rtx reg1
, reg2
, breg
, ireg
;
1169 switch (GET_CODE (addr
))
1173 fprintf (file
, "%se", RP
);
1174 fputs (hi_reg_name
[REGNO (addr
)], file
);
1184 if (CONSTANT_ADDRESS_P (XEXP (addr
, 0)))
1186 offset
= XEXP (addr
, 0);
1187 addr
= XEXP (addr
, 1);
1189 else if (CONSTANT_ADDRESS_P (XEXP (addr
, 1)))
1191 offset
= XEXP (addr
, 1);
1192 addr
= XEXP (addr
, 0);
1194 if (GET_CODE (addr
) != PLUS
) ;
1195 else if (GET_CODE (XEXP (addr
, 0)) == MULT
)
1197 reg1
= XEXP (addr
, 0);
1198 addr
= XEXP (addr
, 1);
1200 else if (GET_CODE (XEXP (addr
, 1)) == MULT
)
1202 reg1
= XEXP (addr
, 1);
1203 addr
= XEXP (addr
, 0);
1205 else if (GET_CODE (XEXP (addr
, 0)) == REG
)
1207 reg1
= XEXP (addr
, 0);
1208 addr
= XEXP (addr
, 1);
1210 else if (GET_CODE (XEXP (addr
, 1)) == REG
)
1212 reg1
= XEXP (addr
, 1);
1213 addr
= XEXP (addr
, 0);
1215 if (GET_CODE (addr
) == REG
|| GET_CODE (addr
) == MULT
)
1217 if (reg1
== 0) reg1
= addr
;
1223 if (addr
!= 0) abort ();
1226 if ((reg1
&& GET_CODE (reg1
) == MULT
)
1227 || (reg2
!= 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2
))))
1232 else if (reg1
!= 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1
)))
1238 if (ireg
!= 0 || breg
!= 0)
1244 if (GET_CODE (addr
) == LABEL_REF
)
1245 output_asm_label (addr
);
1249 output_pic_addr_const (file
, addr
, 0);
1251 output_addr_const (file
, addr
);
1255 if (ireg
!= 0 && GET_CODE (ireg
) == MULT
)
1257 scale
= INTVAL (XEXP (ireg
, 1));
1258 ireg
= XEXP (ireg
, 0);
1261 /* The stack pointer can only appear as a base register,
1262 never an index register, so exchange the regs if it is wrong. */
1264 if (scale
== 1 && ireg
&& REGNO (ireg
) == STACK_POINTER_REGNUM
)
1273 /* output breg+ireg*scale */
1274 PRINT_B_I_S (breg
, ireg
, scale
, file
);
1281 if (GET_CODE (XEXP (addr
, 0)) == CONST_INT
)
1283 scale
= INTVAL (XEXP (addr
, 0));
1284 ireg
= XEXP (addr
, 1);
1288 scale
= INTVAL (XEXP (addr
, 1));
1289 ireg
= XEXP (addr
, 0);
1291 output_addr_const (file
, const0_rtx
);
1292 PRINT_B_I_S ((rtx
) 0, ireg
, scale
, file
);
1297 if (GET_CODE (addr
) == CONST_INT
1298 && INTVAL (addr
) < 0x8000
1299 && INTVAL (addr
) >= -0x8000)
1300 fprintf (file
, "%d", INTVAL (addr
));
1304 output_pic_addr_const (file
, addr
, 0);
1306 output_addr_const (file
, addr
);
1311 /* Set the cc_status for the results of an insn whose pattern is EXP.
1312 On the 80386, we assume that only test and compare insns, as well
1313 as SI, HI, & DI mode ADD, SUB, NEG, AND, IOR, XOR, ASHIFT, LSHIFT,
1314 ASHIFTRT, and LSHIFTRT instructions set the condition codes usefully.
1315 Also, we assume that jumps, moves and sCOND don't affect the condition
1316 codes. All else clobbers the condition codes, by assumption.
1318 We assume that ALL integer add, minus, etc. instructions effect the
1319 condition codes. This MUST be consistent with i386.md.
1321 We don't record any float test or compare - the redundant test &
1322 compare check in final.c does not handle stack-like regs correctly. */
1325 notice_update_cc (exp
)
1328 if (GET_CODE (exp
) == SET
)
1330 /* Jumps do not alter the cc's. */
1331 if (SET_DEST (exp
) == pc_rtx
)
1333 /* Moving register or memory into a register:
1334 it doesn't alter the cc's, but it might invalidate
1335 the RTX's which we remember the cc's came from.
1336 (Note that moving a constant 0 or 1 MAY set the cc's). */
1337 if (REG_P (SET_DEST (exp
))
1338 && (REG_P (SET_SRC (exp
)) || GET_CODE (SET_SRC (exp
)) == MEM
1339 || GET_RTX_CLASS (GET_CODE (SET_SRC (exp
))) == '<'))
1341 if (cc_status
.value1
1342 && reg_overlap_mentioned_p (SET_DEST (exp
), cc_status
.value1
))
1343 cc_status
.value1
= 0;
1344 if (cc_status
.value2
1345 && reg_overlap_mentioned_p (SET_DEST (exp
), cc_status
.value2
))
1346 cc_status
.value2
= 0;
1349 /* Moving register into memory doesn't alter the cc's.
1350 It may invalidate the RTX's which we remember the cc's came from. */
1351 if (GET_CODE (SET_DEST (exp
)) == MEM
1352 && (REG_P (SET_SRC (exp
))
1353 || GET_RTX_CLASS (GET_CODE (SET_SRC (exp
))) == '<'))
1355 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == MEM
)
1356 cc_status
.value1
= 0;
1357 if (cc_status
.value2
&& GET_CODE (cc_status
.value2
) == MEM
)
1358 cc_status
.value2
= 0;
1361 /* Function calls clobber the cc's. */
1362 else if (GET_CODE (SET_SRC (exp
)) == CALL
)
1367 /* Tests and compares set the cc's in predictable ways. */
1368 else if (SET_DEST (exp
) == cc0_rtx
)
1371 cc_status
.value1
= SET_SRC (exp
);
1374 /* Certain instructions effect the condition codes. */
1375 else if (GET_MODE (SET_SRC (exp
)) == SImode
1376 || GET_MODE (SET_SRC (exp
)) == HImode
1377 || GET_MODE (SET_SRC (exp
)) == QImode
)
1378 switch (GET_CODE (SET_SRC (exp
)))
1380 case ASHIFTRT
: case LSHIFTRT
:
1381 case ASHIFT
: case LSHIFT
:
1382 /* Shifts on the 386 don't set the condition codes if the
1383 shift count is zero. */
1384 if (GET_CODE (XEXP (SET_SRC (exp
), 1)) != CONST_INT
)
1389 /* We assume that the CONST_INT is non-zero (this rtx would
1390 have been deleted if it were zero. */
1392 case PLUS
: case MINUS
: case NEG
:
1393 case AND
: case IOR
: case XOR
:
1394 cc_status
.flags
= CC_NO_OVERFLOW
;
1395 cc_status
.value1
= SET_SRC (exp
);
1396 cc_status
.value2
= SET_DEST (exp
);
1407 else if (GET_CODE (exp
) == PARALLEL
1408 && GET_CODE (XVECEXP (exp
, 0, 0)) == SET
)
1410 if (SET_DEST (XVECEXP (exp
, 0, 0)) == pc_rtx
)
1412 if (SET_DEST (XVECEXP (exp
, 0, 0)) == cc0_rtx
)
1415 if (stack_regs_mentioned_p (SET_SRC (XVECEXP (exp
, 0, 0))))
1416 cc_status
.flags
|= CC_IN_80387
;
1418 cc_status
.value1
= SET_SRC (XVECEXP (exp
, 0, 0));
1429 /* Split one or more DImode RTL references into pairs of SImode
1430 references. The RTL can be REG, offsettable MEM, integer constant, or
1431 CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to
1432 split and "num" is its length. lo_half and hi_half are output arrays
1433 that parallel "operands". */
1436 split_di (operands
, num
, lo_half
, hi_half
)
1439 rtx lo_half
[], hi_half
[];
1443 if (GET_CODE (operands
[num
]) == REG
)
1445 lo_half
[num
] = gen_rtx (REG
, SImode
, REGNO (operands
[num
]));
1446 hi_half
[num
] = gen_rtx (REG
, SImode
, REGNO (operands
[num
]) + 1);
1448 else if (CONSTANT_P (operands
[num
]))
1450 split_double (operands
[num
], &lo_half
[num
], &hi_half
[num
]);
1452 else if (offsettable_memref_p (operands
[num
]))
1454 lo_half
[num
] = operands
[num
];
1455 hi_half
[num
] = adj_offsettable_operand (operands
[num
], 4);
1462 /* Return 1 if this is a valid binary operation on a 387.
1463 OP is the expression matched, and MODE is its mode. */
1466 binary_387_op (op
, mode
)
1468 enum machine_mode mode
;
1470 if (mode
!= VOIDmode
&& mode
!= GET_MODE (op
))
1473 switch (GET_CODE (op
))
1479 return GET_MODE_CLASS (GET_MODE (op
)) == MODE_FLOAT
;
1486 /* Return 1 if this is a valid conversion operation on a 387.
1487 OP is the expression matched, and MODE is its mode. */
1490 convert_387_op (op
, mode
)
1492 enum machine_mode mode
;
1494 if (mode
!= VOIDmode
&& mode
!= GET_MODE (op
))
1497 switch (GET_CODE (op
))
1500 return GET_MODE (XEXP (op
, 0)) == SImode
;
1503 return mode
== DFmode
&& GET_MODE (XEXP (op
, 0)) == SFmode
;
1510 /* Return 1 if this is a valid shift or rotate operation on a 386.
1511 OP is the expression matched, and MODE is its mode. */
1516 enum machine_mode mode
;
1518 rtx operand
= XEXP (op
, 0);
1520 if (mode
!= VOIDmode
&& mode
!= GET_MODE (op
))
1523 if (GET_MODE (operand
) != GET_MODE (op
)
1524 || GET_MODE_CLASS (GET_MODE (op
)) != MODE_INT
)
1527 return (GET_CODE (op
) == ASHIFT
1528 || GET_CODE (op
) == ASHIFTRT
1529 || GET_CODE (op
) == LSHIFTRT
1530 || GET_CODE (op
) == ROTATE
1531 || GET_CODE (op
) == ROTATERT
);
1534 /* Return 1 if OP is COMPARE rtx with mode VOIDmode.
1535 MODE is not used. */
1538 VOIDmode_compare_op (op
, mode
)
1540 enum machine_mode mode
;
1542 return GET_CODE (op
) == COMPARE
&& GET_MODE (op
) == VOIDmode
;
1545 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
1546 MINUS, MULT or DIV. OPERANDS are the insn operands, where operands[3]
1547 is the expression of the binary operation. The output may either be
1548 emitted here, or returned to the caller, like all output_* functions.
1550 There is no guarantee that the operands are the same mode, as they
1551 might be within FLOAT or FLOAT_EXTEND expressions. */
1554 output_387_binary_op (insn
, operands
)
1560 static char buf
[100];
1562 switch (GET_CODE (operands
[3]))
1565 if (GET_MODE_CLASS (GET_MODE (operands
[1])) == MODE_INT
1566 || GET_MODE_CLASS (GET_MODE (operands
[2])) == MODE_INT
)
1573 if (GET_MODE_CLASS (GET_MODE (operands
[1])) == MODE_INT
1574 || GET_MODE_CLASS (GET_MODE (operands
[2])) == MODE_INT
)
1581 if (GET_MODE_CLASS (GET_MODE (operands
[1])) == MODE_INT
1582 || GET_MODE_CLASS (GET_MODE (operands
[2])) == MODE_INT
)
1589 if (GET_MODE_CLASS (GET_MODE (operands
[1])) == MODE_INT
1590 || GET_MODE_CLASS (GET_MODE (operands
[2])) == MODE_INT
)
1600 strcpy (buf
, base_op
);
1602 switch (GET_CODE (operands
[3]))
1606 if (REG_P (operands
[2]) && REGNO (operands
[0]) == REGNO (operands
[2]))
1609 operands
[2] = operands
[1];
1613 if (GET_CODE (operands
[2]) == MEM
)
1614 return strcat (buf
, AS1 (%z2
,%2));
1616 if (NON_STACK_REG_P (operands
[1]))
1618 output_op_from_reg (operands
[1], strcat (buf
, AS1 (%z0
,%1)));
1621 else if (NON_STACK_REG_P (operands
[2]))
1623 output_op_from_reg (operands
[2], strcat (buf
, AS1 (%z0
,%1)));
1627 if (find_regno_note (insn
, REG_DEAD
, REGNO (operands
[2])))
1628 return strcat (buf
, AS2 (p
,%2,%0));
1630 if (STACK_TOP_P (operands
[0]))
1631 return strcat (buf
, AS2 (,%y2
,%0));
1633 return strcat (buf
, AS2 (,%2,%0));
1637 if (GET_CODE (operands
[1]) == MEM
)
1638 return strcat (buf
, AS1 (r
%z1
,%1));
1640 if (GET_CODE (operands
[2]) == MEM
)
1641 return strcat (buf
, AS1 (%z2
,%2));
1643 if (NON_STACK_REG_P (operands
[1]))
1645 output_op_from_reg (operands
[1], strcat (buf
, AS1 (r
%z0
,%1)));
1648 else if (NON_STACK_REG_P (operands
[2]))
1650 output_op_from_reg (operands
[2], strcat (buf
, AS1 (%z0
,%1)));
1654 if (! STACK_REG_P (operands
[1]) || ! STACK_REG_P (operands
[2]))
1657 if (find_regno_note (insn
, REG_DEAD
, REGNO (operands
[2])))
1658 return strcat (buf
, AS2 (rp
,%2,%0));
1660 if (find_regno_note (insn
, REG_DEAD
, REGNO (operands
[1])))
1661 return strcat (buf
, AS2 (p
,%1,%0));
1663 if (STACK_TOP_P (operands
[0]))
1665 if (STACK_TOP_P (operands
[1]))
1666 return strcat (buf
, AS2 (,%y2
,%0));
1668 return strcat (buf
, AS2 (r
,%y1
,%0));
1670 else if (STACK_TOP_P (operands
[1]))
1671 return strcat (buf
, AS2 (,%1,%0));
1673 return strcat (buf
, AS2 (r
,%2,%0));
1680 /* Output code for INSN to convert a float to a signed int. OPERANDS
1681 are the insn operands. The output may be SFmode or DFmode and the
1682 input operand may be SImode or DImode. As a special case, make sure
1683 that the 387 stack top dies if the output mode is DImode, because the
1684 hardware requires this. */
1687 output_fix_trunc (insn
, operands
)
1691 int stack_top_dies
= find_regno_note (insn
, REG_DEAD
, FIRST_STACK_REG
) != 0;
1694 if (! STACK_TOP_P (operands
[1]) ||
1695 (GET_MODE (operands
[0]) == DImode
&& ! stack_top_dies
))
1698 xops
[0] = GEN_INT (12);
1699 xops
[1] = operands
[4];
1701 output_asm_insn (AS1 (fnstc
%W2
,%2), operands
);
1702 output_asm_insn (AS2 (mov
%L2
,%2,%4), operands
);
1703 output_asm_insn (AS2 (mov
%B1
,%0,%h1
), xops
);
1704 output_asm_insn (AS2 (mov
%L4
,%4,%3), operands
);
1705 output_asm_insn (AS1 (fldc
%W3
,%3), operands
);
1707 if (NON_STACK_REG_P (operands
[0]))
1708 output_to_reg (operands
[0], stack_top_dies
);
1709 else if (GET_CODE (operands
[0]) == MEM
)
1712 output_asm_insn (AS1 (fistp
%z0
,%0), operands
);
1714 output_asm_insn (AS1 (fist
%z0
,%0), operands
);
1719 return AS1 (fldc
%W2
,%2);
1722 /* Output code for INSN to compare OPERANDS. The two operands might
1723 not have the same mode: one might be within a FLOAT or FLOAT_EXTEND
1724 expression. If the compare is in mode CCFPEQmode, use an opcode that
1725 will not fault if a qNaN is present. */
1728 output_float_compare (insn
, operands
)
1733 rtx body
= XVECEXP (PATTERN (insn
), 0, 0);
1734 int unordered_compare
= GET_MODE (SET_SRC (body
)) == CCFPEQmode
;
1736 if (! STACK_TOP_P (operands
[0]))
1739 stack_top_dies
= find_regno_note (insn
, REG_DEAD
, FIRST_STACK_REG
) != 0;
1741 if (STACK_REG_P (operands
[1])
1743 && find_regno_note (insn
, REG_DEAD
, REGNO (operands
[1]))
1744 && REGNO (operands
[1]) != FIRST_STACK_REG
)
1746 /* If both the top of the 387 stack dies, and the other operand
1747 is also a stack register that dies, then this must be a
1748 `fcompp' float compare */
1750 if (unordered_compare
)
1751 output_asm_insn ("fucompp", operands
);
1753 output_asm_insn ("fcompp", operands
);
1757 static char buf
[100];
1759 /* Decide if this is the integer or float compare opcode, or the
1760 unordered float compare. */
1762 if (unordered_compare
)
1763 strcpy (buf
, "fucom");
1764 else if (GET_MODE_CLASS (GET_MODE (operands
[1])) == MODE_FLOAT
)
1765 strcpy (buf
, "fcom");
1767 strcpy (buf
, "ficom");
1769 /* Modify the opcode if the 387 stack is to be popped. */
1774 if (NON_STACK_REG_P (operands
[1]))
1775 output_op_from_reg (operands
[1], strcat (buf
, AS1 (%z0
,%1)));
1777 output_asm_insn (strcat (buf
, AS1 (%z1
,%y1
)), operands
);
1780 /* Now retrieve the condition code. */
1782 return output_fp_cc0_set (insn
);
1785 /* Output opcodes to transfer the results of FP compare or test INSN
1786 from the FPU to the CPU flags. If TARGET_IEEE_FP, ensure that if the
1787 result of the compare or test is unordered, no comparison operator
1788 succeeds except NE. Return an output template, if any. */
1791 output_fp_cc0_set (insn
)
1795 rtx unordered_label
;
1799 xops
[0] = gen_rtx (REG
, HImode
, 0);
1800 output_asm_insn (AS1 (fnsts
%W0
,%0), xops
);
1802 if (! TARGET_IEEE_FP
)
1805 next
= next_cc0_user (insn
);
1806 if (next
== NULL_RTX
)
1809 if (GET_CODE (next
) == JUMP_INSN
1810 && GET_CODE (PATTERN (next
)) == SET
1811 && SET_DEST (PATTERN (next
)) == pc_rtx
1812 && GET_CODE (SET_SRC (PATTERN (next
))) == IF_THEN_ELSE
)
1814 code
= GET_CODE (XEXP (SET_SRC (PATTERN (next
)), 0));
1816 else if (GET_CODE (PATTERN (next
)) == SET
)
1818 code
= GET_CODE (SET_SRC (PATTERN (next
)));
1823 xops
[0] = gen_rtx (REG
, QImode
, 0);
1828 xops
[1] = GEN_INT (0x45);
1829 output_asm_insn (AS2 (and%B0
,%1,%h0
), xops
);
1834 xops
[1] = GEN_INT (0x45);
1835 xops
[2] = GEN_INT (0x01);
1836 output_asm_insn (AS2 (and%B0
,%1,%h0
), xops
);
1837 output_asm_insn (AS2 (cmp
%B0
,%2,%h0
), xops
);
1842 xops
[1] = GEN_INT (0x05);
1843 output_asm_insn (AS2 (and%B0
,%1,%h0
), xops
);
1848 xops
[1] = GEN_INT (0x45);
1849 xops
[2] = GEN_INT (0x40);
1850 output_asm_insn (AS2 (and%B0
,%1,%h0
), xops
);
1851 output_asm_insn (AS1 (dec
%B0
,%h0
), xops
);
1852 output_asm_insn (AS2 (cmp
%B0
,%2,%h0
), xops
);
1857 xops
[1] = GEN_INT (0x45);
1858 xops
[2] = GEN_INT (0x40);
1859 output_asm_insn (AS2 (and%B0
,%1,%h0
), xops
);
1860 output_asm_insn (AS2 (cmp
%B0
,%2,%h0
), xops
);
1865 xops
[1] = GEN_INT (0x44);
1866 xops
[2] = GEN_INT (0x40);
1867 output_asm_insn (AS2 (and%B0
,%1,%h0
), xops
);
1868 output_asm_insn (AS2 (xor%B0
,%2,%h0
), xops
);
1882 #define MAX_386_STACK_LOCALS 2
1884 static rtx i386_stack_locals
[(int) MAX_MACHINE_MODE
][MAX_386_STACK_LOCALS
];
1886 /* Clear stack slot assignments remembered from previous functions.
1887 This is called from INIT_EXPANDERS once before RTL is emitted for each
1891 clear_386_stack_locals ()
1893 enum machine_mode mode
;
1896 for (mode
= VOIDmode
; (int) mode
< (int) MAX_MACHINE_MODE
;
1897 mode
= (enum machine_mode
) ((int) mode
+ 1))
1898 for (n
= 0; n
< MAX_386_STACK_LOCALS
; n
++)
1899 i386_stack_locals
[(int) mode
][n
] = NULL_RTX
;
1902 /* Return a MEM corresponding to a stack slot with mode MODE.
1903 Allocate a new slot if necessary.
1905 The RTL for a function can have several slots available: N is
1906 which slot to use. */
1909 assign_386_stack_local (mode
, n
)
1910 enum machine_mode mode
;
1913 if (n
< 0 || n
>= MAX_386_STACK_LOCALS
)
1916 if (i386_stack_locals
[(int) mode
][n
] == NULL_RTX
)
1917 i386_stack_locals
[(int) mode
][n
]
1918 = assign_stack_local (mode
, GET_MODE_SIZE (mode
), 0);
1920 return i386_stack_locals
[(int) mode
][n
];