summaryrefslogtreecommitdiff
path: root/gcc/config/mips/sb1.md
blob: 41cebedce4ffe08010fe692b36fcecae07831a32 (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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
;;
;; DFA-based pipeline description for Broadcom SB-1
;;

;; The Broadcom SB-1 core is 4-way superscalar, in-order.  It has 2 load/store
;; pipes (one of which can support some ALU operations), 2 alu pipes, 2 FP
;; pipes, and 1 MDMX pipes.  It can issue 2 ls insns and 2 exe/fpu/mdmx insns
;; each cycle.

;; We model the 4-way issue by ordering unit choices.  The possible choices are
;; {ex1,fp1}|{ex0,fp0}|ls1|ls0.  Instructions issue to the first eligible unit
;; in the list in most cases.  Non-indexed load/stores issue to ls0 first.
;; simple alu operations issue to ls1 if it is still available, and their
;; operands are ready (no co-issue with loads), otherwise to the first
;; available ex unit.

;; When exceptions are enabled, can only issue FP insns to fp1.  This is
;; to ensure that instructions complete in order.  The -mfp-exceptions option
;; can be used to specify whether the system has FP exceptions enabled or not.

;; In 32-bit mode, dependent FP can't co-issue with load, and only one FP exe
;; insn can issue per cycle (fp1).

;; The A1 MDMX pipe is separate from the FP pipes, but uses the same register
;; file.  As a result, once an MDMX insn is issued, no FP insns can be issued
;; for 3 cycles.  When an FP insn is issued, no MDMX insn can be issued for
;; 5 cycles.  This is currently not handled because there is no MDMX insn
;; support as yet.

;;
;; We use two automata.  sb1_cpu_div is for the integer divides, which are
;; not pipelined.  sb1_cpu is for everything else.
;;
(define_automaton "sb1_cpu, sb1_cpu_div")

;; Load/store function units.
(define_cpu_unit "sb1_ls0" "sb1_cpu")
(define_cpu_unit "sb1_ls1" "sb1_cpu")

;; CPU function units.
(define_cpu_unit "sb1_ex0" "sb1_cpu")
(define_cpu_unit "sb1_ex1" "sb1_cpu")

;; The divide unit is not pipelined, and blocks hi/lo reads and writes.
(define_cpu_unit "sb1_div" "sb1_cpu_div")
;; DMULT block any multiply from issuing in the next cycle.
(define_cpu_unit "sb1_mul" "sb1_cpu")

;; Floating-point units.
(define_cpu_unit "sb1_fp0" "sb1_cpu")
(define_cpu_unit "sb1_fp1" "sb1_cpu")

;; Can only issue to one of the ex and fp pipes at a time.
(exclusion_set "sb1_ex0" "sb1_fp0")
(exclusion_set "sb1_ex1" "sb1_fp1")

;; Define an SB-1 specific attribute to simplify some FP descriptions.
;; We can use 2 FP pipes only if we have 64-bit FP code, and exceptions are
;; disabled.

(define_attr "sb1_fp_pipes" "one,two"
  (cond [(and (ne (symbol_ref "TARGET_FLOAT64") (const_int 0))
	      (eq (symbol_ref "TARGET_FP_EXCEPTIONS") (const_int 0)))
	 (const_string "two")]
	(const_string "one")))

;; Define reservations for common combinations.

;; For long cycle operations, the FPU has a 4 cycle pipeline that repeats,
;; effectively re-issuing the operation every 4 cycles.  This means that we
;; can have at most 4 long-cycle operations per pipe.

;; ??? The fdiv operations should be e.g.
;; sb1_fp1_4cycles*7" | "sb1_fp0_4cycle*7
;; but the DFA is too large when we do that.  Perhaps have to use scheduler
;; hooks here.

;; ??? Try limiting scheduler to 2 long latency operations, and see if this
;; results in a usable DFA, and whether it helps code performance.

;;(define_reservation "sb1_fp0_4cycles" "sb1_fp0, nothing*3")
;;(define_reservation "sb1_fp1_4cycles" "sb1_fp1, nothing*3")

;;
;; The ordering of the instruction-execution-path/resource-usage
;; descriptions (also known as reservation RTL) is roughly ordered
;; based on the define attribute RTL for the "type" classification.
;; When modifying, remember that the first test that matches is the
;; reservation used!
;;

(define_insn_reservation "ir_sb1_unknown" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "unknown,multi"))
  "sb1_ls0+sb1_ls1+sb1_ex0+sb1_ex1+sb1_fp0+sb1_fp1")

;; predicted taken branch causes 2 cycle ifetch bubble.  predicted not
;; taken branch causes 0 cycle ifetch bubble.  mispredicted branch causes 8
;; cycle ifetch bubble.  We assume all branches predicted not taken.

;; ??? This assumption that branches are predicated not taken should be
;; investigated.  Maybe using 2 here will give better results.

(define_insn_reservation "ir_sb1_branch" 0
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "branch,jump,call"))
  "sb1_ex0")

;; ??? This is 1 cycle for ldl/ldr to ldl/ldr when they use the same data
;; register as destination.

;; ??? Can co-issue a load with a dependent arith insn if it executes on an EX
;; unit.  Can not co-issue if the dependent insn executes on an LS unit.

;; A load normally has a latency of zero cycles.  In some cases, dependent
;; insns can be issued in the same cycle.  However, a value of 1 gives
;; better performance in empirical testing.

(define_insn_reservation "ir_sb1_load" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "load,prefetch"))
  "sb1_ls0 | sb1_ls1")

;; Can not co-issue fpload with fp exe when in 32-bit mode.

(define_insn_reservation "ir_sb1_fpload" 0
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fpload")
	    (ne (symbol_ref "TARGET_FLOAT64")
		(const_int 0))))
  "sb1_ls0 | sb1_ls1")

(define_insn_reservation "ir_sb1_fpload_32bitfp" 1
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fpload")
	    (eq (symbol_ref "TARGET_FLOAT64")
		(const_int 0))))
  "sb1_ls0 | sb1_ls1")

;; Indexed loads can only execute on LS1 pipe.

(define_insn_reservation "ir_sb1_fpidxload" 0
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fpidxload")
	    (ne (symbol_ref "TARGET_FLOAT64")
		(const_int 0))))
  "sb1_ls1")

(define_insn_reservation "ir_sb1_fpidxload_32bitfp" 1
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fpidxload")
	    (eq (symbol_ref "TARGET_FLOAT64")
		(const_int 0))))
  "sb1_ls1")

;; prefx can only execute on the ls1 pipe.

(define_insn_reservation "ir_sb1_prefetchx" 0
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "prefetchx"))
  "sb1_ls1")

;; ??? There is a 4.5 cycle latency if a store is followed by a load, and
;; there is a RAW dependency.

(define_insn_reservation "ir_sb1_store" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "store"))
  "sb1_ls0+sb1_ex1 | sb1_ls0+sb1_ex0 | sb1_ls1+sb1_ex1 | sb1_ls1+sb1_ex0")

(define_insn_reservation "ir_sb1_fpstore" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "fpstore"))
  "sb1_ls0+sb1_fp1 | sb1_ls0+sb1_fp0 | sb1_ls1+sb1_fp1 | sb1_ls1+sb1_fp0")

;; Indexed stores can only execute on LS1 pipe.

(define_insn_reservation "ir_sb1_fpidxstore" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "fpidxstore"))
  "sb1_ls1+sb1_fp1 | sb1_ls1+sb1_fp0")

;; Load latencies are 3 cycles for one load to another load or store (address
;; only).  This is 0 cycles for one load to a store using it as the data
;; written.

;; This assumes that if a load is dependent on a previous insn, then it must
;; be an address dependence.

(define_bypass 3
  "ir_sb1_load,ir_sb1_fpload,ir_sb1_fpload_32bitfp,ir_sb1_fpidxload,
   ir_sb1_fpidxload_32bitfp"
  "ir_sb1_load,ir_sb1_fpload,ir_sb1_fpload_32bitfp,ir_sb1_fpidxload,
   ir_sb1_fpidxload_32bitfp,ir_sb1_prefetchx")

(define_bypass 3
  "ir_sb1_load,ir_sb1_fpload,ir_sb1_fpload_32bitfp,ir_sb1_fpidxload,
   ir_sb1_fpidxload_32bitfp"
  "ir_sb1_store,ir_sb1_fpstore,ir_sb1_fpidxstore"
  "store_data_bypass_p")

;; Simple alu instructions can execute on the LS1 unit.

;; ??? A simple alu insn issued on an LS unit has 0 cycle latency to an EX
;; insn, to a store (for data), and to an xfer insn.  It has 1 cycle latency to
;; another LS insn (excluding store data).  A simple alu insn issued on an EX
;; unit has a latency of 5 cycles when the results goes to a LS unit (excluding
;; store data), otherwise a latency of 1 cycle.

;; ??? We can not handle latencies properly for simple alu instructions
;; within the DFA pipeline model.  Latencies can be defined only from one
;; insn reservation to another.  We can't make them depend on which function
;; unit was used.  This isn't a DFA flaw.  There is a conflict here, as we
;; need to know the latency before we can determine which unit will be
;; available, but we need to know which unit it is issued to before we can
;; compute the latency.  Perhaps this can be handled via scheduler hooks.
;; This needs to be investigated.

;; ??? Optimal scheduling taking the LS units into account seems to require
;; a pre-scheduling pass.  We need to determine which instructions feed results
;; into store/load addresses, and thus benefit most from being issued to the
;; LS unit.  Also, we need to prune the list to ensure we don't overschedule
;; insns to the LS unit, and that we don't conflict with insns that need LS1
;; such as indexed loads.  We then need to emit nops to ensure that simple
;; alu instructions that are not supposed to be scheduled to LS1 don't
;; accidentally end up there because LS1 is free when they are issued.  This
;; will be a lot of work, and it isn't clear how useful it will be.

;; Empirical testing shows that 2 gives the best result.

(define_insn_reservation "ir_sb1_simple_alu" 2
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "const,arith"))
  "sb1_ls1 | sb1_ex1 | sb1_ex0")

;; ??? condmove also includes some FP instructions that execute on the FP
;; units.  This needs to be clarified.

(define_insn_reservation "ir_sb1_alu" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "condmove,nop,shift"))
  "sb1_ex1 | sb1_ex0")

;; These are type arith/darith that only execute on the EX0 unit.

(define_insn_reservation "ir_sb1_alu_0" 1
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "slt,clz,trap"))
  "sb1_ex0")

;; An alu insn issued on an EX unit has a latency of 5 cycles when the
;; result goes to a LS unit (excluding store data).

;; This assumes that if a load is dependent on a previous insn, then it must
;; be an address dependence.

(define_bypass 5
  "ir_sb1_alu,ir_sb1_alu_0,ir_sb1_mfhi,ir_sb1_mflo"
  "ir_sb1_load,ir_sb1_fpload,ir_sb1_fpload_32bitfp,ir_sb1_fpidxload,
   ir_sb1_fpidxload_32bitfp,ir_sb1_prefetchx")

(define_bypass 5
  "ir_sb1_alu,ir_sb1_alu_0,ir_sb1_mfhi,ir_sb1_mflo"
  "ir_sb1_store,ir_sb1_fpstore,ir_sb1_fpidxstore"
  "store_data_bypass_p")

;; mf{hi,lo} is 1 cycle.  

(define_insn_reservation "ir_sb1_mfhi" 1
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "mfhilo")
	    (not (match_operand 1 "lo_operand"))))
  "sb1_ex1")

(define_insn_reservation "ir_sb1_mflo" 1
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "mfhilo")
	    (match_operand 1 "lo_operand")))
  "sb1_ex1")

;; mt{hi,lo} to mul/div is 4 cycles.

(define_insn_reservation "ir_sb1_mthilo" 4
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "mthilo"))
  "sb1_ex1")

;; mt{hi,lo} to mf{hi,lo} is 3 cycles.

(define_bypass 3 "ir_sb1_mthilo" "ir_sb1_mfhi,ir_sb1_mflo")

;; multiply latency to an EX operation is 3 cycles.

;; ??? Should check whether we need to make multiply conflict with moves
;; to/from hilo registers.

(define_insn_reservation "ir_sb1_mulsi" 3
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "imul,imadd")
	    (eq_attr "mode" "SI")))
  "sb1_ex1+sb1_mul")

;; muldi to mfhi is 4 cycles.
;; Blocks any other multiply insn issue for 1 cycle.

(define_insn_reservation "ir_sb1_muldi" 4
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "imul")
	    (eq_attr "mode" "DI")))
  "sb1_ex1+sb1_mul, sb1_mul")

;; muldi to mflo is 3 cycles.

(define_bypass 3 "ir_sb1_muldi" "ir_sb1_mflo")

;;  mul latency is 7 cycles if the result is used by any LS insn.

;; This assumes that if a load is dependent on a previous insn, then it must
;; be an address dependence.

(define_bypass 7
  "ir_sb1_mulsi,ir_sb1_muldi"
  "ir_sb1_load,ir_sb1_fpload,ir_sb1_fpload_32bitfp,ir_sb1_fpidxload,
   ir_sb1_fpidxload_32bitfp,ir_sb1_prefetchx")

(define_bypass 7
  "ir_sb1_mulsi,ir_sb1_muldi"
  "ir_sb1_store,ir_sb1_fpstore,ir_sb1_fpidxstore"
  "store_data_bypass_p")

;; The divide unit is not pipelined.  Divide busy is asserted in the 4th
;; cycle, and then deasserted on the latency cycle.  So only one divide at
;; a time, but the first/last 4 cycles can overlap.

;; ??? All divides block writes to hi/lo regs.  hi/lo regs are written 4 cycles
;; after the latency cycle for divides (e.g. 40/72).  dmult writes lo in
;; cycle 7, and hi in cycle 8.  All other insns write hi/lo regs in cycle 7.
;; Default for output dependencies is the difference in latencies, which is
;; only 1 cycle off here, e.g. div to mtlo stalls for 32 cycles, but should
;; stall for 33 cycles.  This does not seem significant enough to worry about.

(define_insn_reservation "ir_sb1_divsi" 36
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "idiv")
	    (eq_attr "mode" "SI")))
  "sb1_ex1, nothing*3, sb1_div*32")

(define_insn_reservation "ir_sb1_divdi" 68
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "idiv")
	    (eq_attr "mode" "DI")))
  "sb1_ex1, nothing*3, sb1_div*64")

(define_insn_reservation "ir_sb1_fpu_2pipes" 4
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fmove,fadd,fmul,fabs,fneg,fcvt")
	    (eq_attr "sb1_fp_pipes" "two")))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_fpu_1pipe" 4
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fmove,fadd,fmul,fabs,fneg,fcvt")
	    (eq_attr "sb1_fp_pipes" "one")))
  "sb1_fp1")

;; ??? madd/msub 4-cycle latency to itself (same fr?), but 8 cycle latency
;; otherwise.

;; ??? Blocks issue of another non-madd/msub after 4 cycles.

(define_insn_reservation "ir_sb1_fmadd_2pipes" 8
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fmadd")
	    (eq_attr "sb1_fp_pipes" "two")))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_fmadd_1pipe" 8
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fmadd")
	    (eq_attr "sb1_fp_pipes" "one")))
  "sb1_fp1")

(define_insn_reservation "ir_sb1_fcmp" 4
  (and (eq_attr "cpu" "sb1")
       (eq_attr "type" "fcmp"))
  "sb1_fp1")

;; mtc1 latency 5 cycles.

(define_insn_reservation "ir_sb1_mtxfer" 5
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "xfer")
	    (match_operand 0 "fp_register_operand")))
  "sb1_fp0")

;; mfc1 latency 1 cycle.  

(define_insn_reservation "ir_sb1_mfxfer" 1
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "xfer")
	    (not (match_operand 0 "fp_register_operand"))))
  "sb1_fp0")

;; ??? Can deliver at most 1 result per every 6 cycles because of issue
;; restrictions.

(define_insn_reservation "ir_sb1_divsf_2pipes" 24
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fdiv")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "two"))))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_divsf_1pipes" 24
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fdiv")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "one"))))
  "sb1_fp1")

;; ??? Can deliver at most 1 result per every 8 cycles because of issue
;; restrictions.

(define_insn_reservation "ir_sb1_divdf_2pipes" 32
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fdiv")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "two"))))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_divdf_1pipe" 32
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fdiv")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "one"))))
  "sb1_fp1")

;; ??? Can deliver at most 1 result per every 7 cycles because of issue
;; restrictions.

(define_insn_reservation "ir_sb1_sqrtsf_2pipes" 28
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fsqrt")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "two"))))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_sqrtsf_1pipe" 28
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fsqrt")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "one"))))
  "sb1_fp1")

;; ??? Can deliver at most 1 result per every 10 cycles because of issue
;; restrictions.

(define_insn_reservation "ir_sb1_sqrtdf_2pipes" 40
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fsqrt")
	    (and (eq_attr "mode" "DF")
		 (eq_attr "sb1_fp_pipes" "two"))))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_sqrtdf_1pipe" 40
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "fsqrt")
	    (and (eq_attr "mode" "DF")
		 (eq_attr "sb1_fp_pipes" "one"))))
  "sb1_fp1")

;; ??? Can deliver at most 1 result per every 4 cycles because of issue
;; restrictions.

(define_insn_reservation "ir_sb1_rsqrtsf_2pipes" 16
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "frsqrt")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "two"))))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_rsqrtsf_1pipe" 16
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "frsqrt")
	    (and (eq_attr "mode" "SF")
		 (eq_attr "sb1_fp_pipes" "one"))))
  "sb1_fp1")

;; ??? Can deliver at most 1 result per every 7 cycles because of issue
;; restrictions.

(define_insn_reservation "ir_sb1_rsqrtdf_2pipes" 28
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "frsqrt")
	    (and (eq_attr "mode" "DF")
		 (eq_attr "sb1_fp_pipes" "two"))))
  "sb1_fp1 | sb1_fp0")

(define_insn_reservation "ir_sb1_rsqrtdf_1pipe" 28
  (and (eq_attr "cpu" "sb1")
       (and (eq_attr "type" "frsqrt")
	    (and (eq_attr "mode" "DF")
		 (eq_attr "sb1_fp_pipes" "one"))))
  "sb1_fp1")