1 ;; ARM Cortex-R4 scheduling description.
2 ;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
3 ;; Contributed by CodeSourcery.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 ;; License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
21 (define_automaton "cortex_r4")
23 ;; We approximate the dual-issue constraints of this core using four
24 ;; "issue units" and a reservation matrix as follows. The numbers indicate
25 ;; the instruction groups' preferences in order. Multiple entries for
26 ;; the same numbered preference indicate units that must be reserved
29 ;; Issue unit: A B C ALU
31 ;; ALU w/o reg shift 1st 2nd 1st and 2nd
32 ;; ALU w/ reg shift 1st 2nd 2nd 1st and 2nd
34 ;; Multiplication 1st 1st
36 ;; Load/store single 1st 1st
37 ;; Other load/store 1st 1st
40 (define_cpu_unit "cortex_r4_issue_a" "cortex_r4")
41 (define_cpu_unit "cortex_r4_issue_b" "cortex_r4")
42 (define_cpu_unit "cortex_r4_issue_c" "cortex_r4")
43 (define_cpu_unit "cortex_r4_issue_alu" "cortex_r4")
45 (define_reservation "cortex_r4_alu"
46 "(cortex_r4_issue_a+cortex_r4_issue_alu)|\
47 (cortex_r4_issue_b+cortex_r4_issue_alu)")
48 (define_reservation "cortex_r4_alu_shift_reg"
49 "(cortex_r4_issue_a+cortex_r4_issue_alu)|\
50 (cortex_r4_issue_b+cortex_r4_issue_c+\
51 cortex_r4_issue_alu)")
52 (define_reservation "cortex_r4_mov"
53 "cortex_r4_issue_a|(cortex_r4_issue_b+\
54 cortex_r4_issue_alu)")
55 (define_reservation "cortex_r4_mul" "cortex_r4_issue_a+cortex_r4_issue_alu")
56 (define_reservation "cortex_r4_mul_2"
57 "(cortex_r4_issue_a+cortex_r4_issue_alu)*2")
58 ;; Division instructions execute out-of-order with respect to the
59 ;; rest of the pipeline and only require reservations on their first and
61 (define_reservation "cortex_r4_div_9"
62 "cortex_r4_issue_a+cortex_r4_issue_alu,\
64 cortex_r4_issue_a+cortex_r4_issue_alu")
65 (define_reservation "cortex_r4_div_10"
66 "cortex_r4_issue_a+cortex_r4_issue_alu,\
68 cortex_r4_issue_a+cortex_r4_issue_alu")
69 (define_reservation "cortex_r4_load_store"
70 "cortex_r4_issue_a+cortex_r4_issue_c")
71 (define_reservation "cortex_r4_load_store_2"
72 "(cortex_r4_issue_a+cortex_r4_issue_b)*2")
73 (define_reservation "cortex_r4_branch" "cortex_r4_issue_b")
75 ;; We assume that all instructions are unconditional.
77 ;; Data processing instructions. Moves without shifts are kept separate
78 ;; for the purposes of the dual-issue constraints above.
79 (define_insn_reservation "cortex_r4_alu" 2
80 (and (eq_attr "tune_cortexr4" "yes")
81 (eq_attr "type" "arlo_imm,arlo_reg,shift,shift_reg,mvn_imm,mvn_reg"))
84 (define_insn_reservation "cortex_r4_mov" 2
85 (and (eq_attr "tune_cortexr4" "yes")
86 (eq_attr "type" "mov_imm,mov_reg"))
89 (define_insn_reservation "cortex_r4_alu_shift" 2
90 (and (eq_attr "tune_cortexr4" "yes")
91 (eq_attr "type" "extend,arlo_shift,mov_shift,mvn_shift"))
94 (define_insn_reservation "cortex_r4_alu_shift_reg" 2
95 (and (eq_attr "tune_cortexr4" "yes")
96 (eq_attr "type" "arlo_shift_reg,mov_shift_reg,mvn_shift_reg"))
97 "cortex_r4_alu_shift_reg")
99 ;; An ALU instruction followed by an ALU instruction with no early dep.
100 (define_bypass 1 "cortex_r4_alu,cortex_r4_alu_shift,cortex_r4_alu_shift_reg,\
103 (define_bypass 1 "cortex_r4_alu,cortex_r4_alu_shift,cortex_r4_alu_shift_reg,\
105 "cortex_r4_alu_shift"
106 "arm_no_early_alu_shift_dep")
107 (define_bypass 1 "cortex_r4_alu,cortex_r4_alu_shift,cortex_r4_alu_shift_reg,\
109 "cortex_r4_alu_shift_reg"
110 "arm_no_early_alu_shift_value_dep")
112 ;; In terms of availabilities, a consumer mov could theoretically be
113 ;; issued together with a producer ALU instruction, without stalls.
114 ;; In practice this cannot happen because mov;add (in that order) is not
115 ;; eligible for dual issue and furthermore dual issue is not permitted
116 ;; when a dependency is involved. We therefore note it as latency one.
117 ;; A mov followed by another of the same is also latency one.
118 (define_bypass 1 "cortex_r4_alu,cortex_r4_alu_shift,cortex_r4_alu_shift_reg,\
122 ;; qadd, qdadd, qsub and qdsub are not currently emitted, and neither are
123 ;; media data processing instructions nor sad instructions.
125 ;; Multiplication instructions.
127 (define_insn_reservation "cortex_r4_mul_4" 4
128 (and (eq_attr "tune_cortexr4" "yes")
129 (eq_attr "type" "mul,smmul"))
132 (define_insn_reservation "cortex_r4_mul_3" 3
133 (and (eq_attr "tune_cortexr4" "yes")
134 (eq_attr "type" "smulxy,smulwy,smuad,smusd"))
137 (define_insn_reservation "cortex_r4_mla_4" 4
138 (and (eq_attr "tune_cortexr4" "yes")
139 (eq_attr "type" "mla,smmla"))
142 (define_insn_reservation "cortex_r4_mla_3" 3
143 (and (eq_attr "tune_cortexr4" "yes")
144 (eq_attr "type" "smlaxy,smlawy,smlad,smlsd"))
147 (define_insn_reservation "cortex_r4_smlald" 3
148 (and (eq_attr "tune_cortexr4" "yes")
149 (eq_attr "type" "smlald,smlsld"))
152 (define_insn_reservation "cortex_r4_mull" 4
153 (and (eq_attr "tune_cortexr4" "yes")
154 (eq_attr "type" "smull,umull,umlal,umaal"))
157 ;; A multiply or an MLA with a single-register result, followed by an
158 ;; MLA with an accumulator dependency, has its result forwarded.
159 (define_bypass 2 "cortex_r4_mul_3,cortex_r4_mla_3"
160 "cortex_r4_mla_3,cortex_r4_mla_4"
161 "arm_mac_accumulator_is_mul_result")
163 (define_bypass 3 "cortex_r4_mul_4,cortex_r4_mla_4"
164 "cortex_r4_mla_3,cortex_r4_mla_4"
165 "arm_mac_accumulator_is_mul_result")
167 ;; A multiply followed by an ALU instruction needing the multiply
168 ;; result only at ALU has lower latency than one needing it at Shift.
169 (define_bypass 2 "cortex_r4_mul_3,cortex_r4_mla_3,cortex_r4_smlald"
171 (define_bypass 2 "cortex_r4_mul_3,cortex_r4_mla_3,cortex_r4_smlald"
172 "cortex_r4_alu_shift"
173 "arm_no_early_alu_shift_dep")
174 (define_bypass 2 "cortex_r4_mul_3,cortex_r4_mla_3,cortex_r4_smlald"
175 "cortex_r4_alu_shift_reg"
176 "arm_no_early_alu_shift_value_dep")
177 (define_bypass 3 "cortex_r4_mul_4,cortex_r4_mla_4,cortex_r4_mull"
179 (define_bypass 3 "cortex_r4_mul_4,cortex_r4_mla_4,cortex_r4_mull"
180 "cortex_r4_alu_shift"
181 "arm_no_early_alu_shift_dep")
182 (define_bypass 3 "cortex_r4_mul_4,cortex_r4_mla_4,cortex_r4_mull"
183 "cortex_r4_alu_shift_reg"
184 "arm_no_early_alu_shift_value_dep")
186 ;; A multiply followed by a mov has one cycle lower latency again.
187 (define_bypass 1 "cortex_r4_mul_3,cortex_r4_mla_3,cortex_r4_smlald"
189 (define_bypass 2 "cortex_r4_mul_4,cortex_r4_mla_4,cortex_r4_mull"
192 ;; We guess that division of A/B using sdiv or udiv, on average,
193 ;; is performed with B having ten more leading zeros than A.
194 ;; This gives a latency of nine for udiv and ten for sdiv.
195 (define_insn_reservation "cortex_r4_udiv" 9
196 (and (eq_attr "tune_cortexr4" "yes")
197 (eq_attr "type" "udiv"))
200 (define_insn_reservation "cortex_r4_sdiv" 10
201 (and (eq_attr "tune_cortexr4" "yes")
202 (eq_attr "type" "sdiv"))
205 ;; Branches. We assume correct prediction.
207 (define_insn_reservation "cortex_r4_branch" 0
208 (and (eq_attr "tune_cortexr4" "yes")
209 (eq_attr "type" "branch"))
212 ;; Call latencies are not predictable. A semi-arbitrary very large
213 ;; number is used as "positive infinity" so that everything should be
214 ;; finished by the time of return.
215 (define_insn_reservation "cortex_r4_call" 32
216 (and (eq_attr "tune_cortexr4" "yes")
217 (eq_attr "type" "call"))
220 ;; Status register access instructions are not currently emitted.
222 ;; Load instructions.
223 ;; We do not model the "addr_md_3cycle" cases and assume that
224 ;; accesses following are correctly aligned.
226 (define_insn_reservation "cortex_r4_load_1_2" 3
227 (and (eq_attr "tune_cortexr4" "yes")
228 (eq_attr "type" "load1,load2"))
229 "cortex_r4_load_store")
231 (define_insn_reservation "cortex_r4_load_3_4" 4
232 (and (eq_attr "tune_cortexr4" "yes")
233 (eq_attr "type" "load3,load4"))
234 "cortex_r4_load_store_2")
236 ;; If a producing load is followed by an instruction consuming only
237 ;; as a Normal Reg, there is one fewer cycle of latency.
239 (define_bypass 2 "cortex_r4_load_1_2"
241 (define_bypass 2 "cortex_r4_load_1_2"
242 "cortex_r4_alu_shift"
243 "arm_no_early_alu_shift_dep")
244 (define_bypass 2 "cortex_r4_load_1_2"
245 "cortex_r4_alu_shift_reg"
246 "arm_no_early_alu_shift_value_dep")
248 (define_bypass 3 "cortex_r4_load_3_4"
250 (define_bypass 3 "cortex_r4_load_3_4"
251 "cortex_r4_alu_shift"
252 "arm_no_early_alu_shift_dep")
253 (define_bypass 3 "cortex_r4_load_3_4"
254 "cortex_r4_alu_shift_reg"
255 "arm_no_early_alu_shift_value_dep")
257 ;; If a producing load is followed by an instruction consuming only
258 ;; as a Late Reg, there are two fewer cycles of latency. Such consumer
259 ;; instructions are moves and stores.
261 (define_bypass 1 "cortex_r4_load_1_2"
262 "cortex_r4_mov,cortex_r4_store_1_2,cortex_r4_store_3_4")
263 (define_bypass 2 "cortex_r4_load_3_4"
264 "cortex_r4_mov,cortex_r4_store_1_2,cortex_r4_store_3_4")
266 ;; If a producer's result is required as the base or offset of a load,
267 ;; there is an extra cycle latency.
269 (define_bypass 3 "cortex_r4_alu,cortex_r4_mov,cortex_r4_alu_shift,\
270 cortex_r4_alu_shift_reg"
271 "cortex_r4_load_1_2,cortex_r4_load_3_4")
273 (define_bypass 4 "cortex_r4_mul_3,cortex_r4_mla_3,cortex_r4_smlald"
274 "cortex_r4_load_1_2,cortex_r4_load_3_4")
276 (define_bypass 5 "cortex_r4_mul_4,cortex_r4_mla_4,cortex_r4_mull"
277 "cortex_r4_load_1_2,cortex_r4_load_3_4")
279 ;; Store instructions.
281 (define_insn_reservation "cortex_r4_store_1_2" 0
282 (and (eq_attr "tune_cortexr4" "yes")
283 (eq_attr "type" "store1,store2"))
284 "cortex_r4_load_store")
286 (define_insn_reservation "cortex_r4_store_3_4" 0
287 (and (eq_attr "tune_cortexr4" "yes")
288 (eq_attr "type" "store3,store4"))
289 "cortex_r4_load_store_2")