1 ;; Machine Descriptions for R8C/M16C/M32C
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Red Hat.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 2, or (at your
11 ;; option) any later version.
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 ;; License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING. If not, write to the Free
20 ;; Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 ; conditionals - cmp, jcc, setcc, etc.
25 ; Until support for relaxing is supported in gas, we must assume that
26 ; short labels won't reach, so we must use long labels.
27 ; Unfortunately, there aren't any conditional jumps with long labels,
28 ; so instead we invert the conditional and jump around a regular jump.
30 ; Note that we can, at some point in the future, add code to omit the
31 ; "cmp" portion of the insn if the preceding insn happened to set the
32 ; right flags already. For example, a mov followed by a "cmp *,0" is
33 ; redundant; the move already set the Z flag.
35 (define_insn_and_split "cbranch<mode>4"
36 [(set (pc) (if_then_else
37 (match_operator 0 "m32c_cmp_operator"
38 [(match_operand:QHPSI 1 "mra_operand" "RraSd")
39 (match_operand:QHPSI 2 "mrai_operand" "iRraSd")])
40 (label_ref (match_operand 3 "" ""))
45 [(set (reg:CC FLG_REGNO)
46 (compare (match_dup 1)
48 (set (pc) (if_then_else (match_dup 4)
49 (label_ref (match_dup 3))
51 "operands[4] = m32c_cmp_flg_0 (operands[0]);"
54 (define_insn "stzx_16"
55 [(set (match_operand:QI 0 "mrai_operand" "=R0w,R0w,R0w")
56 (if_then_else:QI (eq (reg:CC FLG_REGNO) (const_int 0))
57 (match_operand:QI 1 "const_int_operand" "i,i,0")
58 (match_operand:QI 2 "const_int_operand" "i,0,i")))]
64 [(set_attr "flags" "n,n,n")]
67 (define_insn "stzx_24_<mode>"
68 [(set (match_operand:QHI 0 "mrai_operand" "=RraSd,RraSd,RraSd")
69 (if_then_else:QHI (eq (reg:CC FLG_REGNO) (const_int 0))
70 (match_operand:QHI 1 "const_int_operand" "i,i,0")
71 (match_operand:QHI 2 "const_int_operand" "i,0,i")))]
77 [(set_attr "flags" "n,n,n")])
79 (define_insn_and_split "stzx_reversed"
80 [(set (match_operand 0 "m32c_r0_operand" "")
81 (if_then_else (ne (reg:CC FLG_REGNO) (const_int 0))
82 (match_operand 1 "const_int_operand" "")
83 (match_operand 2 "const_int_operand" "")))]
84 "TARGET_A24 || GET_MODE (operands[0]) == QImode"
88 (if_then_else (eq (reg:CC FLG_REGNO) (const_int 0))
95 (define_insn "cmp<mode>"
96 [(set (reg:CC FLG_REGNO)
97 (compare (match_operand:QHPSI 0 "mra_operand" "RraSd")
98 (match_operand:QHPSI 1 "mrai_operand" "RraSdi")))]
100 "* return m32c_output_compare(insn, operands); "
101 [(set_attr "flags" "oszc")])
103 (define_insn "b<code>"
105 (if_then_else (any_cond (reg:CC FLG_REGNO)
107 (label_ref (match_operand 0 ""))
111 [(set_attr "flags" "n")]
114 ;; m32c_conditional_register_usage changes the setcc_gen_code array to
115 ;; point to the _24 variants if needed.
117 (define_insn "s<code>"
118 [(set (match_operand:QI 0 "register_operand" "=Rqi")
119 (any_cond:QI (reg:CC FLG_REGNO) (const_int 0)))]
121 "* return m32c_scc_pattern(operands, <CODE>);")
123 (define_insn "s<code>_24"
124 [(set (match_operand:HI 0 "mra_operand" "=RhiSd")
125 (any_cond:HI (reg:CC FLG_REGNO) (const_int 0)))]
128 [(set_attr "flags" "n")]
131 (define_expand "movqicc"
132 [(set (match_operand:QI 0 "register_operand" "")
133 (if_then_else:QI (match_operand 1 "m32c_eqne_operator" "")
134 (match_operand:QI 2 "const_int_operand" "")
135 (match_operand:QI 3 "const_int_operand" "")))]
137 "if (m32c_expand_movcc(operands))
142 (define_expand "movhicc"
143 [(set (match_operand:HI 0 "mra_operand" "")
144 (if_then_else:HI (match_operand 1 "m32c_eqne_operator" "")
145 (match_operand:HI 2 "const_int_operand" "")
146 (match_operand:HI 3 "const_int_operand" "")))]
148 "if (m32c_expand_movcc(operands))
154 ;; CMP opcodes subtract two values, set the flags, and discard the
155 ;; value. This pattern recovers the sign of the discarded value based
156 ;; on the flags. Operand 0 is set to -1, 0, or 1. This is used for
157 ;; the cmpstr pattern. For optimal code, this should be removed if
158 ;; followed by a suitable CMP insn (see the peephole following). This
159 ;; pattern is 7 bytes and 5 cycles. If you don't need specific
160 ;; values, a 5/4 pattern can be made with SCGT and BMLT to set the
163 (define_insn "cond_to_int"
164 [(set (match_operand:HI 0 "mra_qi_operand" "=Rqi")
165 (if_then_else:HI (lt (reg:CC FLG_REGNO) (const_int 0))
167 (if_then_else:HI (eq (reg:CC FLG_REGNO) (const_int 0))
171 "sceq\t%0\n\tbmgt\t1,%h0\n\tdec.w\t%0"
172 [(set_attr "flags" "x")]
175 ;; A cond_to_int followed by a compare against zero is essentially a no-op.
178 [(set (match_operand:HI 0 "mra_qi_operand" "")
179 (if_then_else:HI (lt (reg:CC FLG_REGNO) (const_int 0))
181 (if_then_else:HI (eq (reg:CC FLG_REGNO) (const_int 0))
184 (set (reg:CC FLG_REGNO)
185 (compare (match_operand:HI 1 "mra_qi_operand" "")
188 "rtx_equal_p(operands[0], operands[1])"