2007-01-03 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / gcc / config / i386 / pentium.md
blobc2fcf9ec8a119e35c1b013020126e41589153957
1 ;; Pentium Scheduling
2 ;; Copyright (C) 2002 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC 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)
9 ;; any later version.
11 ;; GCC 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 GCC; see the file COPYING.  If not, write to
18 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.  */
21 ;; The Pentium is an in-order core with two integer pipelines.
23 ;; True for insns that behave like prefixed insns on the Pentium.
24 (define_attr "pent_prefix" "false,true"
25   (if_then_else (ior (eq_attr "prefix_0f" "1")
26                      (ior (eq_attr "prefix_data16" "1")
27                           (eq_attr "prefix_rep" "1")))
28     (const_string "true")
29     (const_string "false")))
31 ;; Categorize how an instruction slots.
33 ;; The non-MMX Pentium slots an instruction with prefixes on U pipe only,
34 ;; while MMX Pentium can slot it on either U or V.  Model non-MMX Pentium
35 ;; rules, because it results in noticeably better code on non-MMX Pentium
36 ;; and doesn't hurt much on MMX.  (Prefixed instructions are not very
37 ;; common, so the scheduler usually has a non-prefixed insn to pair).
39 (define_attr "pent_pair" "uv,pu,pv,np"
40   (cond [(eq_attr "imm_disp" "true")
41            (const_string "np")
42          (ior (eq_attr "type" "alu1,alu,imov,icmp,test,lea,incdec")
43               (and (eq_attr "type" "pop,push")
44                    (eq_attr "memory" "!both")))
45            (if_then_else (eq_attr "pent_prefix" "true")
46              (const_string "pu")
47              (const_string "uv"))
48          (eq_attr "type" "ibr")
49            (const_string "pv")
50          (and (eq_attr "type" "ishift")
51               (match_operand 2 "const_int_operand" ""))
52            (const_string "pu")
53          (and (eq_attr "type" "rotate")
54               (match_operand 2 "const1_operand" ""))
55            (const_string "pu")
56          (and (eq_attr "type" "ishift1")
57               (match_operand 1 "const_int_operand" ""))
58            (const_string "pu")
59          (and (eq_attr "type" "rotate1")
60               (match_operand 1 "const1_operand" ""))
61            (const_string "pu")
62          (and (eq_attr "type" "call")
63               (match_operand 0 "constant_call_address_operand" ""))
64            (const_string "pv")
65          (and (eq_attr "type" "callv")
66               (match_operand 1 "constant_call_address_operand" ""))
67            (const_string "pv")
68         ]
69         (const_string "np")))
71 (define_automaton "pentium,pentium_fpu")
73 ;; Pentium do have U and V pipes.  Instruction to both pipes
74 ;; are always issued together, much like on VLIW.
76 ;;                    predecode
77 ;;                   /         \
78 ;;               decodeu     decodev
79 ;;             /    |           |
80 ;;           fpu executeu    executev
81 ;;            |     |           |
82 ;;           fpu  retire     retire
83 ;;            |
84 ;;           fpu
85 ;; We add dummy "port" pipes allocated only first cycle of
86 ;; instruction to specify this behavior.
88 (define_cpu_unit "pentium-portu,pentium-portv" "pentium")
89 (define_cpu_unit "pentium-u,pentium-v" "pentium")
90 (absence_set "pentium-portu" "pentium-u,pentium-v")
91 (presence_set "pentium-portv" "pentium-portu")
93 ;; Floating point instructions can overlap with new issue of integer
94 ;; instructions.  We model only first cycle of FP pipeline, as it is
95 ;; fully pipelined.
96 (define_cpu_unit "pentium-fp" "pentium_fpu")
98 ;; There is non-pipelined multiplier unit used for complex operations.
99 (define_cpu_unit "pentium-fmul" "pentium_fpu")
101 ;; Pentium preserves memory ordering, so when load-execute-store
102 ;; instruction is executed together with other instruction loading
103 ;; data, the execution of the other instruction is delayed to very
104 ;; last cycle of first instruction, when data are bypassed.
105 ;; We model this by allocating "memory" unit when store is pending
106 ;; and using conflicting load units together.
108 (define_cpu_unit "pentium-memory" "pentium")
109 (define_cpu_unit "pentium-load0" "pentium")
110 (define_cpu_unit "pentium-load1" "pentium")
111 (absence_set "pentium-load0,pentium-load1" "pentium-memory")
113 (define_reservation "pentium-load" "(pentium-load0 | pentium-load1)")
114 (define_reservation "pentium-np" "(pentium-u + pentium-v)")
115 (define_reservation "pentium-uv" "(pentium-u | pentium-v)")
116 (define_reservation "pentium-portuv" "(pentium-portu | pentium-portv)")
117 (define_reservation "pentium-firstu" "(pentium-u + pentium-portu)")
118 (define_reservation "pentium-firstv" "(pentium-v + pentium-portuv)")
119 (define_reservation "pentium-firstuv" "(pentium-uv + pentium-portuv)")
120 (define_reservation "pentium-firstuload" "(pentium-load + pentium-firstu)")
121 (define_reservation "pentium-firstvload" "(pentium-load + pentium-firstv)")
122 (define_reservation "pentium-firstuvload" "(pentium-load + pentium-firstuv)
123                                            | (pentium-firstv,pentium-v,
124                                               (pentium-load+pentium-firstv))")
125 (define_reservation "pentium-firstuboth" "(pentium-load + pentium-firstu
126                                            + pentium-memory)")
127 (define_reservation "pentium-firstvboth" "(pentium-load + pentium-firstv
128                                            + pentium-memory)")
129 (define_reservation "pentium-firstuvboth" "(pentium-load + pentium-firstuv
130                                             + pentium-memory)
131                                            | (pentium-firstv,pentium-v,
132                                               (pentium-load+pentium-firstv))")
134 ;; Few common long latency instructions
135 (define_insn_reservation "pent_mul" 11
136   (and (eq_attr "cpu" "pentium")
137        (eq_attr "type" "imul"))
138   "pentium-np*11")
140 (define_insn_reservation "pent_str" 12
141   (and (eq_attr "cpu" "pentium")
142        (eq_attr "type" "str"))
143   "pentium-np*12")
145 ;; Integer division and some other long latency instruction block all
146 ;; units, including the FP pipe.  There is no value in modeling the
147 ;; latency of these instructions and not modeling the latency
148 ;; decreases the size of the DFA.
149 (define_insn_reservation "pent_block" 1
150   (and (eq_attr "cpu" "pentium")
151        (eq_attr "type" "idiv"))
152   "pentium-np+pentium-fp")
154 ;;  Moves usually have one cycle penalty, but there are exceptions.
155 (define_insn_reservation "pent_fmov" 1
156   (and (eq_attr "cpu" "pentium")
157        (and (eq_attr "type" "fmov")
158             (eq_attr "memory" "none,load")))
159   "(pentium-fp+pentium-np)")
161 (define_insn_reservation "pent_fpmovxf" 3
162   (and (eq_attr "cpu" "pentium")
163        (and (eq_attr "type" "fmov")
164             (and (eq_attr "memory" "load,store")
165                  (eq_attr "mode" "XF"))))
166   "(pentium-fp+pentium-np)*3")
168 (define_insn_reservation "pent_fpstore" 2
169   (and (eq_attr "cpu" "pentium")
170        (and (eq_attr "type" "fmov")
171             (ior (match_operand 1 "immediate_operand" "")
172                  (eq_attr "memory" "store"))))
173   "(pentium-fp+pentium-np)*2")
175 (define_insn_reservation "pent_imov" 1
176   (and (eq_attr "cpu" "pentium")
177        (eq_attr "type" "imov"))
178   "pentium-firstuv")
180 ;; Push and pop instructions have 1 cycle latency and special
181 ;; hardware bypass allows them to be paired with other push,pop
182 ;; and call instructions.
183 (define_bypass 0 "pent_push,pent_pop" "pent_push,pent_pop,pent_call")
184 (define_insn_reservation "pent_push" 1
185   (and (eq_attr "cpu" "pentium")
186        (and (eq_attr "type" "push")
187             (eq_attr "memory" "store")))
188   "pentium-firstuv")
190 (define_insn_reservation "pent_pop" 1
191   (and (eq_attr "cpu" "pentium")
192        (eq_attr "type" "pop,leave"))
193   "pentium-firstuv")
195 ;; Call and branch instruction can execute in either pipe, but
196 ;; they are only pairable when in the v pipe.
197 (define_insn_reservation "pent_call" 10
198   (and (eq_attr "cpu" "pentium")
199        (eq_attr "type" "call,callv"))
200   "pentium-firstv,pentium-v*9")
202 (define_insn_reservation "pent_branch" 1
203   (and (eq_attr "cpu" "pentium")
204        (eq_attr "type" "ibr"))
205   "pentium-firstv")
207 ;; Floating point instruction dispatch in U pipe, but continue
208 ;; in FP pipeline allowing other instructions to be executed.
209 (define_insn_reservation "pent_fp" 3
210   (and (eq_attr "cpu" "pentium")
211        (eq_attr "type" "fop,fistp"))
212   "(pentium-firstu+pentium-fp),nothing,nothing")
214 ;; First two cycles of fmul are not pipelined.
215 (define_insn_reservation "pent_fmul" 3
216   (and (eq_attr "cpu" "pentium")
217        (eq_attr "type" "fmul"))
218   "(pentium-firstuv+pentium-fp+pentium-fmul),pentium-fmul,nothing")
220 ;; Long latency FP instructions overlap with integer instructions,
221 ;; but only last 2 cycles with FP ones.
222 (define_insn_reservation "pent_fdiv" 39
223   (and (eq_attr "cpu" "pentium")
224        (eq_attr "type" "fdiv"))
225   "(pentium-np+pentium-fp+pentium-fmul),
226    (pentium-fp+pentium-fmul)*36,pentium-fmul*2")
228 (define_insn_reservation "pent_fpspc" 70
229   (and (eq_attr "cpu" "pentium")
230        (eq_attr "type" "fpspc"))
231   "(pentium-np+pentium-fp+pentium-fmul),
232    (pentium-fp+pentium-fmul)*67,pentium-fmul*2")
234 ;; Integer instructions.  Load/execute/store takes 3 cycles,
235 ;; load/execute 2 cycles and execute only one cycle.
236 (define_insn_reservation "pent_uv_both" 3
237   (and (eq_attr "cpu" "pentium")
238        (and (eq_attr "pent_pair" "uv")
239             (eq_attr "memory" "both")))
240   "pentium-firstuvboth,pentium-uv+pentium-memory,pentium-uv")
242 (define_insn_reservation "pent_u_both" 3
243   (and (eq_attr "cpu" "pentium")
244        (and (eq_attr "pent_pair" "pu")
245             (eq_attr "memory" "both")))
246   "pentium-firstuboth,pentium-u+pentium-memory,pentium-u")
248 (define_insn_reservation "pent_v_both" 3
249   (and (eq_attr "cpu" "pentium")
250        (and (eq_attr "pent_pair" "pv")
251             (eq_attr "memory" "both")))
252   "pentium-firstvboth,pentium-v+pentium-memory,pentium-v")
254 (define_insn_reservation "pent_np_both" 3
255   (and (eq_attr "cpu" "pentium")
256        (and (eq_attr "pent_pair" "np")
257             (eq_attr "memory" "both")))
258   "pentium-np,pentium-np,pentium-np")
260 (define_insn_reservation "pent_uv_load" 2
261   (and (eq_attr "cpu" "pentium")
262        (and (eq_attr "pent_pair" "uv")
263             (eq_attr "memory" "load")))
264   "pentium-firstuvload,pentium-uv")
266 (define_insn_reservation "pent_u_load" 2
267   (and (eq_attr "cpu" "pentium")
268        (and (eq_attr "pent_pair" "pu")
269             (eq_attr "memory" "load")))
270   "pentium-firstuload,pentium-u")
272 (define_insn_reservation "pent_v_load" 2
273   (and (eq_attr "cpu" "pentium")
274        (and (eq_attr "pent_pair" "pv")
275             (eq_attr "memory" "load")))
276   "pentium-firstvload,pentium-v")
278 (define_insn_reservation "pent_np_load" 2
279   (and (eq_attr "cpu" "pentium")
280        (and (eq_attr "pent_pair" "np")
281             (eq_attr "memory" "load")))
282   "pentium-np,pentium-np")
284 (define_insn_reservation "pent_uv" 1
285   (and (eq_attr "cpu" "pentium")
286        (and (eq_attr "pent_pair" "uv")
287             (eq_attr "memory" "none")))
288   "pentium-firstuv")
290 (define_insn_reservation "pent_u" 1
291   (and (eq_attr "cpu" "pentium")
292        (and (eq_attr "pent_pair" "pu")
293             (eq_attr "memory" "none")))
294   "pentium-firstu")
296 (define_insn_reservation "pent_v" 1
297   (and (eq_attr "cpu" "pentium")
298        (and (eq_attr "pent_pair" "pv")
299             (eq_attr "memory" "none")))
300   "pentium-firstv")
302 (define_insn_reservation "pent_np" 1
303   (and (eq_attr "cpu" "pentium")
304        (and (eq_attr "pent_pair" "np")
305             (eq_attr "memory" "none")))
306   "pentium-np")