xref: /netbsd-src/external/gpl3/gcc/dist/gcc/config/h8300/divmod.md (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1;; ----------------------------------------------------------------------
2;; DIVIDE/MOD INSTRUCTIONS
3;; ----------------------------------------------------------------------
4
5(define_insn_and_split "udiv<mode>3"
6  [(set (match_operand:HSI 0 "register_operand" "=r")
7	(udiv:HSI (match_operand:HSI 1 "register_operand" "0")
8		  (match_operand:HSI 2 "reg_or_nibble_operand" "r IP4>X")))]
9  "TARGET_H8300SX"
10  "#"
11  "&& reload_completed"
12  [(parallel [(set (match_dup 0) (udiv:HSI (match_dup 1) (match_dup 2)))
13	      (clobber (reg:CC CC_REG))])])
14
15(define_insn "udiv<mode>3_clobber_flags"
16  [(set (match_operand:HSI 0 "register_operand" "=r")
17	(udiv:HSI (match_operand:HSI 1 "register_operand" "0")
18		  (match_operand:HSI 2 "reg_or_nibble_operand" "r IP4>X")))
19   (clobber (reg:CC CC_REG))]
20  "TARGET_H8300SX"
21  { return <MODE>mode == HImode ? "divu.w\\t%T2,%T0" : "divu.l\\t%S2,%S0"; }
22  [(set_attr "length" "4")])
23
24(define_insn_and_split "div<mode>3"
25  [(set (match_operand:HSI 0 "register_operand" "=r")
26	(div:HSI (match_operand:HSI 1 "register_operand" "0")
27		 (match_operand:HSI 2 "reg_or_nibble_operand" "r IP4>X")))]
28  "TARGET_H8300SX"
29  "#"
30  "&& reload_completed"
31  [(parallel [(set (match_dup 0) (div:HSI (match_dup 1) (match_dup 2)))
32	      (clobber (reg:CC CC_REG))])])
33
34(define_insn "div<mode>3_clobber_flags"
35  [(set (match_operand:HSI 0 "register_operand" "=r")
36	(div:HSI (match_operand:HSI 1 "register_operand" "0")
37		 (match_operand:HSI 2 "reg_or_nibble_operand" "r IP4>X")))
38   (clobber (reg:CC CC_REG))]
39  "TARGET_H8300SX"
40  { return <MODE>mode == HImode ? "divs.w\\t%T2,%T0" : "divs.l\\t%S2,%S0"; }
41  [(set_attr "length" "4")])
42
43(define_insn_and_split "udivmodqi4"
44  [(set (match_operand:QI 0 "register_operand" "=r")
45	(truncate:QI
46	  (udiv:HI
47	    (match_operand:HI 1 "register_operand" "0")
48	    (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
49   (set (match_operand:QI 3 "register_operand" "=r")
50	(truncate:QI
51	  (umod:HI
52	    (match_dup 1)
53	    (zero_extend:HI (match_dup 2)))))]
54  ""
55  "#"
56  "&& reload_completed"
57  [(parallel [(set (match_dup 0) (truncate:QI
58				   (udiv:HI (match_dup 1)
59					    (zero_extend:HI (match_dup 2)))))
60	      (set (match_dup 3) (truncate:QI
61				   (umod:HI (match_dup 1)
62					    (zero_extend:HI (match_dup 2)))))
63	      (clobber (reg:CC CC_REG))])])
64
65
66(define_insn "udivmodqi4_clobber_flags"
67  [(set (match_operand:QI 0 "register_operand" "=r")
68	(truncate:QI
69	  (udiv:HI
70	    (match_operand:HI 1 "register_operand" "0")
71	    (zero_extend:HI (match_operand:QI 2 "register_operand" "r")))))
72   (set (match_operand:QI 3 "register_operand" "=r")
73	(truncate:QI
74	  (umod:HI
75	    (match_dup 1)
76	    (zero_extend:HI (match_dup 2)))))
77   (clobber (reg:CC CC_REG))]
78  ""
79{
80  if (find_reg_note (insn, REG_UNUSED, operands[3]))
81    return "divxu.b\\t%X2,%T0";
82  else
83    return "divxu.b\\t%X2,%T0\;mov.b\\t%t0,%s3";
84}
85  [(set_attr "length" "4")])
86
87(define_insn_and_split "divmodqi4"
88  [(set (match_operand:QI 0 "register_operand" "=r")
89	(truncate:QI
90	  (div:HI
91	    (match_operand:HI 1 "register_operand" "0")
92	    (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
93   (set (match_operand:QI 3 "register_operand" "=r")
94	(truncate:QI
95	  (mod:HI
96	    (match_dup 1)
97	    (sign_extend:HI (match_dup 2)))))]
98  ""
99  "#"
100  "&& reload_completed"
101  [(parallel [(set (match_dup 0) (truncate:QI
102				   (div:HI (match_dup 1)
103					   (sign_extend:HI (match_dup 2)))))
104	      (set (match_dup 3) (truncate:QI
105				   (mod:HI (match_dup 1)
106					   (sign_extend:HI (match_dup 2)))))
107	      (clobber (reg:CC CC_REG))])])
108
109(define_insn "divmodqi4_clobber_flags"
110  [(set (match_operand:QI 0 "register_operand" "=r")
111	(truncate:QI
112	  (div:HI
113	    (match_operand:HI 1 "register_operand" "0")
114	    (sign_extend:HI (match_operand:QI 2 "register_operand" "r")))))
115   (set (match_operand:QI 3 "register_operand" "=r")
116	(truncate:QI
117	  (mod:HI
118	    (match_dup 1)
119	    (sign_extend:HI (match_dup 2)))))
120   (clobber (reg:CC CC_REG))]
121  ""
122{
123  if (find_reg_note (insn, REG_UNUSED, operands[3]))
124    return "divxs.b\\t%X2,%T0";
125  else
126    return "divxs.b\\t%X2,%T0\;mov.b\\t%t0,%s3";
127}
128  [(set_attr "length" "6")])
129
130(define_insn_and_split "udivmodhi4"
131  [(set (match_operand:HI 0 "register_operand" "=r")
132	(truncate:HI
133	  (udiv:SI
134	    (match_operand:SI 1 "register_operand" "0")
135	    (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
136   (set (match_operand:HI 3 "register_operand" "=r")
137	(truncate:HI
138	  (umod:SI
139	    (match_dup 1)
140	    (zero_extend:SI (match_dup 2)))))]
141  ""
142  "#"
143  "&& reload_completed"
144  [(parallel [(set (match_dup 0) (truncate:HI
145				   (udiv:SI (match_dup 1)
146					    (zero_extend:SI (match_dup 2)))))
147	      (set (match_dup 3) (truncate:HI
148				   (umod:SI (match_dup 1)
149					    (zero_extend:SI (match_dup 2)))))
150	      (clobber (reg:CC CC_REG))])])
151
152(define_insn "udivmodhi4_clobber_flags"
153  [(set (match_operand:HI 0 "register_operand" "=r")
154	(truncate:HI
155	  (udiv:SI
156	    (match_operand:SI 1 "register_operand" "0")
157	    (zero_extend:SI (match_operand:HI 2 "register_operand" "r")))))
158   (set (match_operand:HI 3 "register_operand" "=r")
159	(truncate:HI
160	  (umod:SI
161	    (match_dup 1)
162	    (zero_extend:SI (match_dup 2)))))
163   (clobber (reg:CC CC_REG))]
164  ""
165{
166  if (find_reg_note (insn, REG_UNUSED, operands[3]))
167    return "divxu.w\\t%T2,%S0";
168  else
169    return "divxu.w\\t%T2,%S0\;mov.w\\t%e0,%f3";
170}
171  [(set_attr "length" "4")])
172
173(define_insn_and_split "divmodhi4"
174  [(set (match_operand:HI 0 "register_operand" "=r")
175	(truncate:HI
176	  (div:SI
177	    (match_operand:SI 1 "register_operand" "0")
178	    (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
179   (set (match_operand:HI 3 "register_operand" "=r")
180	(truncate:HI
181	  (mod:SI
182	    (match_dup 1)
183	    (sign_extend:SI (match_dup 2)))))]
184  ""
185  "#"
186  "&& reload_completed"
187  [(parallel [(set (match_dup 0) (truncate:HI
188				   (div:SI (match_dup 1)
189					   (sign_extend:SI (match_dup 2)))))
190	      (set (match_dup 3) (truncate:HI
191				   (mod:SI (match_dup 1)
192					   (sign_extend:SI (match_dup 2)))))
193	      (clobber (reg:CC CC_REG))])])
194
195(define_insn "divmodhi4_clobber_flags"
196  [(set (match_operand:HI 0 "register_operand" "=r")
197	(truncate:HI
198	  (div:SI
199	    (match_operand:SI 1 "register_operand" "0")
200	    (sign_extend:SI (match_operand:HI 2 "register_operand" "r")))))
201   (set (match_operand:HI 3 "register_operand" "=r")
202	(truncate:HI
203	  (mod:SI
204	    (match_dup 1)
205	    (sign_extend:SI (match_dup 2)))))
206   (clobber (reg:CC CC_REG))]
207  ""
208{
209  if (find_reg_note (insn, REG_UNUSED, operands[3]))
210    return "divxs.w\\t%T2,%S0";
211  else
212    return "divxs.w\\t%T2,%S0\;mov.w\\t%e0,%f3";
213}
214  [(set_attr "length" "6")])
215