1 ;; DFA scheduling description for SH4.
2 ;; Copyright (C) 2004 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
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)
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 ;; Load and store instructions save a cycle if they are aligned on a
22 ;; four byte boundary. Using a function unit for stores encourages
23 ;; gcc to separate load and store instructions by one instruction,
24 ;; which makes it more likely that the linker will be able to word
25 ;; align them when relaxing.
27 ;; The following description models the SH4 pipeline using the DFA based
28 ;; scheduler. The DFA based description is better way to model a
29 ;; superscalar pipeline as compared to function unit reservation model.
30 ;; 1. The function unit based model is oriented to describe at most one
31 ;; unit reservation by each insn. It is difficult to model unit reservations
32 ;; in multiple pipeline units by same insn. This can be done using DFA
34 ;; 2. The execution performance of DFA based scheduler does not depend on
35 ;; processor complexity.
36 ;; 3. Writing all unit reservations for an instruction class is a more natural
37 ;; description of the pipeline and makes the interface to the hazard
38 ;; recognizer simpler than the old function unit based model.
39 ;; 4. The DFA model is richer and is a part of greater overall framework
43 ;; Two automata are defined to reduce number of states
44 ;; which a single large automaton will have. (Factoring)
46 (define_automaton "inst_pipeline,fpu_pipe")
48 ;; This unit is basically the decode unit of the processor.
49 ;; Since SH4 is a dual issue machine,it is as if there are two
50 ;; units so that any insn can be processed by either one
51 ;; of the decoding unit.
53 (define_cpu_unit "pipe_01,pipe_02" "inst_pipeline")
56 ;; The fixed point arithmetic calculator(?? EX Unit).
58 (define_cpu_unit "int" "inst_pipeline")
60 ;; f1_1 and f1_2 are floating point units.Actually there is
61 ;; a f1 unit which can overlap with other f1 unit but
62 ;; not another F1 unit.It is as though there were two
65 (define_cpu_unit "f1_1,f1_2" "fpu_pipe")
67 ;; The floating point units (except FS - F2 always precedes it.)
69 (define_cpu_unit "F0,F1,F2,F3" "fpu_pipe")
71 ;; This is basically the MA unit of SH4
72 ;; used in LOAD/STORE pipeline.
74 (define_cpu_unit "memory" "inst_pipeline")
76 ;; However, there are LS group insns that don't use it, even ones that
77 ;; complete in 0 cycles. So we use an extra unit for the issue of LS insns.
78 (define_cpu_unit "load_store" "inst_pipeline")
80 ;; The address calculator used for branch instructions.
81 ;; This will be reserved after "issue" of branch instructions
82 ;; and this is to make sure that no two branch instructions
83 ;; can be issued in parallel.
85 (define_cpu_unit "pcr_addrcalc" "inst_pipeline")
87 ;; ----------------------------------------------------
88 ;; This reservation is to simplify the dual issue description.
90 (define_reservation "issue" "pipe_01|pipe_02")
92 ;; This is to express the locking of D stage.
93 ;; Note that the issue of a CO group insn also effectively locks the D stage.
95 (define_reservation "d_lock" "pipe_01+pipe_02")
97 ;; Every FE instruction but fipr / ftrv starts with issue and this.
98 (define_reservation "F01" "F0+F1")
100 ;; This is to simplify description where F1,F2,FS
101 ;; are used simultaneously.
103 (define_reservation "fpu" "F1+F2")
105 ;; This is to highlight the fact that f1
106 ;; cannot overlap with F1.
108 (exclusion_set "f1_1,f1_2" "F1")
110 (define_insn_reservation "nil" 0 (eq_attr "type" "nil") "nothing")
112 ;; Although reg moves have a latency of zero
113 ;; we need to highlight that they use D stage
118 (define_insn_reservation "reg_mov" 0
119 (and (eq_attr "pipe_model" "sh4")
120 (eq_attr "type" "move"))
125 (define_insn_reservation "freg_mov" 0
126 (and (eq_attr "pipe_model" "sh4")
127 (eq_attr "type" "fmove"))
130 ;; We don't model all pipeline stages; we model the issue ('D') stage
131 ;; inasmuch as we allow only two instructions to issue simultaneously,
132 ;; and CO instructions prevent any simultaneous issue of another instruction.
133 ;; (This uses pipe_01 and pipe_02).
134 ;; Double issue of EX insns is prevented by using the int unit in the EX stage.
135 ;; Double issue of EX / BR insns is prevented by using the int unit /
136 ;; pcr_addrcalc unit in the EX stage.
137 ;; Double issue of BR / LS instructions is prevented by using the
138 ;; pcr_addrcalc / load_store unit in the issue cycle.
139 ;; Double issue of FE instructions is prevented by using F0 in the first
140 ;; pipeline stage after the first D stage.
141 ;; There is no need to describe the [ES]X / [MN]A / S stages after a D stage
142 ;; (except in the cases outlined above), nor to describe the FS stage after
145 ;; Other MT group instructions(1 step operations)
150 (define_insn_reservation "mt" 1
151 (and (eq_attr "pipe_model" "sh4")
152 (eq_attr "type" "mt_group"))
155 ;; Fixed Point Arithmetic Instructions(1 step operations)
160 (define_insn_reservation "sh4_simple_arith" 1
161 (and (eq_attr "pipe_model" "sh4")
162 (eq_attr "insn_class" "ex_group"))
165 ;; Load and store instructions have no alignment peculiarities for the SH4,
166 ;; but they use the load-store unit, which they share with the fmove type
167 ;; insns (fldi[01]; fmov frn,frm; flds; fsts; fabs; fneg) .
168 ;; Loads have a latency of two.
169 ;; However, call insns can only paired with a preceding insn, and have
170 ;; a delay slot, so that we want two more insns to be scheduled between the
171 ;; load of the function address and the call. This is equivalent to a
173 ;; ADJUST_COST can only properly handle reductions of the cost, so we
174 ;; use a latency of three here, which gets multiplied by 10 to yield 30.
175 ;; We only do this for SImode loads of general registers, to make the work
176 ;; for ADJUST_COST easier.
178 ;; Load Store instructions. (MOV.[BWL]@(d,GBR)
183 (define_insn_reservation "sh4_load" 2
184 (and (eq_attr "pipe_model" "sh4")
185 (eq_attr "type" "load,pcload"))
186 "issue+load_store,nothing,memory")
188 ;; calls / sfuncs need an extra instruction for their delay slot.
189 ;; Moreover, estimating the latency for SImode loads as 3 will also allow
190 ;; adjust_cost to meaningfully bump it back up to 3 if they load the shift
191 ;; count of a dynamic shift.
192 (define_insn_reservation "sh4_load_si" 3
193 (and (eq_attr "pipe_model" "sh4")
194 (eq_attr "type" "load_si,pcload_si"))
195 "issue+load_store,nothing,memory")
197 ;; (define_bypass 2 "sh4_load_si" "!sh4_call")
199 ;; The load latency is upped to three higher if the dependent insn does
200 ;; double precision computation. We want the 'default' latency to reflect
201 ;; that increased latency because otherwise the insn priorities won't
202 ;; allow proper scheduling.
203 (define_insn_reservation "sh4_fload" 3
204 (and (eq_attr "pipe_model" "sh4")
205 (eq_attr "type" "fload,pcfload"))
206 "issue+load_store,nothing,memory")
208 ;; (define_bypass 2 "sh4_fload" "!")
210 (define_insn_reservation "sh4_store" 1
211 (and (eq_attr "pipe_model" "sh4")
212 (eq_attr "type" "store"))
213 "issue+load_store,nothing,memory")
215 ;; Load Store instructions.
220 (define_insn_reservation "sh4_gp_fpul" 1
221 (and (eq_attr "pipe_model" "sh4")
222 (eq_attr "type" "gp_fpul"))
225 ;; Load Store instructions.
230 (define_insn_reservation "sh4_fpul_gp" 3
231 (and (eq_attr "pipe_model" "sh4")
232 (eq_attr "type" "fpul_gp"))
235 ;; Branch (BF,BF/S,BT,BT/S,BRA)
237 ;; Latency when taken: 2 (or 1)
239 ;; The latency is 1 when displacement is 0.
240 ;; We can't really do much with the latency, even if we could express it,
241 ;; but the pairing restrictions are useful to take into account.
242 ;; ??? If the branch is likely, we might want to fill the delay slot;
243 ;; if the branch is likely, but not very likely, should we pretend to use
244 ;; a resource that CO instructions use, to get a pairable delay slot insn?
246 (define_insn_reservation "sh4_branch" 1
247 (and (eq_attr "pipe_model" "sh4")
248 (eq_attr "type" "cbranch,jump"))
249 "issue+pcr_addrcalc")
251 ;; Branch Far (JMP,RTS,BRAF)
255 ;; ??? Scheduling happens before branch shortening, and hence jmp and braf
256 ;; can't be distinguished from bra for the "jump" pattern.
258 (define_insn_reservation "sh4_return" 3
259 (and (eq_attr "pipe_model" "sh4")
260 (eq_attr "type" "return,jump_ind"))
267 ;; this instruction can be executed in any of the pipelines
268 ;; and blocks the pipeline for next 4 stages.
270 (define_insn_reservation "sh4_return_from_exp" 5
271 (and (eq_attr "pipe_model" "sh4")
272 (eq_attr "type" "rte"))
280 ;; cwb is used for the sequence ocbwb @%0; extu.w %0,%2; or %1,%2; mov.l %0,@%2
281 ;; ocbwb on its own would be "d_lock,nothing,memory*5"
282 (define_insn_reservation "ocbwb" 6
283 (and (eq_attr "pipe_model" "sh4")
284 (eq_attr "type" "cwb"))
285 "d_lock*2,(d_lock+memory)*3,issue+load_store+memory,memory*2")
291 ;; The SX stage is blocked for last 2 cycles.
292 ;; OTOH, the only time that has an effect for insns generated by the compiler
293 ;; is when lds to PR is followed by sts from PR - and that is highly unlikely -
294 ;; or when we are doing a function call - and we don't do inter-function
295 ;; scheduling. For the function call case, it's really best that we end with
296 ;; something that models an rts.
298 (define_insn_reservation "sh4_lds_to_pr" 3
299 (and (eq_attr "pipe_model" "sh4")
300 (eq_attr "type" "prset") )
303 ;; calls introduce a longisch delay that is likely to flush the pipelines
304 ;; of the caller's instructions. Ordinary functions tend to end with a
305 ;; load to restore a register (in the delay slot of rts), while sfuncs
306 ;; tend to end with an EX or MT insn. But that is not actually relevant,
307 ;; since there are no instructions that contend for memory access early.
308 ;; We could, of course, provide exact scheduling information for specific
309 ;; sfuncs, if that should prove useful.
311 (define_insn_reservation "sh4_call" 16
312 (and (eq_attr "pipe_model" "sh4")
313 (eq_attr "type" "call,sfunc"))
320 ;; The SX unit is blocked for last 2 cycles.
322 (define_insn_reservation "ldsmem_to_pr" 3
323 (and (eq_attr "pipe_model" "sh4")
324 (eq_attr "type" "pload"))
331 ;; The SX unit in second and third cycles.
333 (define_insn_reservation "sts_from_pr" 2
334 (and (eq_attr "pipe_model" "sh4")
335 (eq_attr "type" "prget"))
343 (define_insn_reservation "sh4_prstore_mem" 2
344 (and (eq_attr "pipe_model" "sh4")
345 (eq_attr "type" "pstore"))
346 "d_lock*2,nothing,memory")
352 ;; F1 is blocked for last three cycles.
354 (define_insn_reservation "fpscr_load" 4
355 (and (eq_attr "pipe_model" "sh4")
356 (eq_attr "type" "gp_fpscr"))
357 "d_lock,nothing,F1*3")
362 ;; Latency to update Rn is 1 and latency to update FPSCR is 4
364 ;; F1 is blocked for last three cycles.
366 (define_insn_reservation "fpscr_load_mem" 4
367 (and (eq_attr "pipe_model" "sh4")
368 (eq_attr "type" "mem_fpscr"))
369 "d_lock,nothing,(F1+memory),F1*2")
372 ;; Fixed point multiplication (DMULS.L DMULU.L MUL.L MULS.W,MULU.W)
377 (define_insn_reservation "multi" 4
378 (and (eq_attr "pipe_model" "sh4")
379 (eq_attr "type" "smpy,dmpy"))
380 "d_lock,(d_lock+f1_1),(f1_1|f1_2)*3,F2")
382 ;; Fixed STS from MACL / MACH
387 (define_insn_reservation "sh4_mac_gp" 3
388 (and (eq_attr "pipe_model" "sh4")
389 (eq_attr "type" "mac_gp"))
393 ;; Single precision floating point computation FCMP/EQ,
394 ;; FCMP/GT, FADD, FLOAT, FMAC, FMUL, FSUB, FTRC, FRVHG, FSCHG
399 (define_insn_reservation "fp_arith" 3
400 (and (eq_attr "pipe_model" "sh4")
401 (eq_attr "type" "fp"))
404 (define_insn_reservation "fp_arith_ftrc" 3
405 (and (eq_attr "pipe_model" "sh4")
406 (eq_attr "type" "ftrc_s"))
409 (define_bypass 1 "fp_arith_ftrc" "sh4_fpul_gp")
411 ;; Single Precision FDIV/SQRT
413 ;; Latency: 12/13 (FDIV); 11/12 (FSQRT)
415 ;; We describe fdiv here; fsqrt is actually one cycle faster.
417 (define_insn_reservation "fp_div" 12
418 (and (eq_attr "pipe_model" "sh4")
419 (eq_attr "type" "fdiv"))
420 "issue,F01+F3,F2+F3,F3*7,F1+F3,F2")
422 ;; Double Precision floating point computation
423 ;; (FCNVDS, FCNVSD, FLOAT, FTRC)
428 (define_insn_reservation "dp_float" 4
429 (and (eq_attr "pipe_model" "sh4")
430 (eq_attr "type" "dfp_conv"))
431 "issue,F01,F1+F2,F2")
433 ;; Double-precision floating-point (FADD,FMUL,FSUB)
438 (define_insn_reservation "fp_double_arith" 8
439 (and (eq_attr "pipe_model" "sh4")
440 (eq_attr "type" "dfp_arith"))
441 "issue,F01,F1+F2,fpu*4,F2")
443 ;; Double-precision FCMP (FCMP/EQ,FCMP/GT)
448 (define_insn_reservation "fp_double_cmp" 3
449 (and (eq_attr "pipe_model" "sh4")
450 (eq_attr "type" "dfp_cmp"))
451 "d_lock,(d_lock+F01),F1+F2,F2")
453 ;; Double precision FDIV/SQRT
455 ;; Latency: (24,25)/26
458 (define_insn_reservation "dp_div" 25
459 (and (eq_attr "pipe_model" "sh4")
460 (eq_attr "type" "dfdiv"))
461 "issue,F01+F3,F1+F2+F3,F2+F3,F3*16,F1+F3,(fpu+F3)*2,F2")
464 ;; Use the branch-not-taken case to model arith3 insns. For the branch taken
465 ;; case, we'd get a d_lock instead of issue at the end.
466 (define_insn_reservation "arith3" 3
467 (and (eq_attr "pipe_model" "sh4")
468 (eq_attr "type" "arith3"))
469 "issue,d_lock+pcr_addrcalc,issue")
471 ;; arith3b insns schedule the same no matter if the branch is taken or not.
472 (define_insn_reservation "arith3b" 2
473 (and (eq_attr "pipe_model" "sh4")
474 (eq_attr "type" "arith3"))
475 "issue,d_lock+pcr_addrcalc")