2 * Copyright 2011 Christoph Bumiller
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "nv50_ir_target_nvc0.h"
27 // Argh, all these assertions ...
29 class CodeEmitterNVC0
: public CodeEmitter
32 CodeEmitterNVC0(const TargetNVC0
*);
34 virtual bool emitInstruction(Instruction
*);
35 virtual uint32_t getMinEncodingSize(const Instruction
*) const;
36 virtual void prepareEmission(Function
*);
38 inline void setProgramType(Program::Type pType
) { progType
= pType
; }
41 const TargetNVC0
*targNVC0
;
43 Program::Type progType
;
45 const bool writeIssueDelays
;
48 void emitForm_A(const Instruction
*, uint64_t);
49 void emitForm_B(const Instruction
*, uint64_t);
50 void emitForm_S(const Instruction
*, uint32_t, bool pred
);
52 void emitPredicate(const Instruction
*);
54 void setAddress16(const ValueRef
&);
55 void setImmediate(const Instruction
*, const int s
); // needs op already set
56 void setImmediateS8(const ValueRef
&);
57 void setSUConst16(const Instruction
*, const int s
);
58 void setSUPred(const Instruction
*, const int s
);
60 void emitCondCode(CondCode cc
, int pos
);
61 void emitInterpMode(const Instruction
*);
62 void emitLoadStoreType(DataType ty
);
63 void emitSUGType(DataType
);
64 void emitCachingMode(CacheMode c
);
66 void emitShortSrc2(const ValueRef
&);
68 inline uint8_t getSRegEncoding(const ValueRef
&);
70 void roundMode_A(const Instruction
*);
71 void roundMode_C(const Instruction
*);
72 void roundMode_CS(const Instruction
*);
74 void emitNegAbs12(const Instruction
*);
76 void emitNOP(const Instruction
*);
78 void emitLOAD(const Instruction
*);
79 void emitSTORE(const Instruction
*);
80 void emitMOV(const Instruction
*);
82 void emitINTERP(const Instruction
*);
83 void emitPFETCH(const Instruction
*);
84 void emitVFETCH(const Instruction
*);
85 void emitEXPORT(const Instruction
*);
86 void emitOUT(const Instruction
*);
88 void emitUADD(const Instruction
*);
89 void emitFADD(const Instruction
*);
90 void emitUMUL(const Instruction
*);
91 void emitFMUL(const Instruction
*);
92 void emitIMAD(const Instruction
*);
93 void emitISAD(const Instruction
*);
94 void emitFMAD(const Instruction
*);
95 void emitMADSP(const Instruction
*);
97 void emitNOT(Instruction
*);
98 void emitLogicOp(const Instruction
*, uint8_t subOp
);
99 void emitPOPC(const Instruction
*);
100 void emitINSBF(const Instruction
*);
101 void emitShift(const Instruction
*);
103 void emitSFnOp(const Instruction
*, uint8_t subOp
);
105 void emitCVT(Instruction
*);
106 void emitMINMAX(const Instruction
*);
107 void emitPreOp(const Instruction
*);
109 void emitSET(const CmpInstruction
*);
110 void emitSLCT(const CmpInstruction
*);
111 void emitSELP(const Instruction
*);
113 void emitTEXBAR(const Instruction
*);
114 void emitTEX(const TexInstruction
*);
115 void emitTEXCSAA(const TexInstruction
*);
116 void emitTXQ(const TexInstruction
*);
118 void emitQUADOP(const Instruction
*, uint8_t qOp
, uint8_t laneMask
);
120 void emitFlow(const Instruction
*);
122 void emitSUCLAMPMode(uint16_t);
123 void emitSUCalc(Instruction
*);
124 void emitSULDGB(const TexInstruction
*);
125 void emitSUSTGx(const TexInstruction
*);
127 void emitVSHL(const Instruction
*);
128 void emitVectorSubOp(const Instruction
*);
130 inline void defId(const ValueDef
&, const int pos
);
131 inline void srcId(const ValueRef
&, const int pos
);
132 inline void srcId(const ValueRef
*, const int pos
);
133 inline void srcId(const Instruction
*, int s
, const int pos
);
135 inline void srcAddr32(const ValueRef
&, const int pos
); // address / 4
137 inline bool isLIMM(const ValueRef
&, DataType ty
);
140 // for better visibility
141 #define HEX64(h, l) 0x##h##l##ULL
143 #define SDATA(a) ((a).rep()->reg.data)
144 #define DDATA(a) ((a).rep()->reg.data)
146 void CodeEmitterNVC0::srcId(const ValueRef
& src
, const int pos
)
148 code
[pos
/ 32] |= (src
.get() ? SDATA(src
).id
: 63) << (pos
% 32);
151 void CodeEmitterNVC0::srcId(const ValueRef
*src
, const int pos
)
153 code
[pos
/ 32] |= (src
? SDATA(*src
).id
: 63) << (pos
% 32);
156 void CodeEmitterNVC0::srcId(const Instruction
*insn
, int s
, int pos
)
158 int r
= insn
->srcExists(s
) ? SDATA(insn
->src(s
)).id
: 63;
159 code
[pos
/ 32] |= r
<< (pos
% 32);
162 void CodeEmitterNVC0::srcAddr32(const ValueRef
& src
, const int pos
)
164 code
[pos
/ 32] |= (SDATA(src
).offset
>> 2) << (pos
% 32);
167 void CodeEmitterNVC0::defId(const ValueDef
& def
, const int pos
)
169 code
[pos
/ 32] |= (def
.get() ? DDATA(def
).id
: 63) << (pos
% 32);
172 bool CodeEmitterNVC0::isLIMM(const ValueRef
& ref
, DataType ty
)
174 const ImmediateValue
*imm
= ref
.get()->asImm();
176 return imm
&& (imm
->reg
.data
.u32
& ((ty
== TYPE_F32
) ? 0xfff : 0xfff00000));
180 CodeEmitterNVC0::roundMode_A(const Instruction
*insn
)
183 case ROUND_M
: code
[1] |= 1 << 23; break;
184 case ROUND_P
: code
[1] |= 2 << 23; break;
185 case ROUND_Z
: code
[1] |= 3 << 23; break;
187 assert(insn
->rnd
== ROUND_N
);
193 CodeEmitterNVC0::emitNegAbs12(const Instruction
*i
)
195 if (i
->src(1).mod
.abs()) code
[0] |= 1 << 6;
196 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 7;
197 if (i
->src(1).mod
.neg()) code
[0] |= 1 << 8;
198 if (i
->src(0).mod
.neg()) code
[0] |= 1 << 9;
201 void CodeEmitterNVC0::emitCondCode(CondCode cc
, int pos
)
206 case CC_LT
: val
= 0x1; break;
207 case CC_LTU
: val
= 0x9; break;
208 case CC_EQ
: val
= 0x2; break;
209 case CC_EQU
: val
= 0xa; break;
210 case CC_LE
: val
= 0x3; break;
211 case CC_LEU
: val
= 0xb; break;
212 case CC_GT
: val
= 0x4; break;
213 case CC_GTU
: val
= 0xc; break;
214 case CC_NE
: val
= 0x5; break;
215 case CC_NEU
: val
= 0xd; break;
216 case CC_GE
: val
= 0x6; break;
217 case CC_GEU
: val
= 0xe; break;
218 case CC_TR
: val
= 0xf; break;
219 case CC_FL
: val
= 0x0; break;
221 case CC_A
: val
= 0x14; break;
222 case CC_NA
: val
= 0x13; break;
223 case CC_S
: val
= 0x15; break;
224 case CC_NS
: val
= 0x12; break;
225 case CC_C
: val
= 0x16; break;
226 case CC_NC
: val
= 0x11; break;
227 case CC_O
: val
= 0x17; break;
228 case CC_NO
: val
= 0x10; break;
232 assert(!"invalid condition code");
235 code
[pos
/ 32] |= val
<< (pos
% 32);
239 CodeEmitterNVC0::emitPredicate(const Instruction
*i
)
241 if (i
->predSrc
>= 0) {
242 assert(i
->getPredicate()->reg
.file
== FILE_PREDICATE
);
243 srcId(i
->src(i
->predSrc
), 10);
244 if (i
->cc
== CC_NOT_P
)
245 code
[0] |= 0x2000; // negate
252 CodeEmitterNVC0::setAddress16(const ValueRef
& src
)
254 Symbol
*sym
= src
.get()->asSym();
258 code
[0] |= (sym
->reg
.data
.offset
& 0x003f) << 26;
259 code
[1] |= (sym
->reg
.data
.offset
& 0xffc0) >> 6;
263 CodeEmitterNVC0::setImmediate(const Instruction
*i
, const int s
)
265 const ImmediateValue
*imm
= i
->src(s
).get()->asImm();
269 u32
= imm
->reg
.data
.u32
;
271 if ((code
[0] & 0xf) == 0x2) {
273 code
[0] |= (u32
& 0x3f) << 26;
276 if ((code
[0] & 0xf) == 0x3 || (code
[0] & 0xf) == 4) {
278 assert((u32
& 0xfff00000) == 0 || (u32
& 0xfff00000) == 0xfff00000);
279 assert(!(code
[1] & 0xc000));
281 code
[0] |= (u32
& 0x3f) << 26;
282 code
[1] |= 0xc000 | (u32
>> 6);
285 assert(!(u32
& 0x00000fff));
286 assert(!(code
[1] & 0xc000));
287 code
[0] |= ((u32
>> 12) & 0x3f) << 26;
288 code
[1] |= 0xc000 | (u32
>> 18);
292 void CodeEmitterNVC0::setImmediateS8(const ValueRef
&ref
)
294 const ImmediateValue
*imm
= ref
.get()->asImm();
296 int8_t s8
= static_cast<int8_t>(imm
->reg
.data
.s32
);
298 assert(s8
== imm
->reg
.data
.s32
);
300 code
[0] |= (s8
& 0x3f) << 26;
301 code
[0] |= (s8
>> 6) << 8;
305 CodeEmitterNVC0::emitForm_A(const Instruction
*i
, uint64_t opc
)
312 defId(i
->def(0), 14);
315 if (i
->srcExists(2) && i
->getSrc(2)->reg
.file
== FILE_MEMORY_CONST
)
318 for (int s
= 0; s
< 3 && i
->srcExists(s
); ++s
) {
319 switch (i
->getSrc(s
)->reg
.file
) {
320 case FILE_MEMORY_CONST
:
321 assert(!(code
[1] & 0xc000));
322 code
[1] |= (s
== 2) ? 0x8000 : 0x4000;
323 code
[1] |= i
->getSrc(s
)->reg
.fileIndex
<< 10;
324 setAddress16(i
->src(s
));
328 i
->op
== OP_MOV
|| i
->op
== OP_PRESIN
|| i
->op
== OP_PREEX2
);
329 assert(!(code
[1] & 0xc000));
333 if ((s
== 2) && ((code
[0] & 0x7) == 2)) // LIMM: 3rd src == dst
335 srcId(i
->src(s
), s
? ((s
== 2) ? 49 : s1
) : 20);
338 // ignore here, can be predicate or flags, but must not be address
345 CodeEmitterNVC0::emitForm_B(const Instruction
*i
, uint64_t opc
)
352 defId(i
->def(0), 14);
354 switch (i
->src(0).getFile()) {
355 case FILE_MEMORY_CONST
:
356 assert(!(code
[1] & 0xc000));
357 code
[1] |= 0x4000 | (i
->src(0).get()->reg
.fileIndex
<< 10);
358 setAddress16(i
->src(0));
361 assert(!(code
[1] & 0xc000));
365 srcId(i
->src(0), 26);
368 // ignore here, can be predicate or flags, but must not be address
374 CodeEmitterNVC0::emitForm_S(const Instruction
*i
, uint32_t opc
, bool pred
)
379 if (opc
== 0x0d || opc
== 0x0e)
382 defId(i
->def(0), 14);
383 srcId(i
->src(0), 20);
385 assert(pred
|| (i
->predSrc
< 0));
389 for (int s
= 1; s
< 3 && i
->srcExists(s
); ++s
) {
390 if (i
->src(s
).get()->reg
.file
== FILE_MEMORY_CONST
) {
391 assert(!(code
[0] & (0x300 >> ss2a
)));
392 switch (i
->src(s
).get()->reg
.fileIndex
) {
393 case 0: code
[0] |= 0x100 >> ss2a
; break;
394 case 1: code
[0] |= 0x200 >> ss2a
; break;
395 case 16: code
[0] |= 0x300 >> ss2a
; break;
397 ERROR("invalid c[] space for short form\n");
401 code
[0] |= i
->getSrc(s
)->reg
.data
.offset
<< 24;
403 code
[0] |= i
->getSrc(s
)->reg
.data
.offset
<< 6;
405 if (i
->src(s
).getFile() == FILE_IMMEDIATE
) {
407 setImmediateS8(i
->src(s
));
409 if (i
->src(s
).getFile() == FILE_GPR
) {
410 srcId(i
->src(s
), (s
== 1) ? 26 : 8);
416 CodeEmitterNVC0::emitShortSrc2(const ValueRef
&src
)
418 if (src
.getFile() == FILE_MEMORY_CONST
) {
419 switch (src
.get()->reg
.fileIndex
) {
420 case 0: code
[0] |= 0x100; break;
421 case 1: code
[0] |= 0x200; break;
422 case 16: code
[0] |= 0x300; break;
424 assert(!"unsupported file index for short op");
430 assert(src
.getFile() == FILE_GPR
);
435 CodeEmitterNVC0::emitNOP(const Instruction
*i
)
437 code
[0] = 0x000001e4;
438 code
[1] = 0x40000000;
443 CodeEmitterNVC0::emitFMAD(const Instruction
*i
)
445 bool neg1
= (i
->src(0).mod
^ i
->src(1).mod
).neg();
447 if (i
->encSize
== 8) {
448 if (isLIMM(i
->src(1), TYPE_F32
)) {
449 emitForm_A(i
, HEX64(20000000, 00000002));
451 emitForm_A(i
, HEX64(30000000, 00000000));
453 if (i
->src(2).mod
.neg())
466 assert(!i
->saturate
&& !i
->src(2).mod
.neg());
467 emitForm_S(i
, (i
->src(2).getFile() == FILE_MEMORY_CONST
) ? 0x2e : 0x0e,
475 CodeEmitterNVC0::emitFMUL(const Instruction
*i
)
477 bool neg
= (i
->src(0).mod
^ i
->src(1).mod
).neg();
479 assert(i
->postFactor
>= -3 && i
->postFactor
<= 3);
481 if (i
->encSize
== 8) {
482 if (isLIMM(i
->src(1), TYPE_F32
)) {
483 assert(i
->postFactor
== 0); // constant folded, hopefully
484 emitForm_A(i
, HEX64(30000000, 00000002));
486 emitForm_A(i
, HEX64(58000000, 00000000));
488 code
[1] |= ((i
->postFactor
> 0) ?
489 (7 - i
->postFactor
) : (0 - i
->postFactor
)) << 17;
492 code
[1] ^= 1 << 25; // aliases with LIMM sign bit
503 assert(!neg
&& !i
->saturate
&& !i
->ftz
&& !i
->postFactor
);
504 emitForm_S(i
, 0xa8, true);
509 CodeEmitterNVC0::emitUMUL(const Instruction
*i
)
511 if (i
->encSize
== 8) {
512 if (i
->src(1).getFile() == FILE_IMMEDIATE
) {
513 emitForm_A(i
, HEX64(10000000, 00000002));
515 emitForm_A(i
, HEX64(50000000, 00000003));
517 if (i
->subOp
== NV50_IR_SUBOP_MUL_HIGH
)
519 if (i
->sType
== TYPE_S32
)
521 if (i
->dType
== TYPE_S32
)
524 emitForm_S(i
, i
->src(1).getFile() == FILE_IMMEDIATE
? 0xaa : 0x2a, true);
526 if (i
->sType
== TYPE_S32
)
532 CodeEmitterNVC0::emitFADD(const Instruction
*i
)
534 if (i
->encSize
== 8) {
535 if (isLIMM(i
->src(1), TYPE_F32
)) {
536 assert(!i
->saturate
);
537 emitForm_A(i
, HEX64(28000000, 00000002));
539 code
[0] |= i
->src(0).mod
.abs() << 7;
540 code
[0] |= i
->src(0).mod
.neg() << 9;
542 if (i
->src(1).mod
.abs())
543 code
[1] &= 0xfdffffff;
544 if ((i
->op
== OP_SUB
) != static_cast<bool>(i
->src(1).mod
.neg()))
545 code
[1] ^= 0x02000000;
547 emitForm_A(i
, HEX64(50000000, 00000000));
554 if (i
->op
== OP_SUB
) code
[0] ^= 1 << 8;
559 assert(!i
->saturate
&& i
->op
!= OP_SUB
&&
560 !i
->src(0).mod
.abs() &&
561 !i
->src(1).mod
.neg() && !i
->src(1).mod
.abs());
563 emitForm_S(i
, 0x49, true);
565 if (i
->src(0).mod
.neg())
571 CodeEmitterNVC0::emitUADD(const Instruction
*i
)
575 assert(!i
->src(0).mod
.abs() && !i
->src(1).mod
.abs());
576 assert(!i
->src(0).mod
.neg() || !i
->src(1).mod
.neg());
578 if (i
->src(0).mod
.neg())
580 if (i
->src(1).mod
.neg())
582 if (i
->op
== OP_SUB
) {
584 assert(addOp
!= 0x300); // would be add-plus-one
587 if (i
->encSize
== 8) {
588 if (isLIMM(i
->src(1), TYPE_U32
)) {
589 emitForm_A(i
, HEX64(08000000, 00000002));
591 code
[1] |= 1 << 26; // write carry
593 emitForm_A(i
, HEX64(48000000, 00000003));
595 code
[1] |= 1 << 16; // write carry
601 if (i
->flagsSrc
>= 0) // add carry
604 assert(!(addOp
& 0x100));
605 emitForm_S(i
, (addOp
>> 3) |
606 ((i
->src(1).getFile() == FILE_IMMEDIATE
) ? 0xac : 0x2c), true);
612 CodeEmitterNVC0::emitIMAD(const Instruction
*i
)
614 assert(i
->encSize
== 8);
615 emitForm_A(i
, HEX64(20000000, 00000003));
617 if (isSignedType(i
->dType
))
619 if (isSignedType(i
->sType
))
622 code
[1] |= i
->saturate
<< 24;
624 if (i
->flagsDef
>= 0) code
[1] |= 1 << 16;
625 if (i
->flagsSrc
>= 0) code
[1] |= 1 << 23;
627 if (i
->src(2).mod
.neg()) code
[0] |= 0x10;
628 if (i
->src(1).mod
.neg() ^
629 i
->src(0).mod
.neg()) code
[0] |= 0x20;
631 if (i
->subOp
== NV50_IR_SUBOP_MUL_HIGH
)
636 CodeEmitterNVC0::emitMADSP(const Instruction
*i
)
638 assert(targ
->getChipset() >= NVISA_GK104_CHIPSET
);
640 emitForm_A(i
, HEX64(00000000, 00000003));
642 if (i
->subOp
== NV50_IR_SUBOP_MADSP_SD
) {
643 code
[1] |= 0x01800000;
645 code
[0] |= (i
->subOp
& 0x00f) << 7;
646 code
[0] |= (i
->subOp
& 0x0f0) << 1;
647 code
[0] |= (i
->subOp
& 0x100) >> 3;
648 code
[0] |= (i
->subOp
& 0x200) >> 2;
649 code
[1] |= (i
->subOp
& 0xc00) << 13;
652 if (i
->flagsDef
>= 0)
657 CodeEmitterNVC0::emitISAD(const Instruction
*i
)
659 assert(i
->dType
== TYPE_S32
|| i
->dType
== TYPE_U32
);
660 assert(i
->encSize
== 8);
662 emitForm_A(i
, HEX64(38000000, 00000003));
664 if (i
->dType
== TYPE_S32
)
669 CodeEmitterNVC0::emitNOT(Instruction
*i
)
671 assert(i
->encSize
== 8);
672 i
->setSrc(1, i
->src(0));
673 emitForm_A(i
, HEX64(68000000, 000001c3
));
677 CodeEmitterNVC0::emitLogicOp(const Instruction
*i
, uint8_t subOp
)
679 if (i
->def(0).getFile() == FILE_PREDICATE
) {
680 code
[0] = 0x00000004 | (subOp
<< 30);
681 code
[1] = 0x0c000000;
685 defId(i
->def(0), 17);
686 srcId(i
->src(0), 20);
687 if (i
->src(0).mod
== Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 23;
688 srcId(i
->src(1), 26);
689 if (i
->src(1).mod
== Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 29;
691 if (i
->defExists(1)) {
692 defId(i
->def(1), 14);
697 if (i
->predSrc
!= 2 && i
->srcExists(2)) {
698 code
[1] |= subOp
<< 21;
699 srcId(i
->src(2), 17);
700 if (i
->src(2).mod
== Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 20;
702 code
[1] |= 0x000e0000;
705 if (i
->encSize
== 8) {
706 if (isLIMM(i
->src(1), TYPE_U32
)) {
707 emitForm_A(i
, HEX64(38000000, 00000002));
709 if (i
->flagsDef
>= 0)
712 emitForm_A(i
, HEX64(68000000, 00000003));
714 if (i
->flagsDef
>= 0)
717 code
[0] |= subOp
<< 6;
719 if (i
->flagsSrc
>= 0) // carry
722 if (i
->src(0).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 9;
723 if (i
->src(1).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 8;
725 emitForm_S(i
, (subOp
<< 5) |
726 ((i
->src(1).getFile() == FILE_IMMEDIATE
) ? 0x1d : 0x8d), true);
731 CodeEmitterNVC0::emitPOPC(const Instruction
*i
)
733 emitForm_A(i
, HEX64(54000000, 00000004));
735 if (i
->src(0).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 9;
736 if (i
->src(1).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 8;
740 CodeEmitterNVC0::emitINSBF(const Instruction
*i
)
742 emitForm_A(i
, HEX64(28000000, 30000000));
746 CodeEmitterNVC0::emitShift(const Instruction
*i
)
748 if (i
->op
== OP_SHR
) {
749 emitForm_A(i
, HEX64(58000000, 00000003)
750 | (isSignedType(i
->dType
) ? 0x20 : 0x00));
752 emitForm_A(i
, HEX64(60000000, 00000003));
755 if (i
->subOp
== NV50_IR_SUBOP_SHIFT_WRAP
)
760 CodeEmitterNVC0::emitPreOp(const Instruction
*i
)
762 if (i
->encSize
== 8) {
763 emitForm_B(i
, HEX64(60000000, 00000000));
765 if (i
->op
== OP_PREEX2
)
768 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 6;
769 if (i
->src(0).mod
.neg()) code
[0] |= 1 << 8;
771 emitForm_S(i
, i
->op
== OP_PREEX2
? 0x74000008 : 0x70000008, true);
776 CodeEmitterNVC0::emitSFnOp(const Instruction
*i
, uint8_t subOp
)
778 if (i
->encSize
== 8) {
779 code
[0] = 0x00000000 | (subOp
<< 26);
780 code
[1] = 0xc8000000;
784 defId(i
->def(0), 14);
785 srcId(i
->src(0), 20);
787 assert(i
->src(0).getFile() == FILE_GPR
);
789 if (i
->saturate
) code
[0] |= 1 << 5;
791 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 7;
792 if (i
->src(0).mod
.neg()) code
[0] |= 1 << 9;
794 emitForm_S(i
, 0x80000008 | (subOp
<< 26), true);
796 assert(!i
->src(0).mod
.neg());
797 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 30;
802 CodeEmitterNVC0::emitMINMAX(const Instruction
*i
)
806 assert(i
->encSize
== 8);
808 op
= (i
->op
== OP_MIN
) ? 0x080e000000000000ULL
: 0x081e000000000000ULL
;
813 if (!isFloatType(i
->dType
))
814 op
|= isSignedType(i
->dType
) ? 0x23 : 0x03;
821 CodeEmitterNVC0::roundMode_C(const Instruction
*i
)
824 case ROUND_M
: code
[1] |= 1 << 17; break;
825 case ROUND_P
: code
[1] |= 2 << 17; break;
826 case ROUND_Z
: code
[1] |= 3 << 17; break;
827 case ROUND_NI
: code
[0] |= 1 << 7; break;
828 case ROUND_MI
: code
[0] |= 1 << 7; code
[1] |= 1 << 17; break;
829 case ROUND_PI
: code
[0] |= 1 << 7; code
[1] |= 2 << 17; break;
830 case ROUND_ZI
: code
[0] |= 1 << 7; code
[1] |= 3 << 17; break;
833 assert(!"invalid round mode");
839 CodeEmitterNVC0::roundMode_CS(const Instruction
*i
)
843 case ROUND_MI
: code
[0] |= 1 << 16; break;
845 case ROUND_PI
: code
[0] |= 2 << 16; break;
847 case ROUND_ZI
: code
[0] |= 3 << 16; break;
854 CodeEmitterNVC0::emitCVT(Instruction
*i
)
856 const bool f2f
= isFloatType(i
->dType
) && isFloatType(i
->sType
);
859 case OP_CEIL
: i
->rnd
= f2f
? ROUND_PI
: ROUND_P
; break;
860 case OP_FLOOR
: i
->rnd
= f2f
? ROUND_MI
: ROUND_M
; break;
861 case OP_TRUNC
: i
->rnd
= f2f
? ROUND_ZI
: ROUND_Z
; break;
866 const bool sat
= (i
->op
== OP_SAT
) || i
->saturate
;
867 const bool abs
= (i
->op
== OP_ABS
) || i
->src(0).mod
.abs();
868 const bool neg
= (i
->op
== OP_NEG
) || i
->src(0).mod
.neg();
870 if (i
->encSize
== 8) {
871 emitForm_B(i
, HEX64(10000000, 00000004));
875 // cvt u16 f32 sets high bits to 0, so we don't have to use Value::Size()
876 code
[0] |= util_logbase2(typeSizeof(i
->dType
)) << 20;
877 code
[0] |= util_logbase2(typeSizeof(i
->sType
)) << 23;
883 if (neg
&& i
->op
!= OP_ABS
)
889 if (isSignedIntType(i
->dType
))
891 if (isSignedIntType(i
->sType
))
894 if (isFloatType(i
->dType
)) {
895 if (!isFloatType(i
->sType
))
896 code
[1] |= 0x08000000;
898 if (isFloatType(i
->sType
))
899 code
[1] |= 0x04000000;
901 code
[1] |= 0x0c000000;
904 if (i
->op
== OP_CEIL
|| i
->op
== OP_FLOOR
|| i
->op
== OP_TRUNC
) {
907 if (isFloatType(i
->dType
)) {
908 if (isFloatType(i
->sType
))
911 code
[0] = 0x088 | (isSignedType(i
->sType
) ? (1 << 8) : 0);
913 assert(isFloatType(i
->sType
));
915 code
[0] = 0x288 | (isSignedType(i
->sType
) ? (1 << 8) : 0);
918 if (neg
) code
[0] |= 1 << 16;
919 if (sat
) code
[0] |= 1 << 18;
920 if (abs
) code
[0] |= 1 << 19;
927 CodeEmitterNVC0::emitSET(const CmpInstruction
*i
)
932 if (i
->sType
== TYPE_F64
)
935 if (!isFloatType(i
->sType
))
938 if (isFloatType(i
->dType
) || isSignedIntType(i
->sType
))
942 case OP_SET_AND
: hi
= 0x10000000; break;
943 case OP_SET_OR
: hi
= 0x10200000; break;
944 case OP_SET_XOR
: hi
= 0x10400000; break;
949 emitForm_A(i
, (static_cast<uint64_t>(hi
) << 32) | lo
);
952 srcId(i
->src(2), 32 + 17);
954 if (i
->def(0).getFile() == FILE_PREDICATE
) {
955 if (i
->sType
== TYPE_F32
)
956 code
[1] += 0x10000000;
958 code
[1] += 0x08000000;
961 defId(i
->def(0), 17);
963 defId(i
->def(1), 14);
971 emitCondCode(i
->setCond
, 32 + 23);
976 CodeEmitterNVC0::emitSLCT(const CmpInstruction
*i
)
982 op
= HEX64(30000000, 00000023);
985 op
= HEX64(30000000, 00000003);
988 op
= HEX64(38000000, 00000000);
991 assert(!"invalid type for SLCT");
997 CondCode cc
= i
->setCond
;
999 if (i
->src(2).mod
.neg())
1000 cc
= reverseCondCode(cc
);
1002 emitCondCode(cc
, 32 + 23);
1008 void CodeEmitterNVC0::emitSELP(const Instruction
*i
)
1010 emitForm_A(i
, HEX64(20000000, 00000004));
1012 if (i
->cc
== CC_NOT_P
|| i
->src(2).mod
& Modifier(NV50_IR_MOD_NOT
))
1016 void CodeEmitterNVC0::emitTEXBAR(const Instruction
*i
)
1018 code
[0] = 0x00000006 | (i
->subOp
<< 26);
1019 code
[1] = 0xf0000000;
1021 emitCondCode(i
->flagsSrc
>= 0 ? i
->cc
: CC_ALWAYS
, 5);
1024 void CodeEmitterNVC0::emitTEXCSAA(const TexInstruction
*i
)
1026 code
[0] = 0x00000086;
1027 code
[1] = 0xd0000000;
1029 code
[1] |= i
->tex
.r
;
1030 code
[1] |= i
->tex
.s
<< 8;
1032 if (i
->tex
.liveOnly
)
1035 defId(i
->def(0), 14);
1036 srcId(i
->src(0), 20);
1040 isNextIndependentTex(const TexInstruction
*i
)
1042 if (!i
->next
|| !isTextureOp(i
->next
->op
))
1044 if (i
->getDef(0)->interfers(i
->next
->getSrc(0)))
1046 return !i
->next
->srcExists(1) || !i
->getDef(0)->interfers(i
->next
->getSrc(1));
1050 CodeEmitterNVC0::emitTEX(const TexInstruction
*i
)
1052 code
[0] = 0x00000006;
1054 if (isNextIndependentTex(i
))
1055 code
[0] |= 0x080; // t mode
1057 code
[0] |= 0x100; // p mode
1059 if (i
->tex
.liveOnly
)
1063 case OP_TEX
: code
[1] = 0x80000000; break;
1064 case OP_TXB
: code
[1] = 0x84000000; break;
1065 case OP_TXL
: code
[1] = 0x86000000; break;
1066 case OP_TXF
: code
[1] = 0x90000000; break;
1067 case OP_TXG
: code
[1] = 0xa0000000; break;
1068 case OP_TXD
: code
[1] = 0xe0000000; break;
1070 assert(!"invalid texture op");
1073 if (i
->op
== OP_TXF
) {
1074 if (!i
->tex
.levelZero
)
1075 code
[1] |= 0x02000000;
1077 if (i
->tex
.levelZero
) {
1078 code
[1] |= 0x02000000;
1081 if (i
->op
!= OP_TXD
&& i
->tex
.derivAll
)
1084 defId(i
->def(0), 14);
1085 srcId(i
->src(0), 20);
1089 if (i
->op
== OP_TXG
) code
[0] |= i
->tex
.gatherComp
<< 5;
1091 code
[1] |= i
->tex
.mask
<< 14;
1093 code
[1] |= i
->tex
.r
;
1094 code
[1] |= i
->tex
.s
<< 8;
1095 if (i
->tex
.rIndirectSrc
>= 0 || i
->tex
.sIndirectSrc
>= 0)
1096 code
[1] |= 1 << 18; // in 1st source (with array index)
1099 code
[1] |= (i
->tex
.target
.getDim() - 1) << 20;
1100 if (i
->tex
.target
.isCube())
1102 if (i
->tex
.target
.isArray())
1104 if (i
->tex
.target
.isShadow())
1107 const int src1
= (i
->predSrc
== 1) ? 2 : 1; // if predSrc == 1, !srcExists(2)
1109 if (i
->srcExists(src1
) && i
->src(src1
).getFile() == FILE_IMMEDIATE
) {
1111 if (i
->op
== OP_TXL
)
1112 code
[1] &= ~(1 << 26);
1114 if (i
->op
== OP_TXF
)
1115 code
[1] &= ~(1 << 25);
1117 if (i
->tex
.target
== TEX_TARGET_2D_MS
||
1118 i
->tex
.target
== TEX_TARGET_2D_MS_ARRAY
)
1121 if (i
->tex
.useOffsets
) // in vecSrc0.w
1128 CodeEmitterNVC0::emitTXQ(const TexInstruction
*i
)
1130 code
[0] = 0x00000086;
1131 code
[1] = 0xc0000000;
1133 switch (i
->tex
.query
) {
1134 case TXQ_DIMS
: code
[1] |= 0 << 22; break;
1135 case TXQ_TYPE
: code
[1] |= 1 << 22; break;
1136 case TXQ_SAMPLE_POSITION
: code
[1] |= 2 << 22; break;
1137 case TXQ_FILTER
: code
[1] |= 3 << 22; break;
1138 case TXQ_LOD
: code
[1] |= 4 << 22; break;
1139 case TXQ_BORDER_COLOUR
: code
[1] |= 5 << 22; break;
1141 assert(!"invalid texture query");
1145 code
[1] |= i
->tex
.mask
<< 14;
1147 code
[1] |= i
->tex
.r
;
1148 code
[1] |= i
->tex
.s
<< 8;
1149 if (i
->tex
.sIndirectSrc
>= 0 || i
->tex
.rIndirectSrc
>= 0)
1152 const int src1
= (i
->predSrc
== 1) ? 2 : 1; // if predSrc == 1, !srcExists(2)
1154 defId(i
->def(0), 14);
1155 srcId(i
->src(0), 20);
1162 CodeEmitterNVC0::emitQUADOP(const Instruction
*i
, uint8_t qOp
, uint8_t laneMask
)
1164 code
[0] = 0x00000000 | (laneMask
<< 6);
1165 code
[1] = 0x48000000 | qOp
;
1167 defId(i
->def(0), 14);
1168 srcId(i
->src(0), 20);
1169 srcId(i
->srcExists(1) ? i
->src(1) : i
->src(0), 26);
1171 if (i
->op
== OP_QUADOP
&& progType
!= Program::TYPE_FRAGMENT
)
1172 code
[0] |= 1 << 9; // dall
1178 CodeEmitterNVC0::emitFlow(const Instruction
*i
)
1180 const FlowInstruction
*f
= i
->asFlow();
1182 unsigned mask
; // bit 0: predicate, bit 1: target
1184 code
[0] = 0x00000007;
1188 code
[1] = f
->absolute
? 0x00000000 : 0x40000000;
1189 if (i
->srcExists(0) && i
->src(0).getFile() == FILE_MEMORY_CONST
)
1194 code
[1] = f
->absolute
? 0x10000000 : 0x50000000;
1196 code
[0] |= 0x4000; // indirect calls always use c[] source
1200 case OP_EXIT
: code
[1] = 0x80000000; mask
= 1; break;
1201 case OP_RET
: code
[1] = 0x90000000; mask
= 1; break;
1202 case OP_DISCARD
: code
[1] = 0x98000000; mask
= 1; break;
1203 case OP_BREAK
: code
[1] = 0xa8000000; mask
= 1; break;
1204 case OP_CONT
: code
[1] = 0xb0000000; mask
= 1; break;
1206 case OP_JOINAT
: code
[1] = 0x60000000; mask
= 2; break;
1207 case OP_PREBREAK
: code
[1] = 0x68000000; mask
= 2; break;
1208 case OP_PRECONT
: code
[1] = 0x70000000; mask
= 2; break;
1209 case OP_PRERET
: code
[1] = 0x78000000; mask
= 2; break;
1211 case OP_QUADON
: code
[1] = 0xc0000000; mask
= 0; break;
1212 case OP_QUADPOP
: code
[1] = 0xc8000000; mask
= 0; break;
1213 case OP_BRKPT
: code
[1] = 0xd0000000; mask
= 0; break;
1215 assert(!"invalid flow operation");
1221 if (i
->flagsSrc
< 0)
1234 if (code
[0] & 0x4000) {
1235 assert(i
->srcExists(0) && i
->src(0).getFile() == FILE_MEMORY_CONST
);
1236 setAddress16(i
->src(0));
1237 code
[1] |= i
->getSrc(0)->reg
.fileIndex
<< 10;
1238 if (f
->op
== OP_BRA
)
1239 srcId(f
->src(0).getIndirect(0), 20);
1245 if (f
->op
== OP_CALL
) {
1250 assert(f
->absolute
);
1251 uint32_t pcAbs
= targNVC0
->getBuiltinOffset(f
->target
.builtin
);
1252 addReloc(RelocEntry::TYPE_BUILTIN
, 0, pcAbs
, 0xfc000000, 26);
1253 addReloc(RelocEntry::TYPE_BUILTIN
, 1, pcAbs
, 0x03ffffff, -6);
1255 assert(!f
->absolute
);
1256 int32_t pcRel
= f
->target
.fn
->binPos
- (codeSize
+ 8);
1257 code
[0] |= (pcRel
& 0x3f) << 26;
1258 code
[1] |= (pcRel
>> 6) & 0x3ffff;
1262 int32_t pcRel
= f
->target
.bb
->binPos
- (codeSize
+ 8);
1263 // currently we don't want absolute branches
1264 assert(!f
->absolute
);
1265 code
[0] |= (pcRel
& 0x3f) << 26;
1266 code
[1] |= (pcRel
>> 6) & 0x3ffff;
1271 CodeEmitterNVC0::emitPFETCH(const Instruction
*i
)
1273 uint32_t prim
= i
->src(0).get()->reg
.data
.u32
;
1275 code
[0] = 0x00000006 | ((prim
& 0x3f) << 26);
1276 code
[1] = 0x00000000 | (prim
>> 6);
1280 defId(i
->def(0), 14);
1281 srcId(i
->src(1), 20);
1285 CodeEmitterNVC0::emitVFETCH(const Instruction
*i
)
1287 code
[0] = 0x00000006;
1288 code
[1] = 0x06000000 | i
->src(0).get()->reg
.data
.offset
;
1292 if (i
->getSrc(0)->reg
.file
== FILE_SHADER_OUTPUT
)
1293 code
[0] |= 0x200; // yes, TCPs can read from *outputs* of other threads
1297 code
[0] |= ((i
->getDef(0)->reg
.size
/ 4) - 1) << 5;
1299 defId(i
->def(0), 14);
1300 srcId(i
->src(0).getIndirect(0), 20);
1301 srcId(i
->src(0).getIndirect(1), 26); // vertex address
1305 CodeEmitterNVC0::emitEXPORT(const Instruction
*i
)
1307 unsigned int size
= typeSizeof(i
->dType
);
1309 code
[0] = 0x00000006 | ((size
/ 4 - 1) << 5);
1310 code
[1] = 0x0a000000 | i
->src(0).get()->reg
.data
.offset
;
1312 assert(!(code
[1] & ((size
== 12) ? 15 : (size
- 1))));
1319 assert(i
->src(1).getFile() == FILE_GPR
);
1321 srcId(i
->src(0).getIndirect(0), 20);
1322 srcId(i
->src(0).getIndirect(1), 32 + 17); // vertex base address
1323 srcId(i
->src(1), 26);
1327 CodeEmitterNVC0::emitOUT(const Instruction
*i
)
1329 code
[0] = 0x00000006;
1330 code
[1] = 0x1c000000;
1334 defId(i
->def(0), 14); // new secret address
1335 srcId(i
->src(0), 20); // old secret address, should be 0 initially
1337 assert(i
->src(0).getFile() == FILE_GPR
);
1339 if (i
->op
== OP_EMIT
)
1341 if (i
->op
== OP_RESTART
|| i
->subOp
== NV50_IR_SUBOP_EMIT_RESTART
)
1345 if (i
->src(1).getFile() == FILE_IMMEDIATE
) {
1347 code
[0] |= SDATA(i
->src(1)).u32
<< 26;
1349 srcId(i
->src(1), 26);
1354 CodeEmitterNVC0::emitInterpMode(const Instruction
*i
)
1356 if (i
->encSize
== 8) {
1357 code
[0] |= i
->ipa
<< 6; // TODO: INTERP_SAMPLEID
1359 if (i
->getInterpMode() == NV50_IR_INTERP_SC
)
1361 assert(i
->op
== OP_PINTERP
&& i
->getSampleMode() == 0);
1366 CodeEmitterNVC0::emitINTERP(const Instruction
*i
)
1368 const uint32_t base
= i
->getSrc(0)->reg
.data
.offset
;
1370 if (i
->encSize
== 8) {
1371 code
[0] = 0x00000000;
1372 code
[1] = 0xc0000000 | (base
& 0xffff);
1377 if (i
->op
== OP_PINTERP
)
1378 srcId(i
->src(1), 26);
1380 code
[0] |= 0x3f << 26;
1382 srcId(i
->src(0).getIndirect(0), 20);
1384 assert(i
->op
== OP_PINTERP
);
1385 code
[0] = 0x00000009 | ((base
& 0xc) << 6) | ((base
>> 4) << 26);
1386 srcId(i
->src(1), 20);
1391 defId(i
->def(0), 14);
1393 if (i
->getSampleMode() == NV50_IR_INTERP_OFFSET
)
1394 srcId(i
->src(i
->op
== OP_PINTERP
? 2 : 1), 17);
1396 code
[1] |= 0x3f << 17;
1400 CodeEmitterNVC0::emitLoadStoreType(DataType ty
)
1433 assert(!"invalid type");
1440 CodeEmitterNVC0::emitCachingMode(CacheMode c
)
1461 assert(!"invalid caching mode");
1468 uses64bitAddress(const Instruction
*ldst
)
1470 return ldst
->src(0).getFile() == FILE_MEMORY_GLOBAL
&&
1471 ldst
->src(0).isIndirect(0) &&
1472 ldst
->getIndirect(0, 0)->reg
.size
== 8;
1476 CodeEmitterNVC0::emitSTORE(const Instruction
*i
)
1480 switch (i
->src(0).getFile()) {
1481 case FILE_MEMORY_GLOBAL
: opc
= 0x90000000; break;
1482 case FILE_MEMORY_LOCAL
: opc
= 0xc8000000; break;
1483 case FILE_MEMORY_SHARED
: opc
= 0xc9000000; break;
1485 assert(!"invalid memory file");
1489 code
[0] = 0x00000005;
1492 setAddress16(i
->src(0));
1493 srcId(i
->src(1), 14);
1494 srcId(i
->src(0).getIndirect(0), 20);
1495 if (uses64bitAddress(i
))
1500 emitLoadStoreType(i
->dType
);
1501 emitCachingMode(i
->cache
);
1505 CodeEmitterNVC0::emitLOAD(const Instruction
*i
)
1509 code
[0] = 0x00000005;
1511 switch (i
->src(0).getFile()) {
1512 case FILE_MEMORY_GLOBAL
: opc
= 0x80000000; break;
1513 case FILE_MEMORY_LOCAL
: opc
= 0xc0000000; break;
1514 case FILE_MEMORY_SHARED
: opc
= 0xc1000000; break;
1515 case FILE_MEMORY_CONST
:
1516 if (!i
->src(0).isIndirect(0) && typeSizeof(i
->dType
) == 4) {
1517 emitMOV(i
); // not sure if this is any better
1520 opc
= 0x14000000 | (i
->src(0).get()->reg
.fileIndex
<< 10);
1521 code
[0] = 0x00000006 | (i
->subOp
<< 8);
1524 assert(!"invalid memory file");
1530 defId(i
->def(0), 14);
1532 setAddress16(i
->src(0));
1533 srcId(i
->src(0).getIndirect(0), 20);
1534 if (uses64bitAddress(i
))
1539 emitLoadStoreType(i
->dType
);
1540 emitCachingMode(i
->cache
);
1544 CodeEmitterNVC0::getSRegEncoding(const ValueRef
& ref
)
1546 switch (SDATA(ref
).sv
.sv
) {
1547 case SV_LANEID
: return 0x00;
1548 case SV_PHYSID
: return 0x03;
1549 case SV_VERTEX_COUNT
: return 0x10;
1550 case SV_INVOCATION_ID
: return 0x11;
1551 case SV_YDIR
: return 0x12;
1552 case SV_TID
: return 0x21 + SDATA(ref
).sv
.index
;
1553 case SV_CTAID
: return 0x25 + SDATA(ref
).sv
.index
;
1554 case SV_NTID
: return 0x29 + SDATA(ref
).sv
.index
;
1555 case SV_GRIDID
: return 0x2c;
1556 case SV_NCTAID
: return 0x2d + SDATA(ref
).sv
.index
;
1557 case SV_LBASE
: return 0x34;
1558 case SV_SBASE
: return 0x30;
1559 case SV_CLOCK
: return 0x50 + SDATA(ref
).sv
.index
;
1561 assert(!"no sreg for system value");
1567 CodeEmitterNVC0::emitMOV(const Instruction
*i
)
1569 if (i
->def(0).getFile() == FILE_PREDICATE
) {
1570 if (i
->src(0).getFile() == FILE_GPR
) {
1571 code
[0] = 0xfc01c003;
1572 code
[1] = 0x1a8e0000;
1573 srcId(i
->src(0), 20);
1575 code
[0] = 0x0001c004;
1576 code
[1] = 0x0c0e0000;
1577 if (i
->src(0).getFile() == FILE_IMMEDIATE
) {
1579 if (!i
->getSrc(0)->reg
.data
.u32
)
1582 srcId(i
->src(0), 20);
1585 defId(i
->def(0), 17);
1588 if (i
->src(0).getFile() == FILE_SYSTEM_VALUE
) {
1589 uint8_t sr
= getSRegEncoding(i
->src(0));
1591 if (i
->encSize
== 8) {
1592 code
[0] = 0x00000004 | (sr
<< 26);
1593 code
[1] = 0x2c000000;
1595 code
[0] = 0x40000008 | (sr
<< 20);
1597 defId(i
->def(0), 14);
1601 if (i
->encSize
== 8) {
1604 if (i
->src(0).getFile() == FILE_IMMEDIATE
)
1605 opc
= HEX64(18000000, 000001e2
);
1607 if (i
->src(0).getFile() == FILE_PREDICATE
)
1608 opc
= HEX64(080e0000
, 1c000004
);
1610 opc
= HEX64(28000000, 00000004);
1612 opc
|= i
->lanes
<< 5;
1618 if (i
->src(0).getFile() == FILE_IMMEDIATE
) {
1619 imm
= SDATA(i
->src(0)).u32
;
1620 if (imm
& 0xfff00000) {
1621 assert(!(imm
& 0x000fffff));
1622 code
[0] = 0x00000318 | imm
;
1624 assert(imm
< 0x800 || ((int32_t)imm
>= -0x800));
1625 code
[0] = 0x00000118 | (imm
<< 20);
1629 emitShortSrc2(i
->src(0));
1631 defId(i
->def(0), 14);
1638 CodeEmitterNVC0::emitSUCLAMPMode(uint16_t subOp
)
1641 switch (subOp
& ~NV50_IR_SUBOP_SUCLAMP_2D
) {
1642 case NV50_IR_SUBOP_SUCLAMP_SD(0, 1): m
= 0; break;
1643 case NV50_IR_SUBOP_SUCLAMP_SD(1, 1): m
= 1; break;
1644 case NV50_IR_SUBOP_SUCLAMP_SD(2, 1): m
= 2; break;
1645 case NV50_IR_SUBOP_SUCLAMP_SD(3, 1): m
= 3; break;
1646 case NV50_IR_SUBOP_SUCLAMP_SD(4, 1): m
= 4; break;
1647 case NV50_IR_SUBOP_SUCLAMP_PL(0, 1): m
= 5; break;
1648 case NV50_IR_SUBOP_SUCLAMP_PL(1, 1): m
= 6; break;
1649 case NV50_IR_SUBOP_SUCLAMP_PL(2, 1): m
= 7; break;
1650 case NV50_IR_SUBOP_SUCLAMP_PL(3, 1): m
= 8; break;
1651 case NV50_IR_SUBOP_SUCLAMP_PL(4, 1): m
= 9; break;
1652 case NV50_IR_SUBOP_SUCLAMP_BL(0, 1): m
= 10; break;
1653 case NV50_IR_SUBOP_SUCLAMP_BL(1, 1): m
= 11; break;
1654 case NV50_IR_SUBOP_SUCLAMP_BL(2, 1): m
= 12; break;
1655 case NV50_IR_SUBOP_SUCLAMP_BL(3, 1): m
= 13; break;
1656 case NV50_IR_SUBOP_SUCLAMP_BL(4, 1): m
= 14; break;
1661 if (subOp
& NV50_IR_SUBOP_SUCLAMP_2D
)
1666 CodeEmitterNVC0::emitSUCalc(Instruction
*i
)
1668 ImmediateValue
*imm
= NULL
;
1671 if (i
->srcExists(2)) {
1672 imm
= i
->getSrc(2)->asImm();
1674 i
->setSrc(2, NULL
); // special case, make emitForm_A not assert
1678 case OP_SUCLAMP
: opc
= HEX64(58000000, 00000004); break;
1679 case OP_SUBFM
: opc
= HEX64(5c000000
, 00000004); break;
1680 case OP_SUEAU
: opc
= HEX64(60000000, 00000004); break;
1687 if (i
->op
== OP_SUCLAMP
) {
1688 if (i
->dType
== TYPE_S32
)
1690 emitSUCLAMPMode(i
->subOp
);
1693 if (i
->op
== OP_SUBFM
&& i
->subOp
== NV50_IR_SUBOP_SUBFM_3D
)
1696 if (i
->op
!= OP_SUEAU
) {
1697 if (i
->def(0).getFile() == FILE_PREDICATE
) { // p, #
1698 code
[0] |= 63 << 14;
1699 code
[1] |= i
->getDef(0)->reg
.data
.id
<< 23;
1701 if (i
->defExists(1)) { // r, p
1702 assert(i
->def(1).getFile() == FILE_PREDICATE
);
1703 code
[1] |= i
->getDef(1)->reg
.data
.id
<< 23;
1709 assert(i
->op
== OP_SUCLAMP
);
1711 code
[1] |= (imm
->reg
.data
.u32
& 0x3f) << 17; // sint6
1716 CodeEmitterNVC0::emitSUGType(DataType ty
)
1719 case TYPE_S32
: code
[1] |= 1 << 13; break;
1720 case TYPE_U8
: code
[1] |= 2 << 13; break;
1721 case TYPE_S8
: code
[1] |= 3 << 13; break;
1723 assert(ty
== TYPE_U32
);
1729 CodeEmitterNVC0::setSUConst16(const Instruction
*i
, const int s
)
1731 const uint32_t offset
= i
->getSrc(s
)->reg
.data
.offset
;
1733 assert(i
->src(s
).getFile() == FILE_MEMORY_CONST
);
1734 assert(offset
== (offset
& 0xfffc));
1737 code
[0] |= offset
<< 24;
1738 code
[1] |= offset
>> 8;
1739 code
[1] |= i
->getSrc(s
)->reg
.fileIndex
<< 8;
1743 CodeEmitterNVC0::setSUPred(const Instruction
*i
, const int s
)
1745 if (!i
->srcExists(s
) || (i
->predSrc
== s
)) {
1746 code
[1] |= 0x7 << 17;
1748 if (i
->src(s
).mod
== Modifier(NV50_IR_MOD_NOT
))
1750 srcId(i
->src(s
), 32 + 17);
1755 CodeEmitterNVC0::emitSULDGB(const TexInstruction
*i
)
1758 code
[1] = 0xd4000000 | (i
->subOp
<< 15);
1760 emitLoadStoreType(i
->dType
);
1761 emitSUGType(i
->sType
);
1762 emitCachingMode(i
->cache
);
1765 defId(i
->def(0), 14); // destination
1766 srcId(i
->src(0), 20); // address
1768 if (i
->src(1).getFile() == FILE_GPR
)
1769 srcId(i
->src(1), 26);
1776 CodeEmitterNVC0::emitSUSTGx(const TexInstruction
*i
)
1779 code
[1] = 0xdc000000 | (i
->subOp
<< 15);
1781 if (i
->op
== OP_SUSTP
)
1782 code
[1] |= i
->tex
.mask
<< 22;
1784 emitLoadStoreType(i
->dType
);
1785 emitSUGType(i
->sType
);
1786 emitCachingMode(i
->cache
);
1789 srcId(i
->src(0), 20); // address
1791 if (i
->src(1).getFile() == FILE_GPR
)
1792 srcId(i
->src(1), 26);
1795 srcId(i
->src(3), 14); // values
1800 CodeEmitterNVC0::emitVectorSubOp(const Instruction
*i
)
1802 switch (NV50_IR_SUBOP_Vn(i
->subOp
)) {
1804 code
[1] |= (i
->subOp
& 0x000f) << 12; // vsrc1
1805 code
[1] |= (i
->subOp
& 0x00e0) >> 5; // vsrc2
1806 code
[1] |= (i
->subOp
& 0x0100) << 7; // vsrc2
1807 code
[1] |= (i
->subOp
& 0x3c00) << 13; // vdst
1810 code
[1] |= (i
->subOp
& 0x000f) << 8; // v2src1
1811 code
[1] |= (i
->subOp
& 0x0010) << 11; // v2src1
1812 code
[1] |= (i
->subOp
& 0x01e0) >> 1; // v2src2
1813 code
[1] |= (i
->subOp
& 0x0200) << 6; // v2src2
1814 code
[1] |= (i
->subOp
& 0x3c00) << 2; // v4dst
1815 code
[1] |= (i
->mask
& 0x3) << 2;
1818 code
[1] |= (i
->subOp
& 0x000f) << 8; // v4src1
1819 code
[1] |= (i
->subOp
& 0x01e0) >> 1; // v4src2
1820 code
[1] |= (i
->subOp
& 0x3c00) << 2; // v4dst
1821 code
[1] |= (i
->mask
& 0x3) << 2;
1822 code
[1] |= (i
->mask
& 0xc) << 21;
1831 CodeEmitterNVC0::emitVSHL(const Instruction
*i
)
1835 switch (NV50_IR_SUBOP_Vn(i
->subOp
)) {
1836 case 0: opc
|= 0xe8ULL
<< 56; break;
1837 case 1: opc
|= 0xb4ULL
<< 56; break;
1838 case 2: opc
|= 0x94ULL
<< 56; break;
1843 if (NV50_IR_SUBOP_Vn(i
->subOp
) == 1) {
1844 if (isSignedType(i
->dType
)) opc
|= 1ULL << 0x2a;
1845 if (isSignedType(i
->sType
)) opc
|= (1 << 6) | (1 << 5);
1847 if (isSignedType(i
->dType
)) opc
|= 1ULL << 0x39;
1848 if (isSignedType(i
->sType
)) opc
|= 1 << 6;
1855 if (i
->flagsDef
>= 0)
1860 CodeEmitterNVC0::emitInstruction(Instruction
*insn
)
1862 unsigned int size
= insn
->encSize
;
1864 if (writeIssueDelays
&& !(codeSize
& 0x3f))
1867 if (!insn
->encSize
) {
1868 ERROR("skipping unencodable instruction: "); insn
->print();
1871 if (codeSize
+ size
> codeSizeLimit
) {
1872 ERROR("code emitter output buffer too small\n");
1876 if (writeIssueDelays
) {
1877 if (!(codeSize
& 0x3f)) {
1878 code
[0] = 0x00000007; // cf issue delay "instruction"
1879 code
[1] = 0x20000000;
1883 const unsigned int id
= (codeSize
& 0x3f) / 8 - 1;
1884 uint32_t *data
= code
- (id
* 2 + 2);
1886 data
[0] |= insn
->sched
<< (id
* 8 + 4);
1889 data
[0] |= insn
->sched
<< 28;
1890 data
[1] |= insn
->sched
>> 4;
1892 data
[1] |= insn
->sched
<< ((id
- 4) * 8 + 4);
1896 // assert that instructions with multiple defs don't corrupt registers
1897 for (int d
= 0; insn
->defExists(d
); ++d
)
1898 assert(insn
->asTex() || insn
->def(d
).rep()->reg
.data
.id
>= 0);
1932 if (isFloatType(insn
->dType
))
1938 if (isFloatType(insn
->dType
))
1945 if (isFloatType(insn
->dType
))
1957 emitLogicOp(insn
, 0);
1960 emitLogicOp(insn
, 1);
1963 emitLogicOp(insn
, 2);
1973 emitSET(insn
->asCmp());
1979 emitSLCT(insn
->asCmp());
2021 emitTEX(insn
->asTex());
2024 emitTXQ(insn
->asTex());
2038 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
2039 emitSULDGB(insn
->asTex());
2041 ERROR("SULDB not yet supported on < nve4\n");
2045 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
2046 emitSUSTGx(insn
->asTex());
2048 ERROR("SUSTx not yet supported on < nve4\n");
2067 emitQUADOP(insn
, insn
->subOp
, insn
->lanes
);
2070 emitQUADOP(insn
, insn
->src(0).mod
.neg() ? 0x66 : 0x99, 0x4);
2073 emitQUADOP(insn
, insn
->src(0).mod
.neg() ? 0x5a : 0xa5, 0x5);
2088 ERROR("operation should have been eliminated");
2094 ERROR("operation should have been lowered\n");
2097 ERROR("unknow op\n");
2103 assert(insn
->encSize
== 8);
2106 code
+= insn
->encSize
/ 4;
2107 codeSize
+= insn
->encSize
;
2112 CodeEmitterNVC0::getMinEncodingSize(const Instruction
*i
) const
2114 const Target::OpInfo
&info
= targ
->getOpInfo(i
);
2116 if (writeIssueDelays
|| info
.minEncSize
== 8 || 1)
2119 if (i
->ftz
|| i
->saturate
|| i
->join
)
2121 if (i
->rnd
!= ROUND_N
)
2123 if (i
->predSrc
>= 0 && i
->op
== OP_MAD
)
2126 if (i
->op
== OP_PINTERP
) {
2127 if (i
->getSampleMode() || 1) // XXX: grr, short op doesn't work
2130 if (i
->op
== OP_MOV
&& i
->lanes
!= 0xf) {
2134 for (int s
= 0; i
->srcExists(s
); ++s
) {
2135 if (i
->src(s
).isIndirect(0))
2138 if (i
->src(s
).getFile() == FILE_MEMORY_CONST
) {
2139 if (SDATA(i
->src(s
)).offset
>= 0x100)
2141 if (i
->getSrc(s
)->reg
.fileIndex
> 1 &&
2142 i
->getSrc(s
)->reg
.fileIndex
!= 16)
2145 if (i
->src(s
).getFile() == FILE_IMMEDIATE
) {
2146 if (i
->dType
== TYPE_F32
) {
2147 if (SDATA(i
->src(s
)).u32
>= 0x100)
2150 if (SDATA(i
->src(s
)).u32
> 0xff)
2155 if (i
->op
== OP_CVT
)
2157 if (i
->src(s
).mod
!= Modifier(0)) {
2158 if (i
->src(s
).mod
== Modifier(NV50_IR_MOD_ABS
))
2159 if (i
->op
!= OP_RSQ
)
2161 if (i
->src(s
).mod
== Modifier(NV50_IR_MOD_NEG
))
2162 if (i
->op
!= OP_ADD
|| s
!= 0)
2170 // Simplified, erring on safe side.
2171 class SchedDataCalculator
: public Pass
2174 SchedDataCalculator(const Target
*targ
) : targ(targ
) { }
2180 int st
[DATA_FILE_COUNT
]; // LD to LD delay 3
2181 int ld
[DATA_FILE_COUNT
]; // ST to ST delay 3
2182 int tex
; // TEX to non-TEX delay 17 (0x11)
2183 int sfu
; // SFU to SFU delay 3 (except PRE-ops)
2184 int imul
; // integer MUL to MUL delay 3
2193 void rebase(const int base
)
2195 const int delta
= this->base
- base
;
2200 for (int i
= 0; i
< 64; ++i
) {
2204 for (int i
= 0; i
< 8; ++i
) {
2211 for (unsigned int f
= 0; f
< DATA_FILE_COUNT
; ++f
) {
2221 memset(&rd
, 0, sizeof(rd
));
2222 memset(&wr
, 0, sizeof(wr
));
2223 memset(&res
, 0, sizeof(res
));
2225 int getLatest(const ScoreData
& d
) const
2228 for (int i
= 0; i
< 64; ++i
)
2231 for (int i
= 0; i
< 8; ++i
)
2238 inline int getLatestRd() const
2240 return getLatest(rd
);
2242 inline int getLatestWr() const
2244 return getLatest(wr
);
2246 inline int getLatest() const
2248 const int a
= getLatestRd();
2249 const int b
= getLatestWr();
2251 int max
= MAX2(a
, b
);
2252 for (unsigned int f
= 0; f
< DATA_FILE_COUNT
; ++f
) {
2253 max
= MAX2(res
.ld
[f
], max
);
2254 max
= MAX2(res
.st
[f
], max
);
2256 max
= MAX2(res
.sfu
, max
);
2257 max
= MAX2(res
.imul
, max
);
2258 max
= MAX2(res
.tex
, max
);
2261 void setMax(const RegScores
*that
)
2263 for (int i
= 0; i
< 64; ++i
) {
2264 rd
.r
[i
] = MAX2(rd
.r
[i
], that
->rd
.r
[i
]);
2265 wr
.r
[i
] = MAX2(wr
.r
[i
], that
->wr
.r
[i
]);
2267 for (int i
= 0; i
< 8; ++i
) {
2268 rd
.p
[i
] = MAX2(rd
.p
[i
], that
->rd
.p
[i
]);
2269 wr
.p
[i
] = MAX2(wr
.p
[i
], that
->wr
.p
[i
]);
2271 rd
.c
= MAX2(rd
.c
, that
->rd
.c
);
2272 wr
.c
= MAX2(wr
.c
, that
->wr
.c
);
2274 for (unsigned int f
= 0; f
< DATA_FILE_COUNT
; ++f
) {
2275 res
.ld
[f
] = MAX2(res
.ld
[f
], that
->res
.ld
[f
]);
2276 res
.st
[f
] = MAX2(res
.st
[f
], that
->res
.st
[f
]);
2278 res
.sfu
= MAX2(res
.sfu
, that
->res
.sfu
);
2279 res
.imul
= MAX2(res
.imul
, that
->res
.imul
);
2280 res
.tex
= MAX2(res
.tex
, that
->res
.tex
);
2282 void print(int cycle
)
2284 for (int i
= 0; i
< 64; ++i
) {
2285 if (rd
.r
[i
] > cycle
)
2286 INFO("rd $r%i @ %i\n", i
, rd
.r
[i
]);
2287 if (wr
.r
[i
] > cycle
)
2288 INFO("wr $r%i @ %i\n", i
, wr
.r
[i
]);
2290 for (int i
= 0; i
< 8; ++i
) {
2291 if (rd
.p
[i
] > cycle
)
2292 INFO("rd $p%i @ %i\n", i
, rd
.p
[i
]);
2293 if (wr
.p
[i
] > cycle
)
2294 INFO("wr $p%i @ %i\n", i
, wr
.p
[i
]);
2297 INFO("rd $c @ %i\n", rd
.c
);
2299 INFO("wr $c @ %i\n", wr
.c
);
2300 if (res
.sfu
> cycle
)
2301 INFO("sfu @ %i\n", res
.sfu
);
2302 if (res
.imul
> cycle
)
2303 INFO("imul @ %i\n", res
.imul
);
2304 if (res
.tex
> cycle
)
2305 INFO("tex @ %i\n", res
.tex
);
2309 RegScores
*score
; // for current BB
2310 std::vector
<RegScores
> scoreBoards
;
2317 bool visit(Function
*);
2318 bool visit(BasicBlock
*);
2320 void commitInsn(const Instruction
*, int cycle
);
2321 int calcDelay(const Instruction
*, int cycle
) const;
2322 void setDelay(Instruction
*, int delay
, Instruction
*next
);
2324 void recordRd(const Value
*, const int ready
);
2325 void recordWr(const Value
*, const int ready
);
2326 void checkRd(const Value
*, int cycle
, int& delay
) const;
2327 void checkWr(const Value
*, int cycle
, int& delay
) const;
2329 int getCycles(const Instruction
*, int origDelay
) const;
2333 SchedDataCalculator::setDelay(Instruction
*insn
, int delay
, Instruction
*next
)
2335 if (insn
->op
== OP_EXIT
)
2336 delay
= MAX2(delay
, 14);
2338 if (insn
->op
== OP_TEXBAR
) {
2339 // TODO: except if results not used before EXIT
2342 if (insn
->op
== OP_JOIN
|| insn
->join
) {
2345 if (delay
>= 0 || prevData
== 0x04 ||
2346 !next
|| !targ
->canDualIssue(insn
, next
)) {
2347 insn
->sched
= static_cast<uint8_t>(MAX2(delay
, 0));
2348 if (prevOp
== OP_EXPORT
)
2349 insn
->sched
|= 0x40;
2351 insn
->sched
|= 0x20;
2353 insn
->sched
= 0x04; // dual-issue
2356 if (prevData
!= 0x04 || prevOp
!= OP_EXPORT
)
2357 if (insn
->sched
!= 0x04 || insn
->op
== OP_EXPORT
)
2360 prevData
= insn
->sched
;
2364 SchedDataCalculator::getCycles(const Instruction
*insn
, int origDelay
) const
2366 if (insn
->sched
& 0x80) {
2367 int c
= (insn
->sched
& 0x0f) * 2 + 1;
2368 if (insn
->op
== OP_TEXBAR
&& origDelay
> 0)
2372 if (insn
->sched
& 0x60)
2373 return (insn
->sched
& 0x1f) + 1;
2374 return (insn
->sched
== 0x04) ? 0 : 32;
2378 SchedDataCalculator::visit(Function
*func
)
2380 scoreBoards
.resize(func
->cfg
.getSize());
2381 for (size_t i
= 0; i
< scoreBoards
.size(); ++i
)
2382 scoreBoards
[i
].wipe();
2387 SchedDataCalculator::visit(BasicBlock
*bb
)
2390 Instruction
*next
= NULL
;
2396 score
= &scoreBoards
.at(bb
->getId());
2398 for (Graph::EdgeIterator ei
= bb
->cfg
.incident(); !ei
.end(); ei
.next()) {
2399 BasicBlock
*in
= BasicBlock::get(ei
.getNode());
2400 if (in
->getExit()) {
2401 if (prevData
!= 0x04)
2402 prevData
= in
->getExit()->sched
;
2403 prevOp
= in
->getExit()->op
;
2405 if (ei
.getType() != Graph::Edge::BACK
)
2406 score
->setMax(&scoreBoards
.at(in
->getId()));
2407 // back branches will wait until all target dependencies are satisfied
2409 if (bb
->cfg
.incidentCount() > 1)
2412 #ifdef NVC0_DEBUG_SCHED_DATA
2413 INFO("=== BB:%i initial scores\n", bb
->getId());
2414 score
->print(cycle
);
2417 for (insn
= bb
->getEntry(); insn
&& insn
->next
; insn
= insn
->next
) {
2420 commitInsn(insn
, cycle
);
2421 int delay
= calcDelay(next
, cycle
);
2422 setDelay(insn
, delay
, next
);
2423 cycle
+= getCycles(insn
, delay
);
2425 #ifdef NVC0_DEBUG_SCHED_DATA
2426 INFO("cycle %i, sched %02x\n", cycle
, insn
->sched
);
2433 commitInsn(insn
, cycle
);
2437 for (Graph::EdgeIterator ei
= bb
->cfg
.outgoing(); !ei
.end(); ei
.next()) {
2438 BasicBlock
*out
= BasicBlock::get(ei
.getNode());
2440 if (ei
.getType() != Graph::Edge::BACK
) {
2441 // only test the first instruction of the outgoing block
2442 next
= out
->getEntry();
2444 bbDelay
= MAX2(bbDelay
, calcDelay(next
, cycle
));
2446 // wait until all dependencies are satisfied
2447 const int regsFree
= score
->getLatest();
2448 next
= out
->getFirst();
2449 for (int c
= cycle
; next
&& c
< regsFree
; next
= next
->next
) {
2450 bbDelay
= MAX2(bbDelay
, calcDelay(next
, c
));
2451 c
+= getCycles(next
, bbDelay
);
2456 if (bb
->cfg
.outgoingCount() != 1)
2458 setDelay(insn
, bbDelay
, next
);
2459 cycle
+= getCycles(insn
, bbDelay
);
2461 score
->rebase(cycle
); // common base for initializing out blocks' scores
2465 #define NVE4_MAX_ISSUE_DELAY 0x1f
2467 SchedDataCalculator::calcDelay(const Instruction
*insn
, int cycle
) const
2469 int delay
= 0, ready
= cycle
;
2471 for (int s
= 0; insn
->srcExists(s
); ++s
)
2472 checkRd(insn
->getSrc(s
), cycle
, delay
);
2473 // WAR & WAW don't seem to matter
2474 // for (int s = 0; insn->srcExists(s); ++s)
2475 // recordRd(insn->getSrc(s), cycle);
2477 switch (Target::getOpClass(insn
->op
)) {
2479 ready
= score
->res
.sfu
;
2482 if (insn
->op
== OP_MUL
&& !isFloatType(insn
->dType
))
2483 ready
= score
->res
.imul
;
2485 case OPCLASS_TEXTURE
:
2486 ready
= score
->res
.tex
;
2489 ready
= score
->res
.ld
[insn
->src(0).getFile()];
2492 ready
= score
->res
.st
[insn
->src(0).getFile()];
2497 if (Target::getOpClass(insn
->op
) != OPCLASS_TEXTURE
)
2498 ready
= MAX2(ready
, score
->res
.tex
);
2500 delay
= MAX2(delay
, ready
- cycle
);
2502 // if can issue next cycle, delay is 0, not 1
2503 return MIN2(delay
- 1, NVE4_MAX_ISSUE_DELAY
);
2507 SchedDataCalculator::commitInsn(const Instruction
*insn
, int cycle
)
2509 const int ready
= cycle
+ targ
->getLatency(insn
);
2511 for (int d
= 0; insn
->defExists(d
); ++d
)
2512 recordWr(insn
->getDef(d
), ready
);
2513 // WAR & WAW don't seem to matter
2514 // for (int s = 0; insn->srcExists(s); ++s)
2515 // recordRd(insn->getSrc(s), cycle);
2517 switch (Target::getOpClass(insn
->op
)) {
2519 score
->res
.sfu
= cycle
+ 4;
2522 if (insn
->op
== OP_MUL
&& !isFloatType(insn
->dType
))
2523 score
->res
.imul
= cycle
+ 4;
2525 case OPCLASS_TEXTURE
:
2526 score
->res
.tex
= cycle
+ 18;
2529 if (insn
->src(0).getFile() == FILE_MEMORY_CONST
)
2531 score
->res
.ld
[insn
->src(0).getFile()] = cycle
+ 4;
2532 score
->res
.st
[insn
->src(0).getFile()] = ready
;
2535 score
->res
.st
[insn
->src(0).getFile()] = cycle
+ 4;
2536 score
->res
.ld
[insn
->src(0).getFile()] = ready
;
2539 if (insn
->op
== OP_TEXBAR
)
2540 score
->res
.tex
= cycle
;
2546 #ifdef NVC0_DEBUG_SCHED_DATA
2547 score
->print(cycle
);
2552 SchedDataCalculator::checkRd(const Value
*v
, int cycle
, int& delay
) const
2557 switch (v
->reg
.file
) {
2560 b
= a
+ v
->reg
.size
/ 4;
2561 for (int r
= a
; r
< b
; ++r
)
2562 ready
= MAX2(ready
, score
->rd
.r
[r
]);
2564 case FILE_PREDICATE
:
2565 ready
= MAX2(ready
, score
->rd
.p
[v
->reg
.data
.id
]);
2568 ready
= MAX2(ready
, score
->rd
.c
);
2570 case FILE_SHADER_INPUT
:
2571 case FILE_SHADER_OUTPUT
: // yes, TCPs can read outputs
2572 case FILE_MEMORY_LOCAL
:
2573 case FILE_MEMORY_CONST
:
2574 case FILE_MEMORY_SHARED
:
2575 case FILE_MEMORY_GLOBAL
:
2576 case FILE_SYSTEM_VALUE
:
2577 // TODO: any restrictions here ?
2579 case FILE_IMMEDIATE
:
2586 delay
= MAX2(delay
, ready
- cycle
);
2590 SchedDataCalculator::checkWr(const Value
*v
, int cycle
, int& delay
) const
2595 switch (v
->reg
.file
) {
2598 b
= a
+ v
->reg
.size
/ 4;
2599 for (int r
= a
; r
< b
; ++r
)
2600 ready
= MAX2(ready
, score
->wr
.r
[r
]);
2602 case FILE_PREDICATE
:
2603 ready
= MAX2(ready
, score
->wr
.p
[v
->reg
.data
.id
]);
2606 assert(v
->reg
.file
== FILE_FLAGS
);
2607 ready
= MAX2(ready
, score
->wr
.c
);
2611 delay
= MAX2(delay
, ready
- cycle
);
2615 SchedDataCalculator::recordWr(const Value
*v
, const int ready
)
2617 int a
= v
->reg
.data
.id
;
2619 if (v
->reg
.file
== FILE_GPR
) {
2620 int b
= a
+ v
->reg
.size
/ 4;
2621 for (int r
= a
; r
< b
; ++r
)
2622 score
->rd
.r
[r
] = ready
;
2624 // $c, $pX: shorter issue-to-read delay (at least as exec pred and carry)
2625 if (v
->reg
.file
== FILE_PREDICATE
) {
2626 score
->rd
.p
[a
] = ready
+ 4;
2628 assert(v
->reg
.file
== FILE_FLAGS
);
2629 score
->rd
.c
= ready
+ 4;
2634 SchedDataCalculator::recordRd(const Value
*v
, const int ready
)
2636 int a
= v
->reg
.data
.id
;
2638 if (v
->reg
.file
== FILE_GPR
) {
2639 int b
= a
+ v
->reg
.size
/ 4;
2640 for (int r
= a
; r
< b
; ++r
)
2641 score
->wr
.r
[r
] = ready
;
2643 if (v
->reg
.file
== FILE_PREDICATE
) {
2644 score
->wr
.p
[a
] = ready
;
2646 if (v
->reg
.file
== FILE_FLAGS
) {
2647 score
->wr
.c
= ready
;
2652 calculateSchedDataNVC0(const Target
*targ
, Function
*func
)
2654 SchedDataCalculator
sched(targ
);
2655 return sched
.run(func
, true, true);
2659 CodeEmitterNVC0::prepareEmission(Function
*func
)
2661 CodeEmitter::prepareEmission(func
);
2663 if (targ
->hasSWSched
)
2664 calculateSchedDataNVC0(targ
, func
);
2667 CodeEmitterNVC0::CodeEmitterNVC0(const TargetNVC0
*target
)
2668 : CodeEmitter(target
),
2670 writeIssueDelays(target
->hasSWSched
)
2673 codeSize
= codeSizeLimit
= 0;
2678 TargetNVC0::createCodeEmitterNVC0(Program::Type type
)
2680 CodeEmitterNVC0
*emit
= new CodeEmitterNVC0(this);
2681 emit
->setProgramType(type
);
2686 TargetNVC0::getCodeEmitter(Program::Type type
)
2688 if (chipset
>= NVISA_GK110_CHIPSET
)
2689 return createCodeEmitterGK110(type
);
2690 return createCodeEmitterNVC0(type
);
2693 } // namespace nv50_ir