1 /* Subroutines for assembler code output on the NS32000.
2 Copyright (C) 1988, 1994, 1995 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Some output-actions in ns32k.md need these. */
26 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-flags.h"
32 #include "insn-attr.h"
35 int ns32k_num_files = 0;
42 fprintf (stderr, s, s1, s2);
45 /* Value is 1 if hard register REGNO can hold a value of machine-mode MODE. */
48 hard_regno_mode_ok (regno, mode)
50 enum machine_mode mode;
61 if (regno < 8 || regno == 16 || regno == 17)
67 if (regno < 8 && (regno & 1) == 0)
112 /* Used to abort here, but simply saying "no" handles TImode
117 /* ADDRESS_COST calls this. This function is not optimal
118 for the 32032 & 32332, but it probably is better than
122 calc_address_cost (operand)
128 if (GET_CODE (operand) == MEM)
130 if (GET_CODE (operand) == MULT)
133 if (GET_CODE (operand) == REG)
134 cost += 1; /* not really, but the documentation
135 says different amount of registers
136 shouldn't return the same costs */
138 switch (GET_CODE (operand))
152 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (operand)); i++)
154 cost += calc_address_cost (XEXP (operand, i));
162 /* Return the register class of a scratch register needed to copy IN into
163 or out of a register in CLASS in MODE. If it can be done directly,
164 NO_REGS is returned. */
167 secondary_reload_class (class, mode, in)
168 enum reg_class class;
169 enum machine_mode mode;
172 int regno = true_regnum (in);
174 if (regno >= FIRST_PSEUDO_REGISTER)
177 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
179 if (class == GENERAL_REGS || (regno >= 0 && regno < 8))
182 /* Constants, memory, and FP registers can go into FP registers. */
183 if ((regno == -1 || (regno >= 8 && regno < 16)) && (class == FLOAT_REGS))
186 #if 0 /* This isn't strictly true (can't move fp to sp or vice versa),
187 so it's cleaner to use PREFERRED_RELOAD_CLASS
188 to make the right things happen. */
189 if (regno >= 16 && class == GEN_AND_MEM_REGS)
193 /* Otherwise, we need GENERAL_REGS. */
196 /* Generate the rtx that comes from an address expression in the md file */
197 /* The expression to be build is BASE[INDEX:SCALE]. To recognize this,
198 scale must be converted from an exponent (from ASHIFT) to a
199 multiplier (for MULT). */
201 gen_indexed_expr (base, index, scale)
202 rtx base, index, scale;
206 /* This generates an invalid addressing mode, if BASE is
207 fp or sp. This is handled by PRINT_OPERAND_ADDRESS. */
208 if (GET_CODE (base) != REG && GET_CODE (base) != CONST_INT)
209 base = gen_rtx (MEM, SImode, base);
210 addr = gen_rtx (MULT, SImode, index,
211 gen_rtx (CONST_INT, VOIDmode, 1 << INTVAL (scale)));
212 addr = gen_rtx (PLUS, SImode, base, addr);
216 /* Return 1 if OP is a valid operand of mode MODE. This
217 predicate rejects operands which do not have a mode
218 (such as CONST_INT which are VOIDmode). */
220 reg_or_mem_operand (op, mode)
222 enum machine_mode mode;
224 return (GET_MODE (op) == mode
225 && (GET_CODE (op) == REG
226 || GET_CODE (op) == SUBREG
227 || GET_CODE (op) == MEM));
230 /* Return the best assembler insn template
231 for moving operands[1] into operands[0] as a fullword. */
234 singlemove_string (operands)
237 if (GET_CODE (operands[1]) == CONST_INT
238 && INTVAL (operands[1]) <= 7
239 && INTVAL (operands[1]) >= -8)
240 return "movqd %1,%0";
245 output_move_double (operands)
248 enum anon1 { REGOP, OFFSOP, PUSHOP, CNSTOP, RNDOP } optype0, optype1;
251 /* First classify both operands. */
253 if (REG_P (operands[0]))
255 else if (offsettable_memref_p (operands[0]))
257 else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
262 if (REG_P (operands[1]))
264 else if (CONSTANT_P (operands[1])
265 || GET_CODE (operands[1]) == CONST_DOUBLE)
267 else if (offsettable_memref_p (operands[1]))
269 else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
274 /* Check for the cases that the operand constraints are not
275 supposed to allow to happen. Abort if we get one,
276 because generating code for these cases is painful. */
278 if (optype0 == RNDOP || optype1 == RNDOP)
281 /* Ok, we can do one word at a time.
282 Normally we do the low-numbered word first,
283 but if either operand is autodecrementing then we
284 do the high-numbered word first.
286 In either case, set up in LATEHALF the operands to use
287 for the high-numbered word and in some cases alter the
288 operands in OPERANDS to be suitable for the low-numbered word. */
290 if (optype0 == REGOP)
291 latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1);
292 else if (optype0 == OFFSOP)
293 latehalf[0] = adj_offsettable_operand (operands[0], 4);
295 latehalf[0] = operands[0];
297 if (optype1 == REGOP)
298 latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
299 else if (optype1 == OFFSOP)
300 latehalf[1] = adj_offsettable_operand (operands[1], 4);
301 else if (optype1 == CNSTOP)
302 split_double (operands[1], &operands[1], &latehalf[1]);
304 latehalf[1] = operands[1];
306 /* If insn is effectively movd N(sp),tos then we will do the
307 high word first. We should use the adjusted operand 1 (which is N+4(sp))
308 for the low word as well, to compensate for the first decrement of sp.
309 Given this, it doesn't matter which half we do "first". */
310 if (optype0 == PUSHOP
311 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
312 && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
313 operands[1] = latehalf[1];
315 /* If one or both operands autodecrementing,
316 do the two words, high-numbered first. */
317 else if (optype0 == PUSHOP || optype1 == PUSHOP)
319 output_asm_insn (singlemove_string (latehalf), latehalf);
320 return singlemove_string (operands);
323 /* If the first move would clobber the source of the second one,
324 do them in the other order. */
326 /* Overlapping registers. */
327 if (optype0 == REGOP && optype1 == REGOP
328 && REGNO (operands[0]) == REGNO (latehalf[1]))
331 output_asm_insn (singlemove_string (latehalf), latehalf);
332 /* Do low-numbered word. */
333 return singlemove_string (operands);
335 /* Loading into a register which overlaps a register used in the address. */
336 else if (optype0 == REGOP && optype1 != REGOP
337 && reg_overlap_mentioned_p (operands[0], operands[1]))
339 if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))
340 && reg_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
342 /* If both halves of dest are used in the src memory address,
343 load the destination address into the low reg (operands[0]).
344 Then it works to load latehalf first. */
346 xops[0] = XEXP (operands[1], 0);
347 xops[1] = operands[0];
348 output_asm_insn ("addr %a0,%1", xops);
349 operands[1] = gen_rtx (MEM, DImode, operands[0]);
350 latehalf[1] = adj_offsettable_operand (operands[1], 4);
351 /* The first half has the overlap, Do the late half first. */
352 output_asm_insn (singlemove_string (latehalf), latehalf);
354 return singlemove_string (operands);
356 if (reg_mentioned_p (operands[0], XEXP (operands[1], 0)))
358 /* The first half has the overlap, Do the late half first. */
359 output_asm_insn (singlemove_string (latehalf), latehalf);
361 return singlemove_string (operands);
365 /* Normal case. Do the two words, low-numbered first. */
367 output_asm_insn (singlemove_string (operands), operands);
369 operands[0] = latehalf[0];
370 operands[1] = latehalf[1];
371 return singlemove_string (operands);
375 check_reg (oper, reg)
383 switch (GET_CODE(oper))
386 return (REGNO(oper) == reg) ? 1 : 0;
388 return check_reg(XEXP(oper, 0), reg);
391 return check_reg(XEXP(oper, 0), reg) || check_reg(XEXP(oper, 1), reg);
396 /* Returns 1 if OP contains a global symbol reference */
399 global_symbolic_reference_mentioned_p (op, f)
406 if (GET_CODE (op) == SYMBOL_REF)
408 if (! SYMBOL_REF_FLAG (op))
413 else if (f && GET_CODE (op) != CONST)
416 fmt = GET_RTX_FORMAT (GET_CODE (op));
417 for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
423 for (j = XVECLEN (op, i) - 1; j >= 0; j--)
424 if (global_symbolic_reference_mentioned_p (XVECEXP (op, i, j), 0))
427 else if (fmt[i] == 'e'
428 && global_symbolic_reference_mentioned_p (XEXP (op, i), 0))
436 /* PRINT_OPERAND is defined to call this function,
437 which is easier to debug than putting all the code in
438 a macro definition in ns32k.h. */
441 print_operand (file, x, code)
447 PUT_IMMEDIATE_PREFIX (file);
448 else if (code == '?')
449 PUT_EXTERNAL_PREFIX (file);
450 else if (GET_CODE (x) == REG)
451 fprintf (file, "%s", reg_names[REGNO (x)]);
452 else if (GET_CODE (x) == MEM)
454 rtx tmp = XEXP (x, 0);
455 output_address (XEXP (x, 0));
457 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
459 if (GET_MODE (x) == DFmode)
461 union { double d; int i[2]; } u;
462 u.i[0] = CONST_DOUBLE_LOW (x); u.i[1] = CONST_DOUBLE_HIGH (x);
463 PUT_IMMEDIATE_PREFIX(file);
465 /* Sequent likes it's floating point constants as integers */
466 fprintf (file, "0Dx%08x%08x", u.i[1], u.i[0]);
469 fprintf (file, "0f%.20e", u.d);
471 fprintf (file, "0d%.20e", u.d);
477 union { double d; int i[2]; } u;
478 u.i[0] = CONST_DOUBLE_LOW (x); u.i[1] = CONST_DOUBLE_HIGH (x);
479 PUT_IMMEDIATE_PREFIX (file);
481 /* We have no way of winning if we can't get the bits
482 for a sequent floating point number. */
483 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
487 union { float f; long l; } uu;
489 fprintf (file, "0Fx%08x", uu.l);
492 fprintf (file, "0f%.20e", u.d);
498 #ifdef NO_IMMEDIATE_PREFIX_IF_SYMBOLIC
499 if (GET_CODE (x) == CONST_INT)
501 PUT_IMMEDIATE_PREFIX (file);
502 output_addr_const (file, x);
506 /* PRINT_OPERAND_ADDRESS is defined to call this function,
507 which is easier to debug than putting all the code in
508 a macro definition in ns32k.h . */
510 /* Completely rewritten to get this to work with Gas for PC532 Mach.
511 This function didn't work and I just wasn't able (nor very willing) to
512 figure out how it worked.
513 90-11-25 Tatu Yl|nen <ylo@cs.hut.fi> */
515 print_operand_address (file, addr)
519 static char scales[] = { 'b', 'w', 'd', 0, 'q', };
520 rtx offset, base, indexexp, tmp;
524 if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == POST_DEC)
526 fprintf (file, "tos");
535 if (GET_CODE (addr) == PLUS)
537 if (GET_CODE (XEXP (addr, 0)) == PLUS)
539 tmp = XEXP (addr, 1);
540 addr = XEXP (addr, 0);
545 addr = XEXP (addr,1);
553 switch (GET_CODE (tmp))
587 if (flag_pic && ! CONSTANT_POOL_ADDRESS_P (tmp)
588 && ! SYMBOL_REF_FLAG (tmp))
600 if (flag_pic && GET_CODE (tmp) == CONST)
604 if (GET_CODE (tmp1) != PLUS)
608 if (GET_CODE (sym) != SYMBOL_REF)
615 if (GET_CODE (sym) == SYMBOL_REF)
617 if (GET_CODE (off) != CONST_INT)
620 if (CONSTANT_POOL_ADDRESS_P (sym)
621 || SYMBOL_REF_FLAG (sym))
623 SYMBOL_REF_FLAG (tmp) = 1;
647 offset = gen_rtx (PLUS, SImode, tmp, offset);
659 #ifndef INDEX_RATHER_THAN_BASE
660 && (flag_pic || TARGET_HIMEM)
661 && GET_CODE (base) != SYMBOL_REF
662 && GET_CODE (offset) != CONST_INT
664 /* This is a re-implementation of the SEQUENT_ADDRESS_BUG fix. */
666 && !indexexp && GET_CODE (base) == REG
667 && REG_OK_FOR_INDEX_P (base))
673 /* now, offset, base and indexexp are set */
674 #ifndef BASE_REG_NEEDED
677 #if defined (PC_RELATIVE) || defined (NO_ABSOLUTE_PREFIX_IF_SYMBOLIC)
678 if (GET_CODE (offset) == CONST_INT)
680 PUT_ABSOLUTE_PREFIX (file);
684 output_addr_const (file, offset);
685 if (base) /* base can be (REG ...) or (MEM ...) */
686 switch (GET_CODE (base))
688 /* now we must output base. Possible alternatives are:
692 (pc) (REG ...) used for SYMBOL_REF and LABEL_REF, output
693 (disp(fp)) (MEM ...) just before possible [rX:y]
698 fprintf (file, "(%s)", reg_names[REGNO (base)]);
705 output_addr_const (file, base);
706 fprintf (file, "(sb))");
714 if (GET_CODE (addr) == PLUS)
716 if (GET_CODE (XEXP (addr, 0)) == PLUS)
718 tmp = XEXP (addr, 1);
719 addr = XEXP (addr, 0);
723 tmp = XEXP (addr, 0);
724 addr = XEXP (addr, 1);
732 switch (GET_CODE (tmp))
742 offset = gen_rtx (PLUS, SImode, tmp, offset);
753 output_addr_const (file, offset);
755 fprintf (file, "(%s)", reg_names[REGNO (base)]);
757 fprintf (file, "(sb)");
766 else if (GET_CODE (offset) != CONST_INT)
767 fprintf (file, "(pc)");
768 #ifdef BASE_REG_NEEDED
770 fprintf (file, "(sb)");
774 #endif /* PC_RELATIVE */
776 /* now print index if we have one */
779 if (GET_CODE (indexexp) == MULT)
781 scale = INTVAL (XEXP (indexexp, 1)) >> 1;
782 indexexp = XEXP (indexexp, 0);
786 if (GET_CODE (indexexp) != REG || REGNO (indexexp) >= 8)
790 fprintf (file, "[%c`%s]",
792 reg_names[REGNO (indexexp)]);
794 fprintf (file, "[%s:%c]",
795 reg_names[REGNO (indexexp)],
801 /* National 32032 shifting is so bad that we can get
802 better performance in many common cases by using other
805 output_shift_insn (operands)
808 if (GET_CODE (operands[2]) == CONST_INT
809 && INTVAL (operands[2]) > 0
810 && INTVAL (operands[2]) <= 3)
811 if (GET_CODE (operands[0]) == REG)
813 if (GET_CODE (operands[1]) == REG)
815 if (REGNO (operands[0]) == REGNO (operands[1]))
817 if (operands[2] == const1_rtx)
819 else if (INTVAL (operands[2]) == 2)
820 return "addd %0,%0\n\taddd %0,%0";
822 if (operands[2] == const1_rtx)
823 return "movd %1,%0\n\taddd %0,%0";
825 operands[1] = gen_indexed_expr (const0_rtx, operands[1], operands[2]);
826 return "addr %a1,%0";
828 if (operands[2] == const1_rtx)
829 return "movd %1,%0\n\taddd %0,%0";
831 else if (GET_CODE (operands[1]) == REG)
833 operands[1] = gen_indexed_expr (const0_rtx, operands[1], operands[2]);
834 return "addr %a1,%0";
836 else if (INTVAL (operands[2]) == 1
837 && GET_CODE (operands[1]) == MEM
838 && rtx_equal_p (operands [0], operands[1]))
840 rtx temp = XEXP (operands[1], 0);
842 if (GET_CODE (temp) == REG
843 || (GET_CODE (temp) == PLUS
844 && GET_CODE (XEXP (temp, 0)) == REG
845 && GET_CODE (XEXP (temp, 1)) == CONST_INT))
848 else return "ashd %2,%0";
853 output_move_dconst (n, s)
860 strcpy (r, "movqd ");
861 else if (n > 0 && n < 256)
862 strcpy (r, "movzbd ");
863 else if (n > 0 && n < 65536)
864 strcpy (r, "movzwd ");
865 else if (n < 0 && n > -129)
866 strcpy (r, "movxbd ");
867 else if (n < 0 && n > -32769)
868 strcpy (r, "movxwd ");