2013-09-10 Christophe Lyon <christophe.lyon@linaro.org>
[official-gcc.git] / gcc-4_8-branch / gcc / config / arm / cortex-a7.md
blobe14413d5083a206052ee9c63a0b67fb336c1bc6f
1 ;; ARM Cortex-A7 pipeline description
2 ;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
3 ;;
4 ;; Contributed by ARM Ltd.
5 ;; Based on cortex-a5.md which was originally contributed by CodeSourcery.
6 ;;
7 ;; This file is part of GCC.
8 ;;
9 ;; GCC is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
14 ;; GCC is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING3.  If not see
21 ;; <http://www.gnu.org/licenses/>.
23 (define_automaton "cortex_a7")
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;; Functional units.
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; The Cortex-A7 pipeline integer and vfp pipeline.  
30 ;; The decode is the same for all instructions, so do not model it. 
31 ;; We only model the first execution stage because
32 ;; instructions always advance one stage per cycle in order. 
33 ;; We model all of the LS, Branch, ALU, MAC and FPU pipelines together. 
35 (define_cpu_unit "cortex_a7_ex1, cortex_a7_ex2" "cortex_a7")
37 (define_reservation "cortex_a7_both" "cortex_a7_ex1+cortex_a7_ex2")
39 (define_cpu_unit "cortex_a7_branch" "cortex_a7")
41 ;; Cortex-A7 is in order and can dual-issue under limited circumstances.
42 ;; ex2 can be reserved only after ex1 is reserved.
44 (final_presence_set "cortex_a7_ex2" "cortex_a7_ex1")
46 ;; Pseudo-unit for blocking the multiply pipeline when a double-precision
47 ;; multiply is in progress.
49 (define_cpu_unit "cortex_a7_fpmul_pipe" "cortex_a7")
51 ;; The floating-point add pipeline (ex1/f1 stage), used to model the usage
52 ;; of the add pipeline by fmac instructions, etc.
54 (define_cpu_unit "cortex_a7_fpadd_pipe" "cortex_a7")
56 ;; Floating-point div/sqrt (long latency, out-of-order completion).
58 (define_cpu_unit "cortex_a7_fp_div_sqrt" "cortex_a7")
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61 ;; Branches.
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;; A direct branch can dual issue either as younger or older instruction,
65 ;; but branches cannot dual issue with branches.
66 ;; No latency as there is no result.
68 (define_insn_reservation "cortex_a7_branch" 0
69   (and (eq_attr "tune" "cortexa7")
70        (and (eq_attr "type" "branch")
71             (eq_attr "neon_type" "none")))
72   "(cortex_a7_ex2|cortex_a7_ex1)+cortex_a7_branch")
74 ;; Call cannot dual-issue as an older instruction. It can dual-issue
75 ;; as a younger instruction, or single-issue.  Call cannot dual-issue
76 ;; with another branch instruction.  The result is available the next
77 ;; cycle.
78 (define_insn_reservation "cortex_a7_call" 1
79   (and (eq_attr "tune" "cortexa7")
80        (and (eq_attr "type" "call")
81             (eq_attr "neon_type" "none")))
82   "(cortex_a7_ex2|cortex_a7_both)+cortex_a7_branch")
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 ;; ALU instructions.
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
88 ;; ALU instruction with an immediate operand can dual-issue.
89 (define_insn_reservation "cortex_a7_alu_imm" 2
90   (and (eq_attr "tune" "cortexa7")
91        (and (ior (eq_attr "type" "arlo_imm,mov_imm,mvn_imm")
92                  (ior (eq_attr "type" "extend")
93                       (and (eq_attr "type" "mov_reg,mov_shift,mov_shift_reg")
94                            (not (eq_attr "length" "8")))))
95             (eq_attr "neon_type" "none")))
96   "cortex_a7_ex2|cortex_a7_ex1")
98 ;; ALU instruction with register operands can dual-issue
99 ;; with a younger immediate-based instruction.
100 (define_insn_reservation "cortex_a7_alu_reg" 2
101   (and (eq_attr "tune" "cortexa7")
102        (and (eq_attr "type" "arlo_reg,shift,shift_reg,mov_reg,mvn_reg")
103             (eq_attr "neon_type" "none")))
104   "cortex_a7_ex1")
106 (define_insn_reservation "cortex_a7_alu_shift" 2
107   (and (eq_attr "tune" "cortexa7")
108        (and (eq_attr "type" "arlo_shift,arlo_shift_reg,\
109                              mov_shift,mov_shift_reg,\
110                              mvn_shift,mvn_shift_reg")
111             (eq_attr "neon_type" "none")))
112   "cortex_a7_ex1")
114 ;; Forwarding path for unshifted operands.
115 (define_bypass 1 "cortex_a7_alu_imm,cortex_a7_alu_reg,cortex_a7_alu_shift"
116   "cortex_a7_alu_imm,cortex_a7_alu_reg,cortex_a7_mul")
118 (define_bypass 1 "cortex_a7_alu_imm,cortex_a7_alu_reg,cortex_a7_alu_shift"
119   "cortex_a7_store*"
120   "arm_no_early_store_addr_dep")
122 (define_bypass 1 "cortex_a7_alu_imm,cortex_a7_alu_reg,cortex_a7_alu_shift"
123   "cortex_a7_alu_shift"
124   "arm_no_early_alu_shift_dep")
126 ;; The multiplier pipeline can forward results from wr stage only so
127 ;; there's no need to specify bypasses.
128 ;; Multiply instructions cannot dual-issue.
130 (define_insn_reservation "cortex_a7_mul" 2
131   (and (eq_attr "tune" "cortexa7")
132        (and (eq_attr "neon_type" "none")
133             (ior (eq_attr "mul32" "yes")
134                  (eq_attr "mul64" "yes"))))
135   "cortex_a7_both")
137 ;; Forward the result of a multiply operation to the accumulator 
138 ;; of the following multiply and accumulate instruction.
139 (define_bypass 1 "cortex_a7_mul"
140                  "cortex_a7_mul"
141                  "arm_mac_accumulator_is_result")
143 ;; The latency depends on the operands, so we use an estimate here.
144 (define_insn_reservation "cortex_a7_idiv" 5
145   (and (eq_attr "tune" "cortexa7")
146        (eq_attr "type" "udiv,sdiv"))
147   "cortex_a7_both*5")
149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
150 ;; Load/store instructions.
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
153 ;; Address-generation happens in the issue stage. 
154 ;; Double-word accesses can be issued in a single cycle,
155 ;; and occupy only one pipeline stage.
157 (define_insn_reservation "cortex_a7_load1" 2
158   (and (eq_attr "tune" "cortexa7")
159        (and (eq_attr "type" "load_byte,load1")
160             (eq_attr "neon_type" "none")))
161   "cortex_a7_ex1")
163 (define_insn_reservation "cortex_a7_store1" 0
164   (and (eq_attr "tune" "cortexa7")
165        (and (eq_attr "type" "store1")
166             (eq_attr "neon_type" "none")))
167   "cortex_a7_ex1")
169 (define_insn_reservation "cortex_a7_load2" 2
170   (and (eq_attr "tune" "cortexa7")
171        (and (eq_attr "type" "load2")
172             (eq_attr "neon_type" "none")))
173   "cortex_a7_both")
175 (define_insn_reservation "cortex_a7_store2" 0
176   (and (eq_attr "tune" "cortexa7")
177        (and (eq_attr "type" "store2")
178             (eq_attr "neon_type" "none")))
179   "cortex_a7_both")
181 (define_insn_reservation "cortex_a7_load3" 3
182   (and (eq_attr "tune" "cortexa7")
183        (and (eq_attr "type" "load3")
184             (eq_attr "neon_type" "none")))
185   "cortex_a7_both, cortex_a7_ex1")
187 (define_insn_reservation "cortex_a7_store3" 0
188   (and (eq_attr "tune" "cortexa7")
189        (and (eq_attr "type" "store4")
190             (eq_attr "neon_type" "none")))
191   "cortex_a7_both, cortex_a7_ex1")
193 (define_insn_reservation "cortex_a7_load4" 3
194   (and (eq_attr "tune" "cortexa7")
195        (and (eq_attr "type" "load4")
196             (eq_attr "neon_type" "none")))
197   "cortex_a7_both, cortex_a7_both")
199 (define_insn_reservation "cortex_a7_store4" 0
200   (and (eq_attr "tune" "cortexa7")
201        (and (eq_attr "type" "store3")
202             (eq_attr "neon_type" "none")))
203   "cortex_a7_both, cortex_a7_both")
205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206 ;; Floating-point arithmetic.
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
208 ;; Neon integer, neon floating point, and single-precision floating
209 ;; point instructions of the same type have the same timing
210 ;; characteristics, but neon instructions cannot dual-issue.
212 (define_insn_reservation "cortex_a7_fpalu" 4
213   (and (eq_attr "tune" "cortexa7")
214        (and (eq_attr "type" "ffariths, fadds, ffarithd, faddd, fcpys,\
215                              f_cvt, fcmps, fcmpd")
216             (eq_attr "neon_type" "none")))
217   "cortex_a7_ex1+cortex_a7_fpadd_pipe")
219 ;; For fconsts and fconstd, 8-bit immediate data is passed directly from
220 ;; f1 to f3 (which I think reduces the latency by one cycle).
222 (define_insn_reservation "cortex_a7_fconst" 3
223   (and (eq_attr "tune" "cortexa7")
224        (and (eq_attr "type" "fconsts,fconstd")
225             (eq_attr "neon_type" "none")))
226   "cortex_a7_ex1+cortex_a7_fpadd_pipe")
228 ;; We should try not to attempt to issue a single-precision multiplication in
229 ;; the middle of a double-precision multiplication operation (the usage of
230 ;; cortex_a7_fpmul_pipe).
232 (define_insn_reservation "cortex_a7_fpmuls" 4
233   (and (eq_attr "tune" "cortexa7")
234        (and (eq_attr "type" "fmuls")
235             (eq_attr "neon_type" "none")))
236   "cortex_a7_ex1+cortex_a7_fpmul_pipe")
238 (define_insn_reservation "cortex_a7_neon_mul" 4
239   (and (eq_attr "tune" "cortexa7")
240        (eq_attr "neon_type"
241                 "neon_mul_ddd_8_16_qdd_16_8_long_32_16_long,\
242                  neon_mul_qqq_8_16_32_ddd_32,\
243                  neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar,\
244                  neon_mul_ddd_16_scalar_32_16_long_scalar,\
245                  neon_mul_qqd_32_scalar,\
246                  neon_fp_vmul_ddd,\
247                  neon_fp_vmul_qqd"))
248   "(cortex_a7_both+cortex_a7_fpmul_pipe)*2")
250 (define_insn_reservation "cortex_a7_fpmacs" 8
251   (and (eq_attr "tune" "cortexa7")
252        (and (eq_attr "type" "fmacs,ffmas")
253             (eq_attr "neon_type" "none")))
254   "cortex_a7_ex1+cortex_a7_fpmul_pipe")
256 (define_insn_reservation "cortex_a7_neon_mla" 8
257   (and (eq_attr "tune" "cortexa7")
258        (eq_attr "neon_type"
259                 "neon_mla_ddd_8_16_qdd_16_8_long_32_16_long,\
260                  neon_mla_qqq_8_16,\
261                  neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long,\
262                  neon_mla_qqq_32_qqd_32_scalar,\
263                  neon_mla_ddd_16_scalar_qdd_32_16_long_scalar,\
264                  neon_fp_vmla_ddd,\
265                  neon_fp_vmla_qqq,\
266                  neon_fp_vmla_ddd_scalar,\
267                  neon_fp_vmla_qqq_scalar"))
268   "cortex_a7_both+cortex_a7_fpmul_pipe")
270 (define_bypass 4 "cortex_a7_fpmacs,cortex_a7_neon_mla"
271                  "cortex_a7_fpmacs,cortex_a7_neon_mla"
272                  "arm_mac_accumulator_is_result")
274 ;; Non-multiply instructions can issue between two cycles of a
275 ;; double-precision multiply. 
277 (define_insn_reservation "cortex_a7_fpmuld" 7
278   (and (eq_attr "tune" "cortexa7")
279        (and (eq_attr "type" "fmuld")
280             (eq_attr "neon_type" "none")))
281   "cortex_a7_ex1+cortex_a7_fpmul_pipe, cortex_a7_fpmul_pipe*3")
283 (define_insn_reservation "cortex_a7_fpmacd" 11
284   (and (eq_attr "tune" "cortexa7")
285        (and (eq_attr "type" "fmacd")
286             (eq_attr "neon_type" "none")))
287   "cortex_a7_ex1+cortex_a7_fpmul_pipe, cortex_a7_fpmul_pipe*3")
289 (define_insn_reservation "cortex_a7_fpfmad" 8
290   (and (eq_attr "tune" "cortexa7")
291        (and (eq_attr "type" "ffmad")
292             (eq_attr "neon_type" "none")))
293   "cortex_a7_ex1+cortex_a7_fpmul_pipe, cortex_a7_fpmul_pipe*4")
295 (define_bypass 7 "cortex_a7_fpmacd"
296                  "cortex_a7_fpmacd,cortex_a7_fpfmad"
297                  "arm_mac_accumulator_is_result")
299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
300 ;; Floating-point divide/square root instructions.
301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
303 (define_insn_reservation "cortex_a7_fdivs" 16
304   (and (eq_attr "tune" "cortexa7")
305        (and (eq_attr "type" "fdivs")
306             (eq_attr "neon_type" "none")))
307   "cortex_a7_ex1+cortex_a7_fp_div_sqrt, cortex_a7_fp_div_sqrt * 13")
309 (define_insn_reservation "cortex_a7_fdivd" 31
310   (and (eq_attr "tune" "cortexa7")
311        (and (eq_attr "type" "fdivd")
312             (eq_attr "neon_type" "none")))
313   "cortex_a7_ex1+cortex_a7_fp_div_sqrt, cortex_a7_fp_div_sqrt * 28")
315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
316 ;; VFP to/from core transfers.
317 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
319 ;; Core-to-VFP transfers.
321 (define_insn_reservation "cortex_a7_r2f" 4
322   (and (eq_attr "tune" "cortexa7")
323        (and (eq_attr "type" "r_2_f")
324             (eq_attr "neon_type" "none")))
325   "cortex_a7_both")
327 (define_insn_reservation "cortex_a7_f2r" 2
328   (and (eq_attr "tune" "cortexa7")
329        (and (eq_attr "type" "f_2_r")
330             (eq_attr "neon_type" "none")))
331   "cortex_a7_ex1")
333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334 ;; VFP flag transfer.
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
337 ;; Fuxne: The flag forwarding from fmstat to the second instruction is
338 ;; not modeled at present.
340 (define_insn_reservation "cortex_a7_f_flags" 4
341   (and (eq_attr "tune" "cortexa7")
342        (and (eq_attr "type" "f_flag")
343             (eq_attr "neon_type" "none")))
344   "cortex_a7_ex1")
346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
347 ;; VFP load/store.
348 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350 (define_insn_reservation "cortex_a7_f_loads" 4
351   (and (eq_attr "tune" "cortexa7")
352        (and (eq_attr "type" "f_loads")
353             (eq_attr "neon_type" "none")))
354   "cortex_a7_ex1")
356 (define_insn_reservation "cortex_a7_f_loadd" 4
357   (and (eq_attr "tune" "cortexa7")
358        (and (eq_attr "type" "f_loadd")
359             (eq_attr "neon_type" "none")))
360   "cortex_a7_both")
362 (define_insn_reservation "cortex_a7_f_stores" 0
363   (and (eq_attr "tune" "cortexa7")
364        (and (eq_attr "type" "f_stores")
365             (eq_attr "neon_type" "none")))
366   "cortex_a7_ex1")
368 (define_insn_reservation "cortex_a7_f_stored" 0
369   (and (eq_attr "tune" "cortexa7")
370        (and (eq_attr "type" "f_stored")
371             (eq_attr "neon_type" "none")))
372   "cortex_a7_both")
374 ;; Load-to-use for floating-point values has a penalty of one cycle,
375 ;; i.e. a latency of two.
377 (define_bypass 2 "cortex_a7_f_loads, cortex_a7_f_loadd"
378                   "cortex_a7_fpalu,\
379                    cortex_a7_fpmuls,cortex_a7_fpmacs,\
380                    cortex_a7_fpmuld,cortex_a7_fpmacd, cortex_a7_fpfmad,\
381                    cortex_a7_fdivs, cortex_a7_fdivd,\
382                    cortex_a7_f2r")
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
385 ;; NEON
386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
388 ;; Simple modeling for all neon instructions not covered earlier.
390 (define_insn_reservation "cortex_a7_neon" 4
391   (and (eq_attr "tune" "cortexa7")
392        (eq_attr "neon_type"
393                 "!none,\
394                   neon_mul_ddd_8_16_qdd_16_8_long_32_16_long,\
395                   neon_mul_qqq_8_16_32_ddd_32,\
396                   neon_mul_qdd_64_32_long_qqd_16_ddd_32_scalar_64_32_long_scalar,\
397                   neon_mla_ddd_8_16_qdd_16_8_long_32_16_long,\
398                   neon_mla_qqq_8_16,\
399                   neon_mla_ddd_32_qqd_16_ddd_32_scalar_qdd_64_32_long_scalar_qdd_64_32_long,\
400                   neon_mla_qqq_32_qqd_32_scalar,\
401                   neon_mul_ddd_16_scalar_32_16_long_scalar,\
402                   neon_mul_qqd_32_scalar,\
403                   neon_mla_ddd_16_scalar_qdd_32_16_long_scalar,\
404                   neon_fp_vmul_ddd,\
405                   neon_fp_vmul_qqd,\
406                   neon_fp_vmla_ddd,\
407                   neon_fp_vmla_qqq,\
408                   neon_fp_vmla_ddd_scalar,\
409                   neon_fp_vmla_qqq_scalar"))
410   "cortex_a7_both*2")