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 ;; multiply and divide
25 ; Here is the pattern for the const_int.
26 (define_insn "mulqihi3_c"
27 [(set (match_operand:HI 0 "mra_operand" "=RhiSd,??Rmm")
28 (mult:HI (sign_extend:HI (match_operand:QI 1 "mra_operand" "%0,0"))
29 (match_operand 2 "immediate_operand" "i,i")))]
34 ; Here is the pattern for registers and such.
35 (define_insn "mulqihi3_r"
36 [(set (match_operand:HI 0 "mra_operand" "=RhiSd,RhiSd,??Rmm,??Rmm,Raa,Raa")
37 (mult:HI (sign_extend:HI (match_operand:QI 1 "mra_operand" "%0,0,0,0,0,0"))
38 (sign_extend:HI (match_operand:QI 2 "mra_operand" "RqiSd,?Rmm,RqiSd,?Rmm,RhlSd,?Rmm"))))]
43 ; Don't try to sign_extend a const_int. Same for all other multiplies.
44 (define_expand "mulqihi3"
45 [(set (match_operand:HI 0 "mra_operand" "=RhiSd,RhiSd,??Rmm,??Rmm,Raa,Raa")
46 (mult:HI (sign_extend:HI (match_operand:QI 1 "mra_operand" "%0,0,0,0,0,0"))
47 (match_operand:QI 2 "mra_operand" "RqiSd,?Rmm,RqiSd,?Rmm,RhlSd,?Rmm")))]
49 "{ if (GET_MODE (operands[2]) != VOIDmode)
50 operands[2] = gen_rtx_SIGN_EXTEND (HImode, operands[2]); }"
53 (define_insn "umulqihi3_c"
54 [(set (match_operand:HI 0 "mra_operand" "=RhiSd,??Rmm")
55 (mult:HI (zero_extend:HI (match_operand:QI 1 "mra_operand" "%0,0"))
56 (match_operand 2 "immediate_operand" "i,i")))]
61 (define_insn "umulqihi3_r"
62 [(set (match_operand:HI 0 "mra_operand" "=RhiSd,RhiSd,??Rmm,??Rmm,Raa,Raa")
63 (mult:HI (zero_extend:HI (match_operand:QI 1 "mra_operand" "%0,0,0,0,0,0"))
64 (zero_extend:HI (match_operand:QI 2 "mra_operand" "RqiSd,?Rmm,RqiSd,?Rmm,RhlSd,?Rmm"))))]
69 (define_expand "umulqihi3"
70 [(set (match_operand:HI 0 "mra_operand" "=RhiSd,RhiSd,??Rmm,??Rmm,Raa,Raa")
71 (mult:HI (zero_extend:HI (match_operand:QI 1 "mra_operand" "%0,0,0,0,0,0"))
72 (match_operand:QI 2 "mra_operand" "RqiSd,?Rmm,RqiSd,?Rmm,RhlSd,?Rmm")))]
74 "{ if (GET_MODE (operands[2]) != VOIDmode)
75 operands[2] = gen_rtx_ZERO_EXTEND (HImode, operands[2]); }"
78 (define_insn "mulhisi3_c"
79 [(set (match_operand:SI 0 "mra_operand" "=RsiSd,??Rmm")
80 (mult:SI (sign_extend:SI (match_operand:HI 1 "mra_operand" "%0,0"))
81 (match_operand 2 "immediate_operand" "i,i")))]
86 (define_insn "mulhisi3_r"
87 [(set (match_operand:SI 0 "mra_operand" "=RsiSd,RsiSd,??Rmm,??Rmm")
88 (mult:SI (sign_extend:SI (match_operand:HI 1 "mra_operand" "%0,0,0,0"))
89 (sign_extend:SI (match_operand:HI 2 "mra_operand" "RhiSd,?Rmm,RhiSd,?Rmm"))))]
94 (define_expand "mulhisi3"
95 [(set (match_operand:SI 0 "mra_operand" "=RsiSd,RsiSd,??Rmm,??Rmm")
96 (mult:SI (sign_extend:SI (match_operand:HI 1 "mra_operand" "%0,0,0,0"))
97 (match_operand:HI 2 "mra_operand" "RhiSd,?Rmm,RhiSd,?Rmm")))]
99 "{ if (GET_MODE (operands[2]) != VOIDmode)
100 operands[2] = gen_rtx_SIGN_EXTEND (SImode, operands[2]); }"
103 (define_insn "umulhisi3_c"
104 [(set (match_operand:SI 0 "mra_operand" "=RsiSd,??Rmm")
105 (mult:SI (zero_extend:SI (match_operand:HI 1 "mra_operand" "%0,0"))
106 (match_operand 2 "immediate_operand" "i,i")))]
111 (define_insn "umulhisi3_r"
112 [(set (match_operand:SI 0 "mra_operand" "=RsiSd,RsiSd,??Rmm,??Rmm")
113 (mult:SI (zero_extend:SI (match_operand:HI 1 "mra_operand" "%0,0,0,0"))
114 (zero_extend:SI (match_operand:HI 2 "mra_operand" "RhiSd,?Rmm,RhiSd,?Rmm"))))]
119 (define_expand "umulhisi3"
120 [(set (match_operand:SI 0 "mra_operand" "=RsiSd,RsiSd,??Rmm,??Rmm")
121 (mult:SI (zero_extend:SI (match_operand:HI 1 "mra_operand" "%0,0,0,0"))
122 (match_operand:HI 2 "mra_operand" "RhiSd,?Rmm,RhiSd,?Rmm")))]
124 "{ if (GET_MODE (operands[2]) != VOIDmode)
125 operands[2] = gen_rtx_ZERO_EXTEND (SImode, operands[2]); }"
129 ; GCC expects to be able to multiply pointer-sized integers too, but
130 ; fortunately it only multiplies by powers of two, although sometimes
132 (define_insn "mulpsi3_op"
133 [(set (match_operand:PSI 0 "mra_operand" "=RsiSd")
134 (mult:PSI (match_operand:PSI 1 "mra_operand" "%0")
135 (match_operand 2 "m32c_psi_scale" "Ilb")))]
138 [(set_attr "flags" "szc")]
141 (define_expand "mulpsi3"
142 [(set (match_operand:PSI 0 "mra_operand" "=RsiSd")
143 (mult:PSI (match_operand:PSI 1 "mra_operand" "%0")
144 (match_operand 2 "m32c_psi_scale" "Ilb")))]
146 "if (INTVAL(operands[2]) < 0)
148 m32c_expand_neg_mulpsi3 (operands);
155 (define_expand "divmodqi4"
157 (sign_extend:HI (match_operand:QI 1 "register_operand" "0,0")))
158 (parallel [(set (match_operand:QI 0 "register_operand" "=R0w,R0w")
159 (div:QI (match_dup 4)
160 (match_operand:QI 2 "general_operand" "iRqiSd,?Rmm")))
161 (set (match_operand:QI 3 "register_operand" "=&R0h,&R0h")
162 (mod:QI (match_dup 4) (match_dup 2)))
165 "operands[4] = gen_reg_rtx (HImode);"
168 (define_insn "divmodqi4_n"
169 [(set (match_operand:QI 0 "register_operand" "=R0l,R0l")
170 (div:QI (match_operand:HI 1 "register_operand" "R0w,R0w")
171 (match_operand:QI 2 "general_operand" "iRqiSd,?Rmm")))
172 (set (match_operand:QI 3 "register_operand" "=R0h,R0h")
173 (mod:QI (match_dup 1) (match_dup 2)))
179 (define_expand "udivmodqi4"
181 (zero_extend:HI (match_operand:QI 1 "register_operand" "0,0")))
182 (parallel [(set (match_operand:QI 0 "register_operand" "=R0l,R0l")
183 (udiv:QI (match_dup 4)
184 (match_operand:QI 2 "general_operand" "iRqiSd,?Rmm")))
185 (set (match_operand:QI 3 "register_operand" "=&R0h,&R0h")
186 (umod:QI (match_dup 4) (match_dup 2)))
189 "operands[4] = gen_reg_rtx (HImode);"
192 (define_insn "udivmodqi4_n"
193 [(set (match_operand:QI 0 "register_operand" "=R0l,R0l")
194 (udiv:QI (match_operand:HI 1 "register_operand" "R0w,R0w")
195 (match_operand:QI 2 "general_operand" "iRqiSd,?Rmm")))
196 (set (match_operand:QI 3 "register_operand" "=R0h,R0h")
197 (umod:QI (match_dup 1) (match_dup 2)))
203 (define_expand "divmodhi4"
205 (sign_extend:SI (match_operand:HI 1 "register_operand" "0,0")))
206 (parallel [(set (match_operand:HI 0 "register_operand" "=R0w,R0w")
207 (div:HI (match_dup 4)
208 (match_operand:HI 2 "general_operand" "iRhiSd,?Rmm")))
209 (set (match_operand:HI 3 "register_operand" "=R2w,R2w")
210 (mod:HI (match_dup 4) (match_dup 2)))
213 "operands[4] = gen_reg_rtx (SImode);"
216 (define_insn "divmodhi4_n"
217 [(set (match_operand:HI 0 "m32c_r0_operand" "=R0w,R0w")
218 (div:HI (match_operand:SI 1 "m32c_r0_operand" "R02,R02")
219 (match_operand:HI 2 "m32c_notr2_operand" "iR1wR3wRaaSd,?Rmm")))
220 (set (match_operand:HI 3 "m32c_r2_operand" "=R2w,R2w")
221 (mod:HI (match_dup 1) (match_dup 2)))
227 (define_expand "udivmodhi4"
229 (zero_extend:SI (match_operand:HI 1 "register_operand" "0,0")))
230 (parallel [(set (match_operand:HI 0 "register_operand" "=R0w,R0w")
231 (udiv:HI (match_dup 4)
232 (match_operand:HI 2 "general_operand" "iRhiSd,?Rmm")))
233 (set (match_operand:HI 3 "register_operand" "=R2w,R2w")
234 (umod:HI (match_dup 4) (match_dup 2)))
237 "operands[4] = gen_reg_rtx (SImode);"
240 (define_insn "udivmodhi4_n"
241 [(set (match_operand:HI 0 "m32c_r0_operand" "=R0w,R0w")
242 (udiv:HI (match_operand:SI 1 "m32c_r0_operand" "R02,R02")
243 (match_operand:HI 2 "m32c_notr2_operand" "iR1wR3wRaaSd,?Rmm")))
244 (set (match_operand:HI 3 "m32c_r2_operand" "=R2w,R2w")
245 (umod:HI (match_dup 1) (match_dup 2)))