;;- Machine description for GNU compiler
;;- TMS34010 Version
;;   Copyright (C) 1987, 1988 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, 675 Mass Ave, Cambridge, MA 02139, USA.


;;- instruction definitions

;;- @@The original PO technology requires these to be ordered by speed,
;;- @@    so that assigner will pick the fastest.

;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.

;;- When naming insn's (operand 0 of define_insn) be careful about using
;;- names from other targets machine descriptions.

;;- cpp macro #define NOTICE_UPDATE_CC in file tm.h handles condition code
;;- updates for most instructions.

;;- Operand classes for the register allocator:
;;- 'r' one of the A file registers can be used.

;;- Assembler specs:
;;- "%-"    push operand "*-sp"				move a0,%-,1
;;- "%+"    pop operand "*sp+"				move a0,%+,1
;;- "%@"    top of stack "*sp"				move a0,%@,1

(define_insn ""
  [(set (match_operand:DI 0 "push_operand" "=m")
	(match_operand:DI 1 "general_operand" "ro<>Fy"))]
  ""
  "*
{
  return output_move_double (operands);
}")

;; We don't want to allow a constant operand for test insns because
;; (set (cc0) (const_int foo)) has no mode information.  Such insns will
;; be folded while optimizing anyway.
(define_insn "tstsi"
  [(set (cc0)
	(match_operand:SI 0 "nonimmediate_operand" "rb"))]
  ""
  "*
{
	CC_STATUS_INIT;
	cc_status.value1 = copy_rtx(operands[0]);
	return \"move %0,%0\";
}")

;; compare instructions.

(define_insn "cmpsi"
  [(set (cc0)
	(compare (match_operand:SI 0 "nonimmediate_operand" "r")
		 (match_operand:SI 1 "general_operand" "rn")))]
  ""
  "*
{
	CC_STATUS_INIT;
	cc_status.value1 = gen_rtx(COMPARE, VOIDmode, operands[0], operands[1]);


	if (REG_P(operands[0]) && REG_P(operands[1]))
		return \"cmp %1,%0\";
	if ((GET_CODE(operands[1]) == CONST_INT) && REG_P(operands[0]))
	{
		if (INTVAL(operands[1]) >= 1 && INTVAL(operands[1]) <= 32)
		{
			if (find_reg_note (insn, REG_UNUSED, operands[0]) ||
				find_reg_note (insn, REG_DEAD, operands[0]))
				return \"subk %1,%0\";
		}
		if (INTVAL(operands[1]) >= -32768 && INTVAL(operands[1]) <= 32767)
			return \"cmpiw %1,%0\";
	}
 	return \"cmpi %1,%0\";
}")

;; sign extension instructions

(define_insn "extendhisi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(sign_extend:SI
	 (match_operand:HI 1 "nonimmediate_operand" "rm")))]
  ""
  "*
{
	do_move(operands[1], operands[0], DM_SHORT|DM_SEXT, DM_LONG);
	return \"\";
}")

(define_insn "extendqihi2"
  [(set (match_operand:HI 0 "general_operand" "=r")
	(sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "rm")))]
  ""
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_SEXT, DM_SHORT);
	return \"\";
}")

(define_insn "extendqisi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "rm")))]
  ""
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_SEXT, DM_LONG);
	return \"\";
}")

;; move instructions

(define_insn "movdf"
  [(set (match_operand:DF 0 "general_operand" "=r,m")
	(match_operand:DF 1 "general_operand" "rim,rm"))]
  ""
  "*
{
	return output_move_double (operands);
}")

(define_insn "movsf"
  [(set (match_operand:SF 0 "general_operand" "=r,m")
	(match_operand:SF 1 "general_operand" "rim,rm"))]
  ""
  "*
{
	return output_move_double (operands);
}")

(define_insn "movdi"
  [(set (match_operand:DI 0 "general_operand" "=r,m")
	(match_operand:DI 1 "general_operand" "rim,rm"))]
  ""
  "*
{
	return output_move_double (operands);
}")

;; General case of fullword move.

(define_insn "movsi"
  [(set (match_operand:SI 0 "general_operand" "=r,m,b")
	(match_operand:SI 1 "general_operand" "rimb,rm,rb"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_LONG, DM_LONG);
  return \"\";
}")

(define_insn "movsihi"
  [(set (match_operand:HI 0 "general_operand" "=r,m")
	(match_operand:SI 1 "general_operand" "im,rm"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_SHORT, DM_SHORT);
  return \"\";
}")

(define_insn "movsiqi"
  [(set (match_operand:QI 0 "general_operand" "=r,m")
	(match_operand:SI 1 "general_operand" "rim,rm"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_BYTE, DM_BYTE);
  return \"\";
}")

(define_insn "movhisi"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(match_operand:HI 1 "general_operand" "im"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_SHORT|DM_ZEXT, DM_LONG);
  return \"\";
}")

(define_insn "movhi"
  [(set (match_operand:HI 0 "general_operand" "=r,m")
	(match_operand:HI 1 "general_operand" "rim,rm"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_SHORT, DM_SHORT);
  return \"\";
}")

(define_insn "movhiqi"
  [(set (match_operand:QI 0 "general_operand" "=r,m")
	(match_operand:HI 1 "general_operand" "rim,rm"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_BYTE, DM_BYTE);
  return \"\";
}")

(define_insn "movqisi"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(match_operand:QI 1 "general_operand" "im"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_LONG);
  return \"\";
}")

(define_insn "movqihi"
  [(set (match_operand:HI 0 "general_operand" "=r")
	(match_operand:QI 1 "general_operand" "im"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_SHORT);
  return \"\";
}")

(define_insn "movqi"
  [(set (match_operand:QI 0 "general_operand" "=r,m")
	(match_operand:QI 1 "general_operand" "rim,rm"))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_BYTE, DM_BYTE);
  return \"\";
}")

(define_insn "movstricthi"
  [(set (strict_low_part (match_operand:HI 0 "general_operand" "+r"))
	(match_operand:HI 1 "general_operand" "r"))]
  ""
  "*
{
  return \"movx %1,%0\";
}")

(define_insn "movstrictqi"
  [(set (strict_low_part (match_operand:QI 0 "general_operand" "+r"))
	(match_operand:QI 1 "general_operand" "r"))]
  ""
  "*
{
  return \"move %1,a13\;andi 0xff,a13\;andi 0xffffff00,%0\;or a13,%0\";
}")

;; truncation instructions

(define_insn "truncsiqi2"
  [(set (match_operand:QI 0 "general_operand" "=r")
	(truncate:QI
	 (match_operand:SI 1 "general_operand" "rim")))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_LONG|DM_TRUNC, DM_BYTE);
  return \"\";
}")

(define_insn "trunchiqi2"
  [(set (match_operand:QI 0 "general_operand" "=r")
	(truncate:QI
	 (match_operand:HI 1 "general_operand" "rim")))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_SHORT|DM_TRUNC, DM_BYTE);
  return \"\";
}")

(define_insn "truncsihi2"
  [(set (match_operand:HI 0 "general_operand" "=r")
	(truncate:HI
	 (match_operand:SI 1 "general_operand" "rim")))]
  ""
  "*
{
  do_move(operands[1], operands[0], DM_LONG|DM_TRUNC, DM_SHORT);
  return \"\";
}")

; Zero extend short to long

(define_insn "zero_extendhisi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "rm")))]
  ""
  "*
{
	do_move(operands[1], operands[0], DM_SHORT|DM_ZEXT, DM_LONG);
	return \"\";
}")

; Zero extending byte to long

(define_insn "zero_extendqisi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "rm")))]
  ""
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_LONG);
	return \"\";
}")

; Zero extending move byte to short

(define_insn "zero_extendqihi2"
  [(set (match_operand:HI 0 "general_operand" "=r")
	(zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "rm")))]
  ""
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_SHORT);
	return \"\";
}")

;; add instructions

(define_insn "addsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(plus:SI (match_operand:SI 1 "general_operand" "%0")
		 (match_operand:SI 2 "general_operand" "ri")))]
  ""
  "*
{
	do_addsub(operands, 1);
	return \"\";
}")

;; subtract instructions

(define_insn "subsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(minus:SI (match_operand:SI 1 "general_operand" "0")
		  (match_operand:SI 2 "general_operand" "ri")))]
  ""
  "*
{
	do_addsub(operands, 0);
	return \"\";
}")

;; multiply instructions

(define_insn "mulsi3"
  [(set (match_operand:SI 0 "general_operand" "=|")
	(mult:SI (match_operand:SI 1 "general_operand" "%0")
		 (match_operand:SI 2 "general_operand" "r")))]
  ""
  "*
{
	return \"mpys %2,%0\";
}")

;; divide instructions

(define_insn "divsi3"
  [(set (match_operand:SI 0 "general_operand" "=|")
	(div:SI (match_operand:SI 1 "general_operand" "0")
		 (match_operand:SI 2 "general_operand" "r")))]
  ""
  "*
{
	return \"divs %2,%0\";
}")

(define_insn "udivsi3"
  [(set (match_operand:SI 0 "general_operand" "=|")
	(udiv:SI (match_operand:SI 1 "general_operand" "0")
		 (match_operand:SI 2 "general_operand" "r")))]
  ""
  "*
{
	return \"divu %2,%0\";
}")

;; Remainder instructions.

(define_insn "modsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(mod:HI (match_operand:SI 1 "general_operand" "0")
		(match_operand:SI 2 "general_operand" "r")))]
  ""
  "*
{
	return \"mods %1,%0\";
}")

(define_insn "umodsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(umod:HI (match_operand:SI 1 "general_operand" "0")
		(match_operand:SI 2 "general_operand" "r")))]
  ""
  "*
{
	return \"modu %1,%0\";
}")

;; logical-and instructions

(define_insn "andsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(and:SI (match_operand:SI 1 "general_operand" "0")
		(match_operand:SI 2 "general_operand" "rK")))]
  ""
  "*
{
  if (REG_P(operands[2]))
	return \"and %2,%0\";
  return \"andi %2,%0\";
}")

;; inclusive-or instructions

(define_insn "iorsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(ior:SI (match_operand:SI 1 "general_operand" "0")
		(match_operand:SI 2 "general_operand" "rK")))]
  ""
  "*
{
  if (REG_P(operands[2]))
	return \"or %2,%0\";
  return \"ori %2,%0\";
}")

;; xor instructions

(define_insn "xorsi3"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(xor:SI (match_operand:SI 1 "general_operand" "0")
		(match_operand:SI 2 "general_operand" "rK")))]
  ""
  "*
{
  if (REG_P(operands[2]))
	return \"xor %2,%0\";
  return \"xori %2,%0\";
}")

;; negation instructions

(define_insn "negsi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(neg:SI (match_operand:SI 1 "general_operand" "0")))]
  ""
  "neg %0")

;; absolute value

(define_insn "abssi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(abs:SI (match_operand:SI 1 "general_operand" "0")))]
  ""
  "abs %0")

;; Recognizers for btst instructions.

(define_insn ""
  [(set (cc0) (zero_extract (match_operand:SI 0 "nonimmediate_operand" "r")
	(const_int 1)
	(match_operand:SI 1 "general_operand" "rn")))]
  ""
  "*
{
	return output_btst (operands, operands[1], operands[0], insn, 7);
}")

(define_insn ""
  [(set (cc0) (zero_extract (match_operand:QI 0 "nonimmediate_operand" "o")
    (const_int 1)
    (match_operand:SI 1 "general_operand" "i")))]
  "GET_CODE (operands[1]) == CONST_INT"
  "*
{
	operands[0] = adj_offsettable_operand (operands[0],
							INTVAL (operands[1]) - 15);
	do_move(operands[0], a13_rtx, DM_SHORT, DM_SHORT);
	cc_status.flags = CC_Z_IN_NOT_N;
	return \"\";
	return output_btst (operands, operands[1], operands[0], insn, 7);
}")

;; Absolute value instructions

;; one complement instructions

(define_insn "one_cmplsi2"
  [(set (match_operand:SI 0 "general_operand" "=r")
	(not:SI (match_operand:SI 1 "general_operand" "0")))]
  ""
  "not %0")

;; arithmetic shift instructions

(define_insn "ashlsi3"
  [(set (match_operand:SI 0 "register_operand" "=r")
	(ashift:SI (match_operand:SI 1 "register_operand" "0")
		   (match_operand:SI 2 "general_operand" "rn")))]
  ""
  "*
{
	if (operands[2] == const1_rtx)
		return \"add %0,%0\";
	return \"sla %2,%0\";
}")

(define_insn "ashrsi3"
  [(set (match_operand:SI 0 "register_operand" "=r")
	(ashiftrt:SI (match_operand:SI 1 "register_operand" "0")
		     (match_operand:SI 2 "general_operand" "rn")))]
  ""
  "*
{
  return \"sra %2,%0\";
}")

;; logical shift instructions

(define_insn "lshlsi3"
  [(set (match_operand:SI 0 "register_operand" "=r")
	(lshift:SI (match_operand:SI 1 "register_operand" "0")
		   (match_operand:SI 2 "general_operand" "rn")))]
  ""
  "*
{
  return \"sll %2,%0\";
}")

(define_insn ""
  [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
	(lshift:HI (match_dup 0)
		   (match_operand:HI 1 "general_operand" "rn")))]
  ""
  "*
{
	abort();
}")

(define_insn "lshrsi3"
  [(set (match_operand:SI 0 "register_operand" "=r")
	(lshiftrt:SI (match_operand:SI 1 "register_operand" "0")
		     (match_operand:SI 2 "general_operand" "rn")))]
  ""
  "*
{
  return \"srl %2,%0\";
}")

(define_insn ""
  [(set (strict_low_part (match_operand:HI 0 "register_operand" "+r"))
	(lshiftrt:HI (match_dup 0)
		     (match_operand:HI 1 "general_operand" "rn")))]
  ""
  "*
{
	abort();
}")

;; rotate instructions

(define_insn "rotlsi3"
  [(set (match_operand:SI 0 "register_operand" "=r")
	(rotate:SI (match_operand:SI 1 "register_operand" "0")
		   (match_operand:SI 2 "general_operand" "rn")))]
  ""
  "rl %2,%0")

(define_insn "rotrsi3"
  [(set (match_operand:SI 0 "register_operand" "=r")
	(rotatert:SI (match_operand:SI 1 "register_operand" "0")
		     (match_operand:SI 2 "general_operand" "rn")))]
  ""
  "*
{
	abort();
}")

;; Basic conditional jump instructions.

(define_insn "beq"
  [(set (pc)
	(if_then_else (eq (cc0)
			  (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
{
  OUTPUT_JUMP (\"jreq %l0\", \"fbeq %l0\", \"jbeq %l0\");
}")

(define_insn "bne"
  [(set (pc)
	(if_then_else (ne (cc0)
			  (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
{
  OUTPUT_JUMP (\"jrne %l0\", \"fbne %l0\", \"jbne %l0\");
}")

(define_insn "bgt"
  [(set (pc)
	(if_then_else (gt (cc0)
			  (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  OUTPUT_JUMP (\"jrgt %l0\", \"fbgt %l0\", 0);
")

(define_insn "bgtu"
  [(set (pc)
	(if_then_else (gtu (cc0)
			   (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  return \"jrhi %l0\";
")

(define_insn "blt"
  [(set (pc)
	(if_then_else (lt (cc0)
			  (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  OUTPUT_JUMP (\"jrlt %l0\", \"fblt %l0\", \"jbmi %l0\");
")

(define_insn "bltu"
  [(set (pc)
	(if_then_else (ltu (cc0)
			   (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  return \"jrc %l0\";
")

(define_insn "bge"
  [(set (pc)
	(if_then_else (ge (cc0)
			  (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  OUTPUT_JUMP (\"jrge %l0\", \"fbge %l0\", \"jbpl %l0\");
")

(define_insn "bgeu"
  [(set (pc)
	(if_then_else (geu (cc0)
			   (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  return \"jrnc %l0\";
")

(define_insn "ble"
  [(set (pc)
	(if_then_else (le (cc0)
			  (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  OUTPUT_JUMP (\"jrle %l0\", \"fble %l0\", 0);
")

(define_insn "bleu"
  [(set (pc)
	(if_then_else (leu (cc0)
			   (const_int 0))
		      (label_ref (match_operand 0 "" ""))
		      (pc)))]
  ""
  "*
  return \"jrls %l0\";
")

;; Negated conditional jump instructions.

(define_insn ""
  [(set (pc)
	(if_then_else (eq (cc0)
			  (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
{
  OUTPUT_JUMP (\"jrne %l0\", \"fbne %l0\", \"jbne %l0\");
}")

(define_insn ""
  [(set (pc)
	(if_then_else (ne (cc0)
			  (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
{
  OUTPUT_JUMP (\"jreq %l0\", \"fbeq %l0\", \"jbeq %l0\");
}")

(define_insn ""
  [(set (pc)
	(if_then_else (gt (cc0)
			  (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  OUTPUT_JUMP (\"jrle %l0\", \"fbngt %l0\", 0);
")

(define_insn ""
  [(set (pc)
	(if_then_else (gtu (cc0)
			   (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  return \"jrls %l0\";
")

(define_insn ""
  [(set (pc)
	(if_then_else (lt (cc0)
			  (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  OUTPUT_JUMP (\"jrge %l0\", \"fbnlt %l0\", \"jbpl %l0\");
")

(define_insn ""
  [(set (pc)
	(if_then_else (ltu (cc0)
			   (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  return \"jrnc %l0\";
")

(define_insn ""
  [(set (pc)
	(if_then_else (ge (cc0)
			  (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  OUTPUT_JUMP (\"jrlt %l0\", \"fbnge %l0\", \"jbmi %l0\");
")

(define_insn ""
  [(set (pc)
	(if_then_else (geu (cc0)
			   (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  return \"jrc %l0\";
")

(define_insn ""
  [(set (pc)
	(if_then_else (le (cc0)
			  (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  OUTPUT_JUMP (\"jrgt %l0\", \"fbnle %l0\", 0);
")

(define_insn ""
  [(set (pc)
	(if_then_else (leu (cc0)
			   (const_int 0))
		      (pc)
		      (label_ref (match_operand 0 "" ""))))]
  ""
  "*
  return \"jrhi %l0\";
")

;; Unconditional and other jump instructions
(define_insn "jump"
  [(set (pc)
	(label_ref (match_operand 0 "" "")))]
  ""
  "*
  return \"jauc %l0\";
")

;; We support two different ways of handling dispatch tables.
;; The NeXT uses absolute tables, and other machines use relative.
;; This define_expand can generate either kind.
(define_expand "tablejump"
  [(parallel [(set (pc) (match_operand 0 "" ""))
	      (use (label_ref (match_operand 1 "" "")))])]
  ""
  "
{
#ifdef CASE_VECTOR_PC_RELATIVE
    operands[0] = gen_rtx (PLUS, SImode, pc_rtx, operands[0]);
#endif
}")

;; Jump to variable address from dispatch table of absolute addresses.
(define_insn ""
  [(set (pc) (match_operand:SI 0 "register_operand" "r"))
   (use (label_ref (match_operand 1 "" "")))]
  ""
  "*
  return \"jump %0\";
")

(define_insn ""
  [(set (pc)
	(if_then_else
	 (ne (match_operand:SI 0 "general_operand" "+r")
	     (const_int 1))
	 (label_ref (match_operand 1 "" ""))
	 (pc)))
   (set (match_dup 0)
	(plus:SI (match_dup 0)
		 (const_int -1)))]
  ""
  "*
{
	CC_STATUS_INIT;
	return \"dsj %0,%l1\";
}")

(define_insn ""
  [(set (pc)
	(if_then_else
	 (ne (match_operand:SI 0 "general_operand" "+r")
	     (const_int 0))
	 (label_ref (match_operand 1 "" ""))
	 (pc)))
   (set (match_dup 0)
	(plus:SI (match_dup 0)
		 (const_int -1)))]
  ""
  "*
{
	CC_STATUS_INIT;
	return \"subk 1,%0\;jrnc %l1\";
}")

(define_insn ""
  [(set (pc)
	(if_then_else
	 (eq (match_operand:SI 0 "general_operand" "+r")
	     (const_int 0))
	 (label_ref (match_operand 1 "" ""))
	 (pc)))
   (set (match_dup 0)
	(plus:SI (match_dup 0)
		 (const_int -1)))]
  ""
  "*
{
	CC_STATUS_INIT;
	return \"subk 1,%0\;jrc %l1\";
}")

;; PIC calls are handled by loading the address of the function into a 
;; register (via movsi), then emitting a register indirect call using
;; the "jsr" function call syntax.
;;
;; It is important to note that the "jsr" syntax is always used for 
;; PIC calls, even on machines in which GCC normally uses the "jbsr"
;; syntax for non-PIC calls.  This keeps at least 1 assembler (Sun)
;; from emitting incorrect code for a PIC call.
;;
;; We have different patterns for PIC calls and non-PIC calls.  The
;; different patterns are only used to choose the right syntax
;; ("jsr" vs "jbsr").

;; Call subroutine with no return value.
(define_expand "call"
  [(call (match_operand:QI 0 "memory_operand" "")
	 (match_operand:SI 1 "general_operand" ""))]
  ;; Operand 1 not really used on the m68000.

  ""
  "
{
  if (flag_pic && GET_CODE (XEXP (operands[0], 0)) == SYMBOL_REF)
    operands[0] = gen_rtx (MEM, GET_MODE (operands[0]),
			   force_reg (Pmode, XEXP (operands[0], 0)));
}")

;; This is a normal call sequence.
(define_insn ""
  [(call (match_operand:QI 0 "memory_operand" "o")
	 (match_operand:SI 1 "general_operand" "g"))]
  ;; Operand 1 not really used on the m68000.

  "! flag_pic"
  "*
{
	if (GET_CODE(operands[0]) == MEM && REG_P(XEXP(operands[0], 0)))
	{
		output_asm_insn(\"call %0\", &XEXP(operands[0], 0));
		return \"\";
	}
	return \"calla %0\";
}")

;; This is a PIC call sequence.
(define_insn ""
  [(call (match_operand:QI 0 "memory_operand" "o")
	 (match_operand:SI 1 "general_operand" "g"))]
  ;; Operand 1 not really used on the m68000.

  "flag_pic"
  "*
{
	if (GET_CODE(operands[0]) == MEM && REG_P(XEXP(operands[0], 0)))
	{
		output_asm_insn(\"call %0\", &XEXP(operands[0], 0));
		return \"\";
	}
	return \"calla %0\";
}")

;; Call subroutine, returning value in operand 0
;; (which must be a hard register).
;; See comments before "call" regarding PIC calls.
(define_expand "call_value"
  [(set (match_operand 0 "" "")
	(call (match_operand:QI 1 "memory_operand" "")
     (match_operand:SI 2 "general_operand" "")))]
  ;; Operand 2 not really used on the m68000.
  ""
  "
{
  if (flag_pic && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
    operands[1] = gen_rtx (MEM, GET_MODE (operands[1]),
			   force_reg (Pmode, XEXP (operands[1], 0)));
}")

;; This is a normal call_value
(define_insn ""
  [(set (match_operand 0 "" "=rf")
	(call (match_operand:QI 1 "memory_operand" "o")
	      (match_operand:SI 2 "general_operand" "g")))]
  ;; Operand 2 not really used on the m68000.
  "! flag_pic"
  "*
{
	if (GET_CODE(operands[1]) == MEM && REG_P(XEXP(operands[1], 0)))
	{
		output_asm_insn(\"call %0\", &XEXP(operands[1], 0));
		return \"\";
	}
	return \"calla %1\";
}")

;; This is a PIC call_value
(define_insn ""
  [(set (match_operand 0 "" "=rf")
	(call (match_operand:QI 1 "memory_operand" "o")
	      (match_operand:SI 2 "general_operand" "g")))]
  ;; Operand 2 not really used on the m68000.
  "flag_pic"
  "*
{
	if (GET_CODE(operands[1]) == MEM && REG_P(XEXP(operands[1], 0)))
	{
		output_asm_insn(\"call %0\", &XEXP(operands[1], 0));
		return \"\";
	}
	return \"calla %1\";
}")

(define_insn "nop"
  [(const_int 0)]
  ""
  "nop")

(define_insn "probe"
 [(reg:SI 15)]
 "NEED_PROBE"
 "*
{
  operands[0] = gen_rtx (PLUS, SImode, stack_pointer_rtx,
			 gen_rtx (CONST_INT, VOIDmode, NEED_PROBE));
  abort();
  return \"tstl %a0\";
}")

(define_insn "indirect_jump"
  [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
  ""
  "jump %a0")

;; peepholes

; convert
;	move An,Am
;	zext Am,0
;	sext Am,0
; into
;	move An,Am
;	sext Am,0

(define_peephole [
	(set
		(match_operand:HI 0 "register_operand" "=rb")
        (truncate:HI (match_operand:SI 1 "register_operand" ""))
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (sign_extend:SI (match_operand:HI 3 "register_operand" ""))
	)
  ]
  "(REGNO(operands[0]) == REGNO(operands[2])) && (REGNO(operands[0]) == REGNO(operands[3]))"
  "*
{
	if (REGNO(operands[0]) != REGNO(operands[1]))
		output_asm_insn(\"move %1,%0\", operands);
	return \"sext %0,0\";
}")

; convert
;	move An,Am
;	zext Am,0 (byte)
;	sext Am,0 (byte)
; into
;	move An,Am
;	sext Am,0 (byte)

(define_peephole [
	(set
		(match_operand:QI 0 "register_operand" "=r")
        (truncate:QI (match_operand:SI 1 "register_operand" ""))
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (sign_extend:SI (match_operand:QI 3 "register_operand" ""))
	)
  ]
  "(REGNO(operands[0]) == REGNO(operands[2])) && (REGNO(operands[0]) == REGNO(operands[3]))"
  "*
{
	if (REGNO(operands[0]) != REGNO(operands[1]))
		output_asm_insn(\"move %1,%0\", operands);
	return \"setf 8,1,0\;sext %0,0\;setf 16,1,0\";
}")

; convert
;	subk 1,a4
;	cmpiw -1,a4
;	jreq L7
; into
;	subk 1,a4
;	jrc L7

(define_peephole [
	(set
		(match_operand:SI 0 "register_operand" "=r")
        (plus:SI
			(match_dup 0)
			(const_int -1)
		)
	)
	(set
		(cc0)
		(compare (match_dup 0) (const_int -1))
	)
	(set
		(pc)
		(if_then_else
			(eq (cc0) (const_int 0))
			(label_ref (match_operand 1 "" ""))
			(pc)
		)
	)
  ]
  ""
  "*
{
	return \"subk 1,%0\;jrc %1\";
}")

; convert
;	subk 8,sp
;	movk 1,a0
;	setf 8,1,0
;	move a0,-*sp,0
;	setf 16,1,0
; into
;	movk 1,a0
;	move a0,-*sp,0

(define_peephole [
	(set
		(match_operand:SI 0 "register_operand" "=r")
        (plus:SI (match_dup 0) (const_int -8))
	)
	(set
		(match_operand:QI 1 "register_operand" "")
        (match_operand:SI 2 "immediate_operand" "")
	)
	(set
		(mem:QI (pre_dec:SI (match_dup 0)))
		(match_dup 1)
	)
  ]
  "operands[0] == stack_pointer_rtx && GET_CODE(operands[2]) == CONST_INT"
  "*
{
	do_move(operands[2], operands[1], DM_BYTE, DM_BYTE);
	return \"move %1,-*sp,0\";
}")

; convert
;	subk 8,sp
;	setf 8,1,0
;	move a5,-*sp,0
;	setf 16,1,0
; into
;	move a5,-*sp,0

(define_peephole [
	(set
		(match_operand:SI 0 "register_operand" "=r")
        (plus:SI (match_dup 0) (const_int -8))
	)
	(set
		(mem:QI (pre_dec:SI (match_dup 0)))
		(subreg:QI (match_operand:SI 1 "register_operand" "") 0)
	)
  ]
  "operands[0] == stack_pointer_rtx"
  "*
{
	return \"move %1,-*sp,0\";
}")

; convert
;	subk 8,sp
;	movb mem,a13
;	setf 8,1,0
;	move a13,-*sp,0
;	setf 16,1,0
; into
;	movb mem,a13
;	move a13,-*sp,0

(define_peephole [
	(set
		(match_operand:SI 0 "register_operand" "=r")
        (plus:SI (match_dup 0) (const_int -8))
	)
	(set
		(mem:QI (pre_dec:SI (match_dup 0)))
		(match_operand:QI 1 "memory_operand" "")
	)
  ]
  "operands[0] == stack_pointer_rtx"
  "*
{
	do_move(operands[1], a13_rtx, DM_BYTE|DM_SEXT, DM_SHORT);
	return \"move a13,-*sp,0\";
}")

; convert
;	not	a0
;	and a0,a1
; into
;	andn a0,a1

(define_peephole [
	(set
		(match_operand:SI 0 "register_operand" "=r")
        (not:SI (match_dup 0))
	)
	(set
		(match_operand:SI 1 "register_operand" "")
        (and:SI (match_dup 1) (match_dup 0)) 
	)
  ]
  "find_reg_note(insn, REG_DEAD, operands[0])"
  "*
{
	return \"andn %0,%1\";
}")

; convert
;	movb mem,a0
;	andi 255,a0
;	move a0,a0
;	jreq L2
; into
;	movb mem,a0
;	jreq L2

(define_peephole [
	(set
		(match_operand:QI 0 "register_operand" "=r")
        (match_operand:QI 1 "memory_operand" "")
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (and:SI
			(subreg:SI (match_dup 0) 0)
			(const_int 255)
		)
	)
	(set
		(cc0)
		(match_dup 2)
	)
	(set
		(pc)
		(if_then_else
			(eq (cc0) (const_int 0))
			(label_ref (match_operand 3 "" ""))
			(pc)
		)
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2]) &&
		GET_CODE(operands[1]) != PRE_DEC &&
		GET_CODE(operands[1]) != POST_INC"
  "*
{
  	if (find_reg_note(insn, REG_DEAD, operands[0]))
	{
		do_move(operands[1], operands[0], DM_BYTE|DM_SEXT, DM_LONG);
		return \"jreq %3\";
	}
	do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_LONG);
	return \"jreq %3\";
}")

; convert
;	movb mem,a0
;	andi 255,a0
;	move a0,a0
;	jrne L2
; into
;	movb mem,a0
;	jrne L2

(define_peephole [
	(set
		(match_operand:QI 0 "register_operand" "=r")
        (match_operand:QI 1 "memory_operand" "")
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (and:SI
			(subreg:SI (match_dup 0) 0)
			(const_int 255)
		)
	)
	(set
		(cc0)
		(match_dup 2)
	)
	(set
		(pc)
		(if_then_else
			(ne (cc0) (const_int 0))
			(label_ref (match_operand 3 "" ""))
			(pc)
		)
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2]) &&
		GET_CODE(operands[1]) != PRE_DEC &&
		GET_CODE(operands[1]) != POST_INC"
  "*
{
  	if (find_reg_note(insn, REG_DEAD, operands[0]))
	{
		do_move(operands[1], operands[0], DM_BYTE|DM_SEXT, DM_LONG);
		return \"jrne %3\";
	}
	do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_LONG);
	return \"jrne %3\";
}")

; convert
;	movb mem,a0
;	andi 255,a0
; into
;	setf 8,0,0
;	movb mem,a0
;	setf 8,1,0

(define_peephole [
	(set
		(match_operand:QI 0 "register_operand" "=r")
        (match_operand:QI 1 "memory_operand" "")
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (and:SI
			(subreg:SI (match_dup 0) 0)
			(const_int 255)
		)
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2]) &&
	_can_move(operands[1], operands[0], DM_BYTE, DM_BYTE)"
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_ZEXT, DM_LONG);
	return \"\";
}")

; convert
;	move mem,a0,0
;	andi 65535,a0
; into
;	move mem,a0,0
;	zext a0,0

(define_peephole [
	(set
		(match_operand:HI 0 "register_operand" "=r")
        (match_operand:HI 1 "memory_operand" "")
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (and:SI
			(subreg:SI (match_dup 0) 0)
			(const_int 65535)
		)
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2]) &&
	_can_move(operands[1], operands[0], DM_SHORT, DM_SHORT)"
  "*
{
	do_move(operands[1], operands[0], DM_SHORT|DM_ZEXT, DM_LONG);
	return \"\";
}")

; convert
;	move mem,a0,0
;	sext a0,0
; into
;	move mem,a0,0

(define_peephole [
	(set
		(match_operand:HI 0 "register_operand" "=r")
        (match_operand:HI 1 "memory_operand" "")
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (sign_extend:SI (match_dup 0))
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2])"
  "*
{
	do_move(operands[1], operands[0], DM_SHORT|DM_SEXT, DM_LONG);
	return \"\";
}")

; convert
;	movb mem,a0
;	move a1,a1
;	setf 8,1,0
;	sext a1,0
;	setf 16,1,0
; into
;	movb mem

(define_peephole [
	(set
		(match_operand:QI 0 "register_operand" "=r")
        (match_operand:QI 1 "memory_operand" "")
	)
	(set
		(match_operand:SI 2 "register_operand" "")
        (sign_extend:SI (match_dup 0))
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2])"
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_SEXT, DM_LONG);
	return \"\";
}")

; convert
;	movb mem,a0
;	move a1,a1
;	setf 8,1,0
;	sext a1,0
;	setf 16,1,0
; into
;	movb mem
; (for HImode output)

(define_peephole [
	(set
		(match_operand:QI 0 "register_operand" "=r")
        (match_operand:QI 1 "memory_operand" "")
	)
	(set
		(match_operand:HI 2 "register_operand" "")
        (sign_extend:HI (match_dup 0))
	)
  ]
  "REGNO(operands[0]) == REGNO(operands[2])"
  "*
{
	do_move(operands[1], operands[0], DM_BYTE|DM_SEXT, DM_LONG);
	return \"\";
}")


