summaryrefslogtreecommitdiff
path: root/gcc/config/nds32/nds32-n8.md
blob: d6242f8f0e11de9e2d9c1c63a411ab7ec901e36a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
;; Pipeline descriptions of Andes NDS32 cpu for GNU compiler
;; Copyright (C) 2012-2018 Free Software Foundation, Inc.
;; Contributed by Andes Technology Corporation.
;;
;; This file is part of GCC.
;;
;; GCC is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.
;;
;; GCC is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
;; License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GCC; see the file COPYING3.  If not see
;; <http://www.gnu.org/licenses/>.


;; ------------------------------------------------------------------------
;; Define N8 pipeline settings.
;; ------------------------------------------------------------------------

(define_automaton "nds32_n8_machine")

;; ------------------------------------------------------------------------
;; Pipeline Stages
;; ------------------------------------------------------------------------
;; IF - Instruction Fetch
;; II - Instruction Issue / Address Generation
;; EX - Instruction Execution
;; EXD - Psuedo Stage / Load Data Completion

(define_cpu_unit "n8_ii" "nds32_n8_machine")
(define_cpu_unit "n8_ex" "nds32_n8_machine")

(define_insn_reservation "nds_n8_unknown" 1
  (and (eq_attr "type" "unknown")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_misc" 1
  (and (eq_attr "type" "misc")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_alu" 1
  (and (eq_attr "type" "alu")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_load" 1
  (and (match_test "nds32::load_single_p (insn)")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_store" 1
  (and (match_test "nds32::store_single_p (insn)")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_1" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "1"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_2" 1
  (and (ior (and (eq_attr "type" "load_multiple")
		 (eq_attr "combo" "2"))
	    (match_test "nds32::load_double_p (insn)"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ii+n8_ex, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_3" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "3"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*2, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_4" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "4"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*3, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_5" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "5"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*4, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_6" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "6"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*5, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_7" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "7"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*6, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_8" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "8"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*7, n8_ex")

(define_insn_reservation "nds_n8_load_multiple_12" 1
  (and (and (eq_attr "type" "load_multiple")
	    (eq_attr "combo" "12"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*11, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_1" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "1"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_2" 1
  (and (ior (and (eq_attr "type" "store_multiple")
		 (eq_attr "combo" "2"))
	    (match_test "nds32::store_double_p (insn)"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ii+n8_ex, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_3" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "3"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*2, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_4" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "4"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*3, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_5" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "5"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*4, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_6" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "6"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*5, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_7" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "7"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*6, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_8" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "8"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*7, n8_ex")

(define_insn_reservation "nds_n8_store_multiple_12" 1
  (and (and (eq_attr "type" "store_multiple")
	    (eq_attr "combo" "12"))
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*11, n8_ex")

(define_insn_reservation "nds_n8_mul_fast" 1
  (and (match_test "nds32_mul_config != MUL_TYPE_SLOW")
       (and (eq_attr "type" "mul")
	    (eq_attr "pipeline_model" "n8")))
  "n8_ii, n8_ex")

(define_insn_reservation "nds_n8_mul_slow" 1
  (and (match_test "nds32_mul_config == MUL_TYPE_SLOW")
       (and (eq_attr "type" "mul")
	    (eq_attr "pipeline_model" "n8")))
  "n8_ii, n8_ex*16")

(define_insn_reservation "nds_n8_mac_fast" 1
  (and (match_test "nds32_mul_config != MUL_TYPE_SLOW")
       (and (eq_attr "type" "mac")
	    (eq_attr "pipeline_model" "n8")))
  "n8_ii, n8_ii+n8_ex, n8_ex")

(define_insn_reservation "nds_n8_mac_slow" 1
  (and (match_test "nds32_mul_config == MUL_TYPE_SLOW")
       (and (eq_attr "type" "mac")
	    (eq_attr "pipeline_model" "n8")))
  "n8_ii, (n8_ii+n8_ex)*16, n8_ex")

(define_insn_reservation "nds_n8_div" 1
  (and (eq_attr "type" "div")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, (n8_ii+n8_ex)*36, n8_ex")

(define_insn_reservation "nds_n8_branch" 1
  (and (eq_attr "type" "branch")
       (eq_attr "pipeline_model" "n8"))
  "n8_ii, n8_ex")

;; ------------------------------------------------------------------------
;; Comment Notations and Bypass Rules
;; ------------------------------------------------------------------------
;; Producers (LHS)
;;   LD_!bi
;;     Load data from the memory (without updating the base register) and
;;     produce the loaded data. The result is ready at EXD.
;;   LD_bi
;;     Load data from the memory (with updating the base register) and
;;     produce the loaded data. The result is ready at EXD. Because the
;;     register port is 2R1W, two micro-operations are required in order
;;     to write two registers. The base register is updated by the second
;;     micro-operation and the result is ready at EX.
;;   LMW(N, M)
;;     There are N micro-operations within an instruction that loads multiple
;;     words. The result produced by the M-th micro-operation is sent to
;;     consumers. The result is ready at EXD. If the base register should be
;;     updated, an extra micro-operation is inserted to the sequence, and the
;;     result is ready at EX.
;;   ADDR_OUT
;;     Most load/store instructions can produce an address output if updating
;;     the base register is required. The result is ready at EX, which is
;;     produced by ALU.
;;   ALU, MUL, MAC
;;     The result is ready at EX.
;;   MOVD44_O
;;     A double-word move instruction needs to write registers twice. Because
;;     the register port is 2R1W, two micro-operations are required. The even
;;     number reigster is updated by the first one, and the odd number register
;;     is updated by the second one. Each of the results is ready at EX.
;;     The letter 'O' stands for odd.
;;   DIV_Rs
;;     A division instruction saves the quotient result to Rt and saves the
;;     remainder result to Rs. It requires two micro-operations because the
;;     register port is 2R1W. The first micro-operation writes to Rt, and
;;     the seconde one writes to Rs. Each of the results is ready at EX.
;;
;; Consumers (RHS)
;;   ALU, MUL, DIV
;;     Require operands at EX.
;;   MOVD44_E
;;     The letter 'E' stands for even, which is accessed by the first micro-
;;     operation and a movd44 instruction. The operand is required at EX.
;;   MAC_RaRb
;;     A MAC instruction is separated into two micro-operations. The first
;;     micro-operation does the multiplication, which requires operands Ra
;;     and Rb at EX. The second micro-options does the accumulation, which
;;     requires the operand Rt at EX.
;;   ADDR_IN_MOP(N)
;;     Because the reigster port is 2R1W, some load/store instructions are
;;     separated into many micro-operations. N denotes the address input is
;;     required by the N-th micro-operation. Such operand is required at II.
;;   ST_bi
;;     A post-increment store instruction requires its data at EX.
;;   ST_!bi_RI
;;     A store instruction with an immediate offset requires its data at EX.
;;     If the offset field is a register (ST_!bi_RR), the instruction will be
;;     separated into two micro-operations, and the second one requires the
;;     input operand at EX in order to store it to the memory.
;;   SMW(N, M)
;;     There are N micro-operations within an instruction that stores multiple
;;     words. Each M-th micro-operation requires its data at EX. If the base
;;     register should be updated, an extra micro-operation is inserted to the
;;     sequence.
;;   BR_COND
;;     If a branch instruction is conditional, its input data is required at EX.

;; LD_!bi -> ADDR_IN_MOP(1)
(define_bypass 3
  "nds_n8_load"
  "nds_n8_branch,\
   nds_n8_load, nds_n8_store,\
   nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_load_to_ii_p"
)

;; LMW(N, N) -> ADDR_IN_MOP(1)
(define_bypass 3
  "nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12"
  "nds_n8_branch,\
   nds_n8_load, nds_n8_store,\
   nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_last_load_to_ii_p"
)

;; LMW(N, N - 1) -> ADDR_IN_MOP(1)
(define_bypass 2
  "nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12"
  "nds_n8_branch,\
   nds_n8_load, nds_n8_store,\
   nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_last_load_two_to_ii_p"
)

;; LD_bi -> ADDR_IN_MOP(1)
(define_bypass 2
  "nds_n8_load"
  "nds_n8_branch,\
   nds_n8_load, nds_n8_store,\
   nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_load_bi_to_ii_p"
)

;; LD_!bi -> ALU, MOVD44_E, MUL, MAC_RaRb, DIV, BR_COND, ST_bi, ST_!bi_RI, SMW(N, 1)
(define_bypass 2
  "nds_n8_load"
  "nds_n8_alu,
   nds_n8_mul_fast, nds_n8_mul_slow,\
   nds_n8_mac_fast, nds_n8_mac_slow,\
   nds_n8_div,\
   nds_n8_branch,\
   nds_n8_store,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_load_to_ex_p"
)

;; ALU, MOVD44_O, MUL, MAC, DIV_Rs, LD_bi, ADDR_OUT -> ADDR_IN_MOP(1)
(define_bypass 2
  "nds_n8_alu,
   nds_n8_mul_fast, nds_n8_mul_slow,\
   nds_n8_mac_fast, nds_n8_mac_slow,\
   nds_n8_div,\
   nds_n8_load, nds_n8_store,\
   nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds_n8_branch,\
   nds_n8_load, nds_n8_store,\
   nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_ex_to_ii_p"
)

;; LMW(N, N) -> ALU, MOVD44_E, MUL, MAC_RaRb, DIV, BR_COND, ST_bi, ST_!bi_RI, SMW(N, 1)
(define_bypass 2
  "nds_n8_load_multiple_1,nds_n8_load_multiple_2, nds_n8_load_multiple_3,\
   nds_n8_load_multiple_4,nds_n8_load_multiple_5, nds_n8_load_multiple_6,\
   nds_n8_load_multiple_7,nds_n8_load_multiple_8, nds_n8_load_multiple_12"
  "nds_n8_alu,
   nds_n8_mul_fast, nds_n8_mul_slow,\
   nds_n8_mac_fast, nds_n8_mac_slow,\
   nds_n8_div,\
   nds_n8_branch,\
   nds_n8_store,\
   nds_n8_store_multiple_1,nds_n8_store_multiple_2, nds_n8_store_multiple_3,\
   nds_n8_store_multiple_4,nds_n8_store_multiple_5, nds_n8_store_multiple_6,\
   nds_n8_store_multiple_7,nds_n8_store_multiple_8, nds_n8_store_multiple_12"
  "nds32_n8_last_load_to_ex_p"
)