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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include "codegen/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 setAddress24(const ValueRef
&);
56 void setAddressByFile(const ValueRef
&);
57 void setImmediate(const Instruction
*, const int s
); // needs op already set
58 void setImmediateS8(const ValueRef
&);
59 void setSUConst16(const Instruction
*, const int s
);
60 void setSUPred(const Instruction
*, const int s
);
61 void setPDSTL(const Instruction
*, const int d
);
63 void emitCondCode(CondCode cc
, int pos
);
64 void emitInterpMode(const Instruction
*);
65 void emitLoadStoreType(DataType ty
);
66 void emitSUGType(DataType
);
67 void emitSUAddr(const TexInstruction
*);
68 void emitSUDim(const TexInstruction
*);
69 void emitCachingMode(CacheMode c
);
71 void emitShortSrc2(const ValueRef
&);
73 inline uint8_t getSRegEncoding(const ValueRef
&);
75 void roundMode_A(const Instruction
*);
76 void roundMode_C(const Instruction
*);
77 void roundMode_CS(const Instruction
*);
79 void emitNegAbs12(const Instruction
*);
81 void emitNOP(const Instruction
*);
83 void emitLOAD(const Instruction
*);
84 void emitSTORE(const Instruction
*);
85 void emitMOV(const Instruction
*);
86 void emitATOM(const Instruction
*);
87 void emitMEMBAR(const Instruction
*);
88 void emitCCTL(const Instruction
*);
90 void emitINTERP(const Instruction
*);
91 void emitAFETCH(const Instruction
*);
92 void emitPFETCH(const Instruction
*);
93 void emitVFETCH(const Instruction
*);
94 void emitEXPORT(const Instruction
*);
95 void emitOUT(const Instruction
*);
97 void emitUADD(const Instruction
*);
98 void emitFADD(const Instruction
*);
99 void emitDADD(const Instruction
*);
100 void emitUMUL(const Instruction
*);
101 void emitFMUL(const Instruction
*);
102 void emitDMUL(const Instruction
*);
103 void emitIMAD(const Instruction
*);
104 void emitISAD(const Instruction
*);
105 void emitSHLADD(const Instruction
*a
);
106 void emitFMAD(const Instruction
*);
107 void emitDMAD(const Instruction
*);
108 void emitMADSP(const Instruction
*);
110 void emitNOT(Instruction
*);
111 void emitLogicOp(const Instruction
*, uint8_t subOp
);
112 void emitPOPC(const Instruction
*);
113 void emitINSBF(const Instruction
*);
114 void emitEXTBF(const Instruction
*);
115 void emitBFIND(const Instruction
*);
116 void emitPERMT(const Instruction
*);
117 void emitShift(const Instruction
*);
119 void emitSFnOp(const Instruction
*, uint8_t subOp
);
121 void emitCVT(Instruction
*);
122 void emitMINMAX(const Instruction
*);
123 void emitPreOp(const Instruction
*);
125 void emitSET(const CmpInstruction
*);
126 void emitSLCT(const CmpInstruction
*);
127 void emitSELP(const Instruction
*);
129 void emitTEXBAR(const Instruction
*);
130 void emitTEX(const TexInstruction
*);
131 void emitTEXCSAA(const TexInstruction
*);
132 void emitTXQ(const TexInstruction
*);
134 void emitQUADOP(const Instruction
*, uint8_t qOp
, uint8_t laneMask
);
136 void emitFlow(const Instruction
*);
137 void emitBAR(const Instruction
*);
139 void emitSUCLAMPMode(uint16_t);
140 void emitSUCalc(Instruction
*);
141 void emitSULDGB(const TexInstruction
*);
142 void emitSUSTGx(const TexInstruction
*);
144 void emitSULDB(const TexInstruction
*);
145 void emitSUSTx(const TexInstruction
*);
146 void emitSULEA(const TexInstruction
*);
148 void emitVSHL(const Instruction
*);
149 void emitVectorSubOp(const Instruction
*);
151 void emitPIXLD(const Instruction
*);
153 void emitSHFL(const Instruction
*);
155 void emitVOTE(const Instruction
*);
157 inline void defId(const ValueDef
&, const int pos
);
158 inline void defId(const Instruction
*, int d
, const int pos
);
159 inline void srcId(const ValueRef
&, const int pos
);
160 inline void srcId(const ValueRef
*, const int pos
);
161 inline void srcId(const Instruction
*, int s
, const int pos
);
162 inline void srcAddr32(const ValueRef
&, int pos
, int shr
);
164 inline bool isLIMM(const ValueRef
&, DataType ty
);
167 // for better visibility
168 #define HEX64(h, l) 0x##h##l##ULL
170 #define SDATA(a) ((a).rep()->reg.data)
171 #define DDATA(a) ((a).rep()->reg.data)
173 void CodeEmitterNVC0::srcId(const ValueRef
& src
, const int pos
)
175 code
[pos
/ 32] |= (src
.get() ? SDATA(src
).id
: 63) << (pos
% 32);
178 void CodeEmitterNVC0::srcId(const ValueRef
*src
, const int pos
)
180 code
[pos
/ 32] |= (src
? SDATA(*src
).id
: 63) << (pos
% 32);
183 void CodeEmitterNVC0::srcId(const Instruction
*insn
, int s
, int pos
)
185 int r
= insn
->srcExists(s
) ? SDATA(insn
->src(s
)).id
: 63;
186 code
[pos
/ 32] |= r
<< (pos
% 32);
190 CodeEmitterNVC0::srcAddr32(const ValueRef
& src
, int pos
, int shr
)
192 const uint32_t offset
= SDATA(src
).offset
>> shr
;
194 code
[pos
/ 32] |= offset
<< (pos
% 32);
195 if (pos
&& (pos
< 32))
196 code
[1] |= offset
>> (32 - pos
);
199 void CodeEmitterNVC0::defId(const ValueDef
& def
, const int pos
)
201 code
[pos
/ 32] |= (def
.get() && def
.getFile() != FILE_FLAGS
? DDATA(def
).id
: 63) << (pos
% 32);
204 void CodeEmitterNVC0::defId(const Instruction
*insn
, int d
, const int pos
)
206 if (insn
->defExists(d
))
207 defId(insn
->def(d
), pos
);
209 code
[pos
/ 32] |= 63 << (pos
% 32);
212 bool CodeEmitterNVC0::isLIMM(const ValueRef
& ref
, DataType ty
)
214 const ImmediateValue
*imm
= ref
.get()->asImm();
217 return imm
&& imm
->reg
.data
.u32
& 0xfff;
219 return imm
&& (imm
->reg
.data
.s32
> 0x7ffff ||
220 imm
->reg
.data
.s32
< -0x80000);
224 CodeEmitterNVC0::roundMode_A(const Instruction
*insn
)
227 case ROUND_M
: code
[1] |= 1 << 23; break;
228 case ROUND_P
: code
[1] |= 2 << 23; break;
229 case ROUND_Z
: code
[1] |= 3 << 23; break;
231 assert(insn
->rnd
== ROUND_N
);
237 CodeEmitterNVC0::emitNegAbs12(const Instruction
*i
)
239 if (i
->src(1).mod
.abs()) code
[0] |= 1 << 6;
240 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 7;
241 if (i
->src(1).mod
.neg()) code
[0] |= 1 << 8;
242 if (i
->src(0).mod
.neg()) code
[0] |= 1 << 9;
245 void CodeEmitterNVC0::emitCondCode(CondCode cc
, int pos
)
250 case CC_LT
: val
= 0x1; break;
251 case CC_LTU
: val
= 0x9; break;
252 case CC_EQ
: val
= 0x2; break;
253 case CC_EQU
: val
= 0xa; break;
254 case CC_LE
: val
= 0x3; break;
255 case CC_LEU
: val
= 0xb; break;
256 case CC_GT
: val
= 0x4; break;
257 case CC_GTU
: val
= 0xc; break;
258 case CC_NE
: val
= 0x5; break;
259 case CC_NEU
: val
= 0xd; break;
260 case CC_GE
: val
= 0x6; break;
261 case CC_GEU
: val
= 0xe; break;
262 case CC_TR
: val
= 0xf; break;
263 case CC_FL
: val
= 0x0; break;
265 case CC_A
: val
= 0x14; break;
266 case CC_NA
: val
= 0x13; break;
267 case CC_S
: val
= 0x15; break;
268 case CC_NS
: val
= 0x12; break;
269 case CC_C
: val
= 0x16; break;
270 case CC_NC
: val
= 0x11; break;
271 case CC_O
: val
= 0x17; break;
272 case CC_NO
: val
= 0x10; break;
276 assert(!"invalid condition code");
279 code
[pos
/ 32] |= val
<< (pos
% 32);
283 CodeEmitterNVC0::emitPredicate(const Instruction
*i
)
285 if (i
->predSrc
>= 0) {
286 assert(i
->getPredicate()->reg
.file
== FILE_PREDICATE
);
287 srcId(i
->src(i
->predSrc
), 10);
288 if (i
->cc
== CC_NOT_P
)
289 code
[0] |= 0x2000; // negate
296 CodeEmitterNVC0::setAddressByFile(const ValueRef
& src
)
298 switch (src
.getFile()) {
299 case FILE_MEMORY_GLOBAL
:
300 srcAddr32(src
, 26, 0);
302 case FILE_MEMORY_LOCAL
:
303 case FILE_MEMORY_SHARED
:
307 assert(src
.getFile() == FILE_MEMORY_CONST
);
314 CodeEmitterNVC0::setAddress16(const ValueRef
& src
)
316 Symbol
*sym
= src
.get()->asSym();
320 code
[0] |= (sym
->reg
.data
.offset
& 0x003f) << 26;
321 code
[1] |= (sym
->reg
.data
.offset
& 0xffc0) >> 6;
325 CodeEmitterNVC0::setAddress24(const ValueRef
& src
)
327 Symbol
*sym
= src
.get()->asSym();
331 code
[0] |= (sym
->reg
.data
.offset
& 0x00003f) << 26;
332 code
[1] |= (sym
->reg
.data
.offset
& 0xffffc0) >> 6;
336 CodeEmitterNVC0::setImmediate(const Instruction
*i
, const int s
)
338 const ImmediateValue
*imm
= i
->src(s
).get()->asImm();
342 u32
= imm
->reg
.data
.u32
;
344 if ((code
[0] & 0xf) == 0x1) {
346 uint64_t u64
= imm
->reg
.data
.u64
;
347 assert(!(u64
& 0x00000fffffffffffULL
));
348 assert(!(code
[1] & 0xc000));
349 code
[0] |= ((u64
>> 44) & 0x3f) << 26;
350 code
[1] |= 0xc000 | (u64
>> 50);
352 if ((code
[0] & 0xf) == 0x2) {
354 code
[0] |= (u32
& 0x3f) << 26;
357 if ((code
[0] & 0xf) == 0x3 || (code
[0] & 0xf) == 4) {
359 assert((u32
& 0xfff80000) == 0 || (u32
& 0xfff80000) == 0xfff80000);
360 assert(!(code
[1] & 0xc000));
362 code
[0] |= (u32
& 0x3f) << 26;
363 code
[1] |= 0xc000 | (u32
>> 6);
366 assert(!(u32
& 0x00000fff));
367 assert(!(code
[1] & 0xc000));
368 code
[0] |= ((u32
>> 12) & 0x3f) << 26;
369 code
[1] |= 0xc000 | (u32
>> 18);
373 void CodeEmitterNVC0::setImmediateS8(const ValueRef
&ref
)
375 const ImmediateValue
*imm
= ref
.get()->asImm();
377 int8_t s8
= static_cast<int8_t>(imm
->reg
.data
.s32
);
379 assert(s8
== imm
->reg
.data
.s32
);
381 code
[0] |= (s8
& 0x3f) << 26;
382 code
[0] |= (s8
>> 6) << 8;
385 void CodeEmitterNVC0::setPDSTL(const Instruction
*i
, const int d
)
387 assert(d
< 0 || (i
->defExists(d
) && i
->def(d
).getFile() == FILE_PREDICATE
));
389 uint32_t pred
= d
>= 0 ? DDATA(i
->def(d
)).id
: 7;
391 code
[0] |= (pred
& 3) << 8;
392 code
[1] |= (pred
& 4) << (26 - 2);
396 CodeEmitterNVC0::emitForm_A(const Instruction
*i
, uint64_t opc
)
403 defId(i
->def(0), 14);
406 if (i
->srcExists(2) && i
->getSrc(2)->reg
.file
== FILE_MEMORY_CONST
)
409 for (int s
= 0; s
< 3 && i
->srcExists(s
); ++s
) {
410 switch (i
->getSrc(s
)->reg
.file
) {
411 case FILE_MEMORY_CONST
:
412 assert(!(code
[1] & 0xc000));
413 code
[1] |= (s
== 2) ? 0x8000 : 0x4000;
414 code
[1] |= i
->getSrc(s
)->reg
.fileIndex
<< 10;
415 setAddress16(i
->src(s
));
419 i
->op
== OP_MOV
|| i
->op
== OP_PRESIN
|| i
->op
== OP_PREEX2
);
420 assert(!(code
[1] & 0xc000));
424 if ((s
== 2) && ((code
[0] & 0x7) == 2)) // LIMM: 3rd src == dst
426 srcId(i
->src(s
), s
? ((s
== 2) ? 49 : s1
) : 20);
429 if (i
->op
== OP_SELP
) {
430 // OP_SELP is used to implement shared+atomics on Fermi.
431 assert(s
== 2 && i
->src(s
).getFile() == FILE_PREDICATE
);
432 srcId(i
->src(s
), 49);
434 // ignore here, can be predicate or flags, but must not be address
441 CodeEmitterNVC0::emitForm_B(const Instruction
*i
, uint64_t opc
)
448 defId(i
->def(0), 14);
450 switch (i
->src(0).getFile()) {
451 case FILE_MEMORY_CONST
:
452 assert(!(code
[1] & 0xc000));
453 code
[1] |= 0x4000 | (i
->src(0).get()->reg
.fileIndex
<< 10);
454 setAddress16(i
->src(0));
457 assert(!(code
[1] & 0xc000));
461 srcId(i
->src(0), 26);
464 // ignore here, can be predicate or flags, but must not be address
470 CodeEmitterNVC0::emitForm_S(const Instruction
*i
, uint32_t opc
, bool pred
)
475 if (opc
== 0x0d || opc
== 0x0e)
478 defId(i
->def(0), 14);
479 srcId(i
->src(0), 20);
481 assert(pred
|| (i
->predSrc
< 0));
485 for (int s
= 1; s
< 3 && i
->srcExists(s
); ++s
) {
486 if (i
->src(s
).get()->reg
.file
== FILE_MEMORY_CONST
) {
487 assert(!(code
[0] & (0x300 >> ss2a
)));
488 switch (i
->src(s
).get()->reg
.fileIndex
) {
489 case 0: code
[0] |= 0x100 >> ss2a
; break;
490 case 1: code
[0] |= 0x200 >> ss2a
; break;
491 case 16: code
[0] |= 0x300 >> ss2a
; break;
493 ERROR("invalid c[] space for short form\n");
497 code
[0] |= i
->getSrc(s
)->reg
.data
.offset
<< 24;
499 code
[0] |= i
->getSrc(s
)->reg
.data
.offset
<< 6;
501 if (i
->src(s
).getFile() == FILE_IMMEDIATE
) {
503 setImmediateS8(i
->src(s
));
505 if (i
->src(s
).getFile() == FILE_GPR
) {
506 srcId(i
->src(s
), (s
== 1) ? 26 : 8);
512 CodeEmitterNVC0::emitShortSrc2(const ValueRef
&src
)
514 if (src
.getFile() == FILE_MEMORY_CONST
) {
515 switch (src
.get()->reg
.fileIndex
) {
516 case 0: code
[0] |= 0x100; break;
517 case 1: code
[0] |= 0x200; break;
518 case 16: code
[0] |= 0x300; break;
520 assert(!"unsupported file index for short op");
523 srcAddr32(src
, 20, 2);
526 assert(src
.getFile() == FILE_GPR
);
531 CodeEmitterNVC0::emitNOP(const Instruction
*i
)
533 code
[0] = 0x000001e4;
534 code
[1] = 0x40000000;
539 CodeEmitterNVC0::emitFMAD(const Instruction
*i
)
541 bool neg1
= (i
->src(0).mod
^ i
->src(1).mod
).neg();
543 if (i
->encSize
== 8) {
544 if (isLIMM(i
->src(1), TYPE_F32
)) {
545 emitForm_A(i
, HEX64(20000000, 00000002));
547 emitForm_A(i
, HEX64(30000000, 00000000));
549 if (i
->src(2).mod
.neg())
566 assert(!i
->saturate
&& !i
->src(2).mod
.neg());
567 emitForm_S(i
, (i
->src(2).getFile() == FILE_MEMORY_CONST
) ? 0x2e : 0x0e,
575 CodeEmitterNVC0::emitDMAD(const Instruction
*i
)
577 bool neg1
= (i
->src(0).mod
^ i
->src(1).mod
).neg();
579 emitForm_A(i
, HEX64(20000000, 00000001));
581 if (i
->src(2).mod
.neg())
589 assert(!i
->saturate
);
594 CodeEmitterNVC0::emitFMUL(const Instruction
*i
)
596 bool neg
= (i
->src(0).mod
^ i
->src(1).mod
).neg();
598 assert(i
->postFactor
>= -3 && i
->postFactor
<= 3);
600 if (i
->encSize
== 8) {
601 if (isLIMM(i
->src(1), TYPE_F32
)) {
602 assert(i
->postFactor
== 0); // constant folded, hopefully
603 emitForm_A(i
, HEX64(30000000, 00000002));
605 emitForm_A(i
, HEX64(58000000, 00000000));
607 code
[1] |= ((i
->postFactor
> 0) ?
608 (7 - i
->postFactor
) : (0 - i
->postFactor
)) << 17;
611 code
[1] ^= 1 << 25; // aliases with LIMM sign bit
622 assert(!neg
&& !i
->saturate
&& !i
->ftz
&& !i
->postFactor
);
623 emitForm_S(i
, 0xa8, true);
628 CodeEmitterNVC0::emitDMUL(const Instruction
*i
)
630 bool neg
= (i
->src(0).mod
^ i
->src(1).mod
).neg();
632 emitForm_A(i
, HEX64(50000000, 00000001));
638 assert(!i
->saturate
);
641 assert(!i
->postFactor
);
645 CodeEmitterNVC0::emitUMUL(const Instruction
*i
)
647 if (i
->encSize
== 8) {
648 if (isLIMM(i
->src(1), TYPE_U32
)) {
649 emitForm_A(i
, HEX64(10000000, 00000002));
651 emitForm_A(i
, HEX64(50000000, 00000003));
653 if (i
->subOp
== NV50_IR_SUBOP_MUL_HIGH
)
655 if (i
->sType
== TYPE_S32
)
657 if (i
->dType
== TYPE_S32
)
660 emitForm_S(i
, i
->src(1).getFile() == FILE_IMMEDIATE
? 0xaa : 0x2a, true);
662 if (i
->sType
== TYPE_S32
)
668 CodeEmitterNVC0::emitFADD(const Instruction
*i
)
670 if (i
->encSize
== 8) {
671 if (isLIMM(i
->src(1), TYPE_F32
)) {
672 assert(!i
->saturate
);
673 emitForm_A(i
, HEX64(28000000, 00000002));
675 code
[0] |= i
->src(0).mod
.abs() << 7;
676 code
[0] |= i
->src(0).mod
.neg() << 9;
678 if (i
->src(1).mod
.abs())
679 code
[1] &= 0xfdffffff;
680 if ((i
->op
== OP_SUB
) != static_cast<bool>(i
->src(1).mod
.neg()))
681 code
[1] ^= 0x02000000;
683 emitForm_A(i
, HEX64(50000000, 00000000));
690 if (i
->op
== OP_SUB
) code
[0] ^= 1 << 8;
695 assert(!i
->saturate
&& i
->op
!= OP_SUB
&&
696 !i
->src(0).mod
.abs() &&
697 !i
->src(1).mod
.neg() && !i
->src(1).mod
.abs());
699 emitForm_S(i
, 0x49, true);
701 if (i
->src(0).mod
.neg())
707 CodeEmitterNVC0::emitDADD(const Instruction
*i
)
709 assert(i
->encSize
== 8);
710 emitForm_A(i
, HEX64(48000000, 00000001));
712 assert(!i
->saturate
);
720 CodeEmitterNVC0::emitUADD(const Instruction
*i
)
724 assert(!i
->src(0).mod
.abs() && !i
->src(1).mod
.abs());
726 if (i
->src(0).mod
.neg())
728 if (i
->src(1).mod
.neg())
733 assert(addOp
!= 0x300); // would be add-plus-one
735 if (i
->encSize
== 8) {
736 if (isLIMM(i
->src(1), TYPE_U32
)) {
737 emitForm_A(i
, HEX64(08000000, 00000002));
738 if (i
->flagsDef
>= 0)
739 code
[1] |= 1 << 26; // write carry
741 emitForm_A(i
, HEX64(48000000, 00000003));
742 if (i
->flagsDef
>= 0)
743 code
[1] |= 1 << 16; // write carry
749 if (i
->flagsSrc
>= 0) // add carry
752 assert(!(addOp
& 0x100));
753 emitForm_S(i
, (addOp
>> 3) |
754 ((i
->src(1).getFile() == FILE_IMMEDIATE
) ? 0xac : 0x2c), true);
759 CodeEmitterNVC0::emitIMAD(const Instruction
*i
)
762 i
->src(2).mod
.neg() | ((i
->src(0).mod
.neg() ^ i
->src(1).mod
.neg()) << 1);
764 assert(i
->encSize
== 8);
765 emitForm_A(i
, HEX64(20000000, 00000003));
768 code
[0] |= addOp
<< 8;
770 if (isSignedType(i
->dType
))
772 if (isSignedType(i
->sType
))
775 code
[1] |= i
->saturate
<< 24;
777 if (i
->flagsDef
>= 0) code
[1] |= 1 << 16;
778 if (i
->flagsSrc
>= 0) code
[1] |= 1 << 23;
780 if (i
->subOp
== NV50_IR_SUBOP_MUL_HIGH
)
785 CodeEmitterNVC0::emitSHLADD(const Instruction
*i
)
787 uint8_t addOp
= (i
->src(0).mod
.neg() << 1) | i
->src(2).mod
.neg();
788 const ImmediateValue
*imm
= i
->src(1).get()->asImm();
791 code
[0] = 0x00000003;
792 code
[1] = 0x40000000 | addOp
<< 23;
796 defId(i
->def(0), 14);
797 srcId(i
->src(0), 20);
799 if (i
->flagsDef
>= 0)
802 assert(!(imm
->reg
.data
.u32
& 0xffffffe0));
803 code
[0] |= imm
->reg
.data
.u32
<< 5;
805 switch (i
->src(2).getFile()) {
807 srcId(i
->src(2), 26);
809 case FILE_MEMORY_CONST
:
811 code
[1] |= i
->getSrc(2)->reg
.fileIndex
<< 10;
812 setAddress16(i
->src(2));
818 assert(!"bad src2 file");
824 CodeEmitterNVC0::emitMADSP(const Instruction
*i
)
826 assert(targ
->getChipset() >= NVISA_GK104_CHIPSET
);
828 emitForm_A(i
, HEX64(00000000, 00000003));
830 if (i
->subOp
== NV50_IR_SUBOP_MADSP_SD
) {
831 code
[1] |= 0x01800000;
833 code
[0] |= (i
->subOp
& 0x00f) << 7;
834 code
[0] |= (i
->subOp
& 0x0f0) << 1;
835 code
[0] |= (i
->subOp
& 0x100) >> 3;
836 code
[0] |= (i
->subOp
& 0x200) >> 2;
837 code
[1] |= (i
->subOp
& 0xc00) << 13;
840 if (i
->flagsDef
>= 0)
845 CodeEmitterNVC0::emitISAD(const Instruction
*i
)
847 assert(i
->dType
== TYPE_S32
|| i
->dType
== TYPE_U32
);
848 assert(i
->encSize
== 8);
850 emitForm_A(i
, HEX64(38000000, 00000003));
852 if (i
->dType
== TYPE_S32
)
857 CodeEmitterNVC0::emitNOT(Instruction
*i
)
859 assert(i
->encSize
== 8);
860 if (i
->getPredicate())
861 i
->moveSources(1, 1);
862 i
->setSrc(1, i
->src(0));
863 emitForm_A(i
, HEX64(68000000, 000001c3
));
867 CodeEmitterNVC0::emitLogicOp(const Instruction
*i
, uint8_t subOp
)
869 if (i
->def(0).getFile() == FILE_PREDICATE
) {
870 code
[0] = 0x00000004 | (subOp
<< 30);
871 code
[1] = 0x0c000000;
875 defId(i
->def(0), 17);
876 srcId(i
->src(0), 20);
877 if (i
->src(0).mod
== Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 23;
878 srcId(i
->src(1), 26);
879 if (i
->src(1).mod
== Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 29;
881 if (i
->defExists(1)) {
882 defId(i
->def(1), 14);
887 if (i
->predSrc
!= 2 && i
->srcExists(2)) {
888 code
[1] |= subOp
<< 21;
889 srcId(i
->src(2), 49);
890 if (i
->src(2).mod
== Modifier(NV50_IR_MOD_NOT
)) code
[1] |= 1 << 20;
892 code
[1] |= 0x000e0000;
895 if (i
->encSize
== 8) {
896 if (isLIMM(i
->src(1), TYPE_U32
)) {
897 emitForm_A(i
, HEX64(38000000, 00000002));
899 if (i
->flagsDef
>= 0)
902 emitForm_A(i
, HEX64(68000000, 00000003));
904 if (i
->flagsDef
>= 0)
907 code
[0] |= subOp
<< 6;
909 if (i
->flagsSrc
>= 0) // carry
912 if (i
->src(0).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 9;
913 if (i
->src(1).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 8;
915 emitForm_S(i
, (subOp
<< 5) |
916 ((i
->src(1).getFile() == FILE_IMMEDIATE
) ? 0x1d : 0x8d), true);
921 CodeEmitterNVC0::emitPOPC(const Instruction
*i
)
923 emitForm_A(i
, HEX64(54000000, 00000004));
925 if (i
->src(0).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 9;
926 if (i
->src(1).mod
& Modifier(NV50_IR_MOD_NOT
)) code
[0] |= 1 << 8;
930 CodeEmitterNVC0::emitINSBF(const Instruction
*i
)
932 emitForm_A(i
, HEX64(28000000, 00000003));
936 CodeEmitterNVC0::emitEXTBF(const Instruction
*i
)
938 emitForm_A(i
, HEX64(70000000, 00000003));
940 if (i
->dType
== TYPE_S32
)
942 if (i
->subOp
== NV50_IR_SUBOP_EXTBF_REV
)
947 CodeEmitterNVC0::emitBFIND(const Instruction
*i
)
949 emitForm_B(i
, HEX64(78000000, 00000003));
951 if (i
->dType
== TYPE_S32
)
953 if (i
->src(0).mod
== Modifier(NV50_IR_MOD_NOT
))
955 if (i
->subOp
== NV50_IR_SUBOP_BFIND_SAMT
)
960 CodeEmitterNVC0::emitPERMT(const Instruction
*i
)
962 emitForm_A(i
, HEX64(24000000, 00000004));
964 code
[0] |= i
->subOp
<< 5;
968 CodeEmitterNVC0::emitShift(const Instruction
*i
)
970 if (i
->op
== OP_SHR
) {
971 emitForm_A(i
, HEX64(58000000, 00000003)
972 | (isSignedType(i
->dType
) ? 0x20 : 0x00));
974 emitForm_A(i
, HEX64(60000000, 00000003));
977 if (i
->subOp
== NV50_IR_SUBOP_SHIFT_WRAP
)
982 CodeEmitterNVC0::emitPreOp(const Instruction
*i
)
984 if (i
->encSize
== 8) {
985 emitForm_B(i
, HEX64(60000000, 00000000));
987 if (i
->op
== OP_PREEX2
)
990 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 6;
991 if (i
->src(0).mod
.neg()) code
[0] |= 1 << 8;
993 emitForm_S(i
, i
->op
== OP_PREEX2
? 0x74000008 : 0x70000008, true);
998 CodeEmitterNVC0::emitSFnOp(const Instruction
*i
, uint8_t subOp
)
1000 if (i
->encSize
== 8) {
1001 code
[0] = 0x00000000 | (subOp
<< 26);
1002 code
[1] = 0xc8000000;
1006 defId(i
->def(0), 14);
1007 srcId(i
->src(0), 20);
1009 assert(i
->src(0).getFile() == FILE_GPR
);
1011 if (i
->saturate
) code
[0] |= 1 << 5;
1013 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 7;
1014 if (i
->src(0).mod
.neg()) code
[0] |= 1 << 9;
1016 emitForm_S(i
, 0x80000008 | (subOp
<< 26), true);
1018 assert(!i
->src(0).mod
.neg());
1019 if (i
->src(0).mod
.abs()) code
[0] |= 1 << 30;
1024 CodeEmitterNVC0::emitMINMAX(const Instruction
*i
)
1028 assert(i
->encSize
== 8);
1030 op
= (i
->op
== OP_MIN
) ? 0x080e000000000000ULL
: 0x081e000000000000ULL
;
1035 if (!isFloatType(i
->dType
)) {
1036 op
|= isSignedType(i
->dType
) ? 0x23 : 0x03;
1037 op
|= i
->subOp
<< 6;
1039 if (i
->dType
== TYPE_F64
)
1045 if (i
->flagsDef
>= 0)
1050 CodeEmitterNVC0::roundMode_C(const Instruction
*i
)
1053 case ROUND_M
: code
[1] |= 1 << 17; break;
1054 case ROUND_P
: code
[1] |= 2 << 17; break;
1055 case ROUND_Z
: code
[1] |= 3 << 17; break;
1056 case ROUND_NI
: code
[0] |= 1 << 7; break;
1057 case ROUND_MI
: code
[0] |= 1 << 7; code
[1] |= 1 << 17; break;
1058 case ROUND_PI
: code
[0] |= 1 << 7; code
[1] |= 2 << 17; break;
1059 case ROUND_ZI
: code
[0] |= 1 << 7; code
[1] |= 3 << 17; break;
1060 case ROUND_N
: break;
1062 assert(!"invalid round mode");
1068 CodeEmitterNVC0::roundMode_CS(const Instruction
*i
)
1072 case ROUND_MI
: code
[0] |= 1 << 16; break;
1074 case ROUND_PI
: code
[0] |= 2 << 16; break;
1076 case ROUND_ZI
: code
[0] |= 3 << 16; break;
1083 CodeEmitterNVC0::emitCVT(Instruction
*i
)
1085 const bool f2f
= isFloatType(i
->dType
) && isFloatType(i
->sType
);
1089 case OP_CEIL
: i
->rnd
= f2f
? ROUND_PI
: ROUND_P
; break;
1090 case OP_FLOOR
: i
->rnd
= f2f
? ROUND_MI
: ROUND_M
; break;
1091 case OP_TRUNC
: i
->rnd
= f2f
? ROUND_ZI
: ROUND_Z
; break;
1096 const bool sat
= (i
->op
== OP_SAT
) || i
->saturate
;
1097 const bool abs
= (i
->op
== OP_ABS
) || i
->src(0).mod
.abs();
1098 const bool neg
= (i
->op
== OP_NEG
) || i
->src(0).mod
.neg();
1100 if (i
->op
== OP_NEG
&& i
->dType
== TYPE_U32
)
1105 if (i
->encSize
== 8) {
1106 emitForm_B(i
, HEX64(10000000, 00000004));
1110 // cvt u16 f32 sets high bits to 0, so we don't have to use Value::Size()
1111 code
[0] |= util_logbase2(typeSizeof(dType
)) << 20;
1112 code
[0] |= util_logbase2(typeSizeof(i
->sType
)) << 23;
1114 // for 8/16 source types, the byte/word is in subOp. word 1 is
1115 // represented as 2.
1116 if (!isFloatType(i
->sType
))
1117 code
[1] |= i
->subOp
<< 0x17;
1119 code
[1] |= i
->subOp
<< 0x18;
1125 if (neg
&& i
->op
!= OP_ABS
)
1131 if (isSignedIntType(dType
))
1133 if (isSignedIntType(i
->sType
))
1136 if (isFloatType(dType
)) {
1137 if (!isFloatType(i
->sType
))
1138 code
[1] |= 0x08000000;
1140 if (isFloatType(i
->sType
))
1141 code
[1] |= 0x04000000;
1143 code
[1] |= 0x0c000000;
1146 if (i
->op
== OP_CEIL
|| i
->op
== OP_FLOOR
|| i
->op
== OP_TRUNC
) {
1149 if (isFloatType(dType
)) {
1150 if (isFloatType(i
->sType
))
1153 code
[0] = 0x088 | (isSignedType(i
->sType
) ? (1 << 8) : 0);
1155 assert(isFloatType(i
->sType
));
1157 code
[0] = 0x288 | (isSignedType(i
->sType
) ? (1 << 8) : 0);
1160 if (neg
) code
[0] |= 1 << 16;
1161 if (sat
) code
[0] |= 1 << 18;
1162 if (abs
) code
[0] |= 1 << 19;
1169 CodeEmitterNVC0::emitSET(const CmpInstruction
*i
)
1174 if (i
->sType
== TYPE_F64
)
1177 if (!isFloatType(i
->sType
))
1180 if (isSignedIntType(i
->sType
))
1182 if (isFloatType(i
->dType
)) {
1183 if (isFloatType(i
->sType
))
1190 case OP_SET_AND
: hi
= 0x10000000; break;
1191 case OP_SET_OR
: hi
= 0x10200000; break;
1192 case OP_SET_XOR
: hi
= 0x10400000; break;
1197 emitForm_A(i
, (static_cast<uint64_t>(hi
) << 32) | lo
);
1199 if (i
->op
!= OP_SET
)
1200 srcId(i
->src(2), 32 + 17);
1202 if (i
->def(0).getFile() == FILE_PREDICATE
) {
1203 if (i
->sType
== TYPE_F32
)
1204 code
[1] += 0x10000000;
1206 code
[1] += 0x08000000;
1208 code
[0] &= ~0xfc000;
1209 defId(i
->def(0), 17);
1210 if (i
->defExists(1))
1211 defId(i
->def(1), 14);
1218 if (i
->flagsSrc
>= 0)
1221 emitCondCode(i
->setCond
, 32 + 23);
1226 CodeEmitterNVC0::emitSLCT(const CmpInstruction
*i
)
1232 op
= HEX64(30000000, 00000023);
1235 op
= HEX64(30000000, 00000003);
1238 op
= HEX64(38000000, 00000000);
1241 assert(!"invalid type for SLCT");
1247 CondCode cc
= i
->setCond
;
1249 if (i
->src(2).mod
.neg())
1250 cc
= reverseCondCode(cc
);
1252 emitCondCode(cc
, 32 + 23);
1259 nvc0_selpFlip(const FixupEntry
*entry
, uint32_t *code
, const FixupData
& data
)
1261 int loc
= entry
->loc
;
1262 if (data
.force_persample_interp
)
1263 code
[loc
+ 1] |= 1 << 20;
1265 code
[loc
+ 1] &= ~(1 << 20);
1268 void CodeEmitterNVC0::emitSELP(const Instruction
*i
)
1270 emitForm_A(i
, HEX64(20000000, 00000004));
1272 if (i
->src(2).mod
& Modifier(NV50_IR_MOD_NOT
))
1275 if (i
->subOp
== 1) {
1276 addInterp(0, 0, nvc0_selpFlip
);
1280 void CodeEmitterNVC0::emitTEXBAR(const Instruction
*i
)
1282 code
[0] = 0x00000006 | (i
->subOp
<< 26);
1283 code
[1] = 0xf0000000;
1285 emitCondCode(i
->flagsSrc
>= 0 ? i
->cc
: CC_ALWAYS
, 5);
1288 void CodeEmitterNVC0::emitTEXCSAA(const TexInstruction
*i
)
1290 code
[0] = 0x00000086;
1291 code
[1] = 0xd0000000;
1293 code
[1] |= i
->tex
.r
;
1294 code
[1] |= i
->tex
.s
<< 8;
1296 if (i
->tex
.liveOnly
)
1299 defId(i
->def(0), 14);
1300 srcId(i
->src(0), 20);
1304 isNextIndependentTex(const TexInstruction
*i
)
1306 if (!i
->next
|| !isTextureOp(i
->next
->op
))
1308 if (i
->getDef(0)->interfers(i
->next
->getSrc(0)))
1310 return !i
->next
->srcExists(1) || !i
->getDef(0)->interfers(i
->next
->getSrc(1));
1314 CodeEmitterNVC0::emitTEX(const TexInstruction
*i
)
1316 code
[0] = 0x00000006;
1318 if (isNextIndependentTex(i
))
1319 code
[0] |= 0x080; // t mode
1321 code
[0] |= 0x100; // p mode
1323 if (i
->tex
.liveOnly
)
1327 case OP_TEX
: code
[1] = 0x80000000; break;
1328 case OP_TXB
: code
[1] = 0x84000000; break;
1329 case OP_TXL
: code
[1] = 0x86000000; break;
1330 case OP_TXF
: code
[1] = 0x90000000; break;
1331 case OP_TXG
: code
[1] = 0xa0000000; break;
1332 case OP_TXLQ
: code
[1] = 0xb0000000; break;
1333 case OP_TXD
: code
[1] = 0xe0000000; break;
1335 assert(!"invalid texture op");
1338 if (i
->op
== OP_TXF
) {
1339 if (!i
->tex
.levelZero
)
1340 code
[1] |= 0x02000000;
1342 if (i
->tex
.levelZero
) {
1343 code
[1] |= 0x02000000;
1346 if (i
->op
!= OP_TXD
&& i
->tex
.derivAll
)
1349 defId(i
->def(0), 14);
1350 srcId(i
->src(0), 20);
1354 if (i
->op
== OP_TXG
) code
[0] |= i
->tex
.gatherComp
<< 5;
1356 code
[1] |= i
->tex
.mask
<< 14;
1358 code
[1] |= i
->tex
.r
;
1359 code
[1] |= i
->tex
.s
<< 8;
1360 if (i
->tex
.rIndirectSrc
>= 0 || i
->tex
.sIndirectSrc
>= 0)
1361 code
[1] |= 1 << 18; // in 1st source (with array index)
1364 code
[1] |= (i
->tex
.target
.getDim() - 1) << 20;
1365 if (i
->tex
.target
.isCube())
1367 if (i
->tex
.target
.isArray())
1369 if (i
->tex
.target
.isShadow())
1372 const int src1
= (i
->predSrc
== 1) ? 2 : 1; // if predSrc == 1, !srcExists(2)
1374 if (i
->srcExists(src1
) && i
->src(src1
).getFile() == FILE_IMMEDIATE
) {
1376 if (i
->op
== OP_TXL
)
1377 code
[1] &= ~(1 << 26);
1379 if (i
->op
== OP_TXF
)
1380 code
[1] &= ~(1 << 25);
1382 if (i
->tex
.target
== TEX_TARGET_2D_MS
||
1383 i
->tex
.target
== TEX_TARGET_2D_MS_ARRAY
)
1386 if (i
->tex
.useOffsets
== 1)
1388 if (i
->tex
.useOffsets
== 4)
1395 CodeEmitterNVC0::emitTXQ(const TexInstruction
*i
)
1397 code
[0] = 0x00000086;
1398 code
[1] = 0xc0000000;
1400 switch (i
->tex
.query
) {
1401 case TXQ_DIMS
: code
[1] |= 0 << 22; break;
1402 case TXQ_TYPE
: code
[1] |= 1 << 22; break;
1403 case TXQ_SAMPLE_POSITION
: code
[1] |= 2 << 22; break;
1404 case TXQ_FILTER
: code
[1] |= 3 << 22; break;
1405 case TXQ_LOD
: code
[1] |= 4 << 22; break;
1406 case TXQ_BORDER_COLOUR
: code
[1] |= 5 << 22; break;
1408 assert(!"invalid texture query");
1412 code
[1] |= i
->tex
.mask
<< 14;
1414 code
[1] |= i
->tex
.r
;
1415 code
[1] |= i
->tex
.s
<< 8;
1416 if (i
->tex
.sIndirectSrc
>= 0 || i
->tex
.rIndirectSrc
>= 0)
1419 const int src1
= (i
->predSrc
== 1) ? 2 : 1; // if predSrc == 1, !srcExists(2)
1421 defId(i
->def(0), 14);
1422 srcId(i
->src(0), 20);
1429 CodeEmitterNVC0::emitQUADOP(const Instruction
*i
, uint8_t qOp
, uint8_t laneMask
)
1431 code
[0] = 0x00000200 | (laneMask
<< 6); // dall
1432 code
[1] = 0x48000000 | qOp
;
1434 defId(i
->def(0), 14);
1435 srcId(i
->src(0), 20);
1436 srcId((i
->srcExists(1) && i
->predSrc
!= 1) ? i
->src(1) : i
->src(0), 26);
1442 CodeEmitterNVC0::emitFlow(const Instruction
*i
)
1444 const FlowInstruction
*f
= i
->asFlow();
1446 unsigned mask
; // bit 0: predicate, bit 1: target
1448 code
[0] = 0x00000007;
1452 code
[1] = f
->absolute
? 0x00000000 : 0x40000000;
1453 if (i
->srcExists(0) && i
->src(0).getFile() == FILE_MEMORY_CONST
)
1458 code
[1] = f
->absolute
? 0x10000000 : 0x50000000;
1460 code
[0] |= 0x4000; // indirect calls always use c[] source
1464 case OP_EXIT
: code
[1] = 0x80000000; mask
= 1; break;
1465 case OP_RET
: code
[1] = 0x90000000; mask
= 1; break;
1466 case OP_DISCARD
: code
[1] = 0x98000000; mask
= 1; break;
1467 case OP_BREAK
: code
[1] = 0xa8000000; mask
= 1; break;
1468 case OP_CONT
: code
[1] = 0xb0000000; mask
= 1; break;
1470 case OP_JOINAT
: code
[1] = 0x60000000; mask
= 2; break;
1471 case OP_PREBREAK
: code
[1] = 0x68000000; mask
= 2; break;
1472 case OP_PRECONT
: code
[1] = 0x70000000; mask
= 2; break;
1473 case OP_PRERET
: code
[1] = 0x78000000; mask
= 2; break;
1475 case OP_QUADON
: code
[1] = 0xc0000000; mask
= 0; break;
1476 case OP_QUADPOP
: code
[1] = 0xc8000000; mask
= 0; break;
1477 case OP_BRKPT
: code
[1] = 0xd0000000; mask
= 0; break;
1479 assert(!"invalid flow operation");
1485 if (i
->flagsSrc
< 0)
1498 if (code
[0] & 0x4000) {
1499 assert(i
->srcExists(0) && i
->src(0).getFile() == FILE_MEMORY_CONST
);
1500 setAddress16(i
->src(0));
1501 code
[1] |= i
->getSrc(0)->reg
.fileIndex
<< 10;
1502 if (f
->op
== OP_BRA
)
1503 srcId(f
->src(0).getIndirect(0), 20);
1509 if (f
->op
== OP_CALL
) {
1514 assert(f
->absolute
);
1515 uint32_t pcAbs
= targNVC0
->getBuiltinOffset(f
->target
.builtin
);
1516 addReloc(RelocEntry::TYPE_BUILTIN
, 0, pcAbs
, 0xfc000000, 26);
1517 addReloc(RelocEntry::TYPE_BUILTIN
, 1, pcAbs
, 0x03ffffff, -6);
1519 assert(!f
->absolute
);
1520 int32_t pcRel
= f
->target
.fn
->binPos
- (codeSize
+ 8);
1521 code
[0] |= (pcRel
& 0x3f) << 26;
1522 code
[1] |= (pcRel
>> 6) & 0x3ffff;
1526 int32_t pcRel
= f
->target
.bb
->binPos
- (codeSize
+ 8);
1527 if (writeIssueDelays
&& !(f
->target
.bb
->binPos
& 0x3f))
1529 // currently we don't want absolute branches
1530 assert(!f
->absolute
);
1531 code
[0] |= (pcRel
& 0x3f) << 26;
1532 code
[1] |= (pcRel
>> 6) & 0x3ffff;
1537 CodeEmitterNVC0::emitBAR(const Instruction
*i
)
1539 Value
*rDef
= NULL
, *pDef
= NULL
;
1542 case NV50_IR_SUBOP_BAR_ARRIVE
: code
[0] = 0x84; break;
1543 case NV50_IR_SUBOP_BAR_RED_AND
: code
[0] = 0x24; break;
1544 case NV50_IR_SUBOP_BAR_RED_OR
: code
[0] = 0x44; break;
1545 case NV50_IR_SUBOP_BAR_RED_POPC
: code
[0] = 0x04; break;
1548 assert(i
->subOp
== NV50_IR_SUBOP_BAR_SYNC
);
1551 code
[1] = 0x50000000;
1553 code
[0] |= 63 << 14;
1559 if (i
->src(0).getFile() == FILE_GPR
) {
1560 srcId(i
->src(0), 20);
1562 ImmediateValue
*imm
= i
->getSrc(0)->asImm();
1564 code
[0] |= imm
->reg
.data
.u32
<< 20;
1569 if (i
->src(1).getFile() == FILE_GPR
) {
1570 srcId(i
->src(1), 26);
1572 ImmediateValue
*imm
= i
->getSrc(1)->asImm();
1574 assert(imm
->reg
.data
.u32
<= 0xfff);
1575 code
[0] |= imm
->reg
.data
.u32
<< 26;
1576 code
[1] |= imm
->reg
.data
.u32
>> 6;
1580 if (i
->srcExists(2) && (i
->predSrc
!= 2)) {
1581 srcId(i
->src(2), 32 + 17);
1582 if (i
->src(2).mod
== Modifier(NV50_IR_MOD_NOT
))
1588 if (i
->defExists(0)) {
1589 if (i
->def(0).getFile() == FILE_GPR
)
1590 rDef
= i
->getDef(0);
1592 pDef
= i
->getDef(0);
1594 if (i
->defExists(1)) {
1595 if (i
->def(1).getFile() == FILE_GPR
)
1596 rDef
= i
->getDef(1);
1598 pDef
= i
->getDef(1);
1602 code
[0] &= ~(63 << 14);
1606 code
[1] &= ~(7 << 21);
1607 defId(pDef
, 32 + 21);
1612 CodeEmitterNVC0::emitAFETCH(const Instruction
*i
)
1614 code
[0] = 0x00000006;
1615 code
[1] = 0x0c000000 | (i
->src(0).get()->reg
.data
.offset
& 0x7ff);
1617 if (i
->getSrc(0)->reg
.file
== FILE_SHADER_OUTPUT
)
1622 defId(i
->def(0), 14);
1623 srcId(i
->src(0).getIndirect(0), 20);
1627 CodeEmitterNVC0::emitPFETCH(const Instruction
*i
)
1629 uint32_t prim
= i
->src(0).get()->reg
.data
.u32
;
1631 code
[0] = 0x00000006 | ((prim
& 0x3f) << 26);
1632 code
[1] = 0x00000000 | (prim
>> 6);
1636 const int src1
= (i
->predSrc
== 1) ? 2 : 1; // if predSrc == 1, !srcExists(2)
1638 defId(i
->def(0), 14);
1643 CodeEmitterNVC0::emitVFETCH(const Instruction
*i
)
1645 code
[0] = 0x00000006;
1646 code
[1] = 0x06000000 | i
->src(0).get()->reg
.data
.offset
;
1650 if (i
->getSrc(0)->reg
.file
== FILE_SHADER_OUTPUT
)
1651 code
[0] |= 0x200; // yes, TCPs can read from *outputs* of other threads
1655 code
[0] |= ((i
->getDef(0)->reg
.size
/ 4) - 1) << 5;
1657 defId(i
->def(0), 14);
1658 srcId(i
->src(0).getIndirect(0), 20);
1659 srcId(i
->src(0).getIndirect(1), 26); // vertex address
1663 CodeEmitterNVC0::emitEXPORT(const Instruction
*i
)
1665 unsigned int size
= typeSizeof(i
->dType
);
1667 code
[0] = 0x00000006 | ((size
/ 4 - 1) << 5);
1668 code
[1] = 0x0a000000 | i
->src(0).get()->reg
.data
.offset
;
1670 assert(!(code
[1] & ((size
== 12) ? 15 : (size
- 1))));
1677 assert(i
->src(1).getFile() == FILE_GPR
);
1679 srcId(i
->src(0).getIndirect(0), 20);
1680 srcId(i
->src(0).getIndirect(1), 32 + 17); // vertex base address
1681 srcId(i
->src(1), 26);
1685 CodeEmitterNVC0::emitOUT(const Instruction
*i
)
1687 code
[0] = 0x00000006;
1688 code
[1] = 0x1c000000;
1692 defId(i
->def(0), 14); // new secret address
1693 srcId(i
->src(0), 20); // old secret address, should be 0 initially
1695 assert(i
->src(0).getFile() == FILE_GPR
);
1697 if (i
->op
== OP_EMIT
)
1699 if (i
->op
== OP_RESTART
|| i
->subOp
== NV50_IR_SUBOP_EMIT_RESTART
)
1703 if (i
->src(1).getFile() == FILE_IMMEDIATE
) {
1704 unsigned int stream
= SDATA(i
->src(1)).u32
;
1708 code
[0] |= stream
<< 26;
1713 srcId(i
->src(1), 26);
1718 CodeEmitterNVC0::emitInterpMode(const Instruction
*i
)
1720 if (i
->encSize
== 8) {
1721 code
[0] |= i
->ipa
<< 6; // TODO: INTERP_SAMPLEID
1723 if (i
->getInterpMode() == NV50_IR_INTERP_SC
)
1725 assert(i
->op
== OP_PINTERP
&& i
->getSampleMode() == 0);
1730 nvc0_interpApply(const FixupEntry
*entry
, uint32_t *code
, const FixupData
& data
)
1732 int ipa
= entry
->ipa
;
1733 int reg
= entry
->reg
;
1734 int loc
= entry
->loc
;
1736 if (data
.flatshade
&&
1737 (ipa
& NV50_IR_INTERP_MODE_MASK
) == NV50_IR_INTERP_SC
) {
1738 ipa
= NV50_IR_INTERP_FLAT
;
1740 } else if (data
.force_persample_interp
&&
1741 (ipa
& NV50_IR_INTERP_SAMPLE_MASK
) == NV50_IR_INTERP_DEFAULT
&&
1742 (ipa
& NV50_IR_INTERP_MODE_MASK
) != NV50_IR_INTERP_FLAT
) {
1743 ipa
|= NV50_IR_INTERP_CENTROID
;
1745 code
[loc
+ 0] &= ~(0xf << 6);
1746 code
[loc
+ 0] |= ipa
<< 6;
1747 code
[loc
+ 0] &= ~(0x3f << 26);
1748 code
[loc
+ 0] |= reg
<< 26;
1752 CodeEmitterNVC0::emitINTERP(const Instruction
*i
)
1754 const uint32_t base
= i
->getSrc(0)->reg
.data
.offset
;
1756 if (i
->encSize
== 8) {
1757 code
[0] = 0x00000000;
1758 code
[1] = 0xc0000000 | (base
& 0xffff);
1763 if (i
->op
== OP_PINTERP
) {
1764 srcId(i
->src(1), 26);
1765 addInterp(i
->ipa
, SDATA(i
->src(1)).id
, nvc0_interpApply
);
1767 code
[0] |= 0x3f << 26;
1768 addInterp(i
->ipa
, 0x3f, nvc0_interpApply
);
1771 srcId(i
->src(0).getIndirect(0), 20);
1773 assert(i
->op
== OP_PINTERP
);
1774 code
[0] = 0x00000009 | ((base
& 0xc) << 6) | ((base
>> 4) << 26);
1775 srcId(i
->src(1), 20);
1780 defId(i
->def(0), 14);
1782 if (i
->getSampleMode() == NV50_IR_INTERP_OFFSET
)
1783 srcId(i
->src(i
->op
== OP_PINTERP
? 2 : 1), 32 + 17);
1785 code
[1] |= 0x3f << 17;
1789 CodeEmitterNVC0::emitLoadStoreType(DataType ty
)
1822 assert(!"invalid type");
1829 CodeEmitterNVC0::emitCachingMode(CacheMode c
)
1850 assert(!"invalid caching mode");
1857 uses64bitAddress(const Instruction
*ldst
)
1859 return ldst
->src(0).getFile() == FILE_MEMORY_GLOBAL
&&
1860 ldst
->src(0).isIndirect(0) &&
1861 ldst
->getIndirect(0, 0)->reg
.size
== 8;
1865 CodeEmitterNVC0::emitSTORE(const Instruction
*i
)
1869 switch (i
->src(0).getFile()) {
1870 case FILE_MEMORY_GLOBAL
: opc
= 0x90000000; break;
1871 case FILE_MEMORY_LOCAL
: opc
= 0xc8000000; break;
1872 case FILE_MEMORY_SHARED
:
1873 if (i
->subOp
== NV50_IR_SUBOP_STORE_UNLOCKED
) {
1874 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
1883 assert(!"invalid memory file");
1887 code
[0] = 0x00000005;
1890 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
) {
1891 // Unlocked store on shared memory can fail.
1892 if (i
->src(0).getFile() == FILE_MEMORY_SHARED
&&
1893 i
->subOp
== NV50_IR_SUBOP_STORE_UNLOCKED
) {
1894 assert(i
->defExists(0));
1899 setAddressByFile(i
->src(0));
1900 srcId(i
->src(1), 14);
1901 srcId(i
->src(0).getIndirect(0), 20);
1902 if (uses64bitAddress(i
))
1907 emitLoadStoreType(i
->dType
);
1908 emitCachingMode(i
->cache
);
1912 CodeEmitterNVC0::emitLOAD(const Instruction
*i
)
1916 code
[0] = 0x00000005;
1918 switch (i
->src(0).getFile()) {
1919 case FILE_MEMORY_GLOBAL
: opc
= 0x80000000; break;
1920 case FILE_MEMORY_LOCAL
: opc
= 0xc0000000; break;
1921 case FILE_MEMORY_SHARED
:
1922 if (i
->subOp
== NV50_IR_SUBOP_LOAD_LOCKED
) {
1923 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
1931 case FILE_MEMORY_CONST
:
1932 if (!i
->src(0).isIndirect(0) && typeSizeof(i
->dType
) == 4) {
1933 emitMOV(i
); // not sure if this is any better
1936 opc
= 0x14000000 | (i
->src(0).get()->reg
.fileIndex
<< 10);
1937 code
[0] = 0x00000006 | (i
->subOp
<< 8);
1940 assert(!"invalid memory file");
1947 if (i
->src(0).getFile() == FILE_MEMORY_SHARED
) {
1948 if (i
->subOp
== NV50_IR_SUBOP_LOAD_LOCKED
) {
1949 if (i
->def(0).getFile() == FILE_PREDICATE
) { // p, #
1952 } else if (i
->defExists(1)) { // r, p
1955 assert(!"Expected predicate dest for load locked");
1961 defId(i
->def(r
), 14);
1963 code
[0] |= 63 << 14;
1966 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
1969 defId(i
->def(p
), 32 + 18);
1972 setAddressByFile(i
->src(0));
1973 srcId(i
->src(0).getIndirect(0), 20);
1974 if (uses64bitAddress(i
))
1979 emitLoadStoreType(i
->dType
);
1980 emitCachingMode(i
->cache
);
1984 CodeEmitterNVC0::getSRegEncoding(const ValueRef
& ref
)
1986 switch (SDATA(ref
).sv
.sv
) {
1987 case SV_LANEID
: return 0x00;
1988 case SV_PHYSID
: return 0x03;
1989 case SV_VERTEX_COUNT
: return 0x10;
1990 case SV_INVOCATION_ID
: return 0x11;
1991 case SV_YDIR
: return 0x12;
1992 case SV_THREAD_KILL
: return 0x13;
1993 case SV_COMBINED_TID
: return 0x20;
1994 case SV_TID
: return 0x21 + SDATA(ref
).sv
.index
;
1995 case SV_CTAID
: return 0x25 + SDATA(ref
).sv
.index
;
1996 case SV_NTID
: return 0x29 + SDATA(ref
).sv
.index
;
1997 case SV_GRIDID
: return 0x2c;
1998 case SV_NCTAID
: return 0x2d + SDATA(ref
).sv
.index
;
1999 case SV_LBASE
: return 0x34;
2000 case SV_SBASE
: return 0x30;
2001 case SV_LANEMASK_EQ
: return 0x38;
2002 case SV_LANEMASK_LT
: return 0x39;
2003 case SV_LANEMASK_LE
: return 0x3a;
2004 case SV_LANEMASK_GT
: return 0x3b;
2005 case SV_LANEMASK_GE
: return 0x3c;
2006 case SV_CLOCK
: return 0x50 + SDATA(ref
).sv
.index
;
2008 assert(!"no sreg for system value");
2014 CodeEmitterNVC0::emitMOV(const Instruction
*i
)
2016 assert(!i
->saturate
);
2017 if (i
->def(0).getFile() == FILE_PREDICATE
) {
2018 if (i
->src(0).getFile() == FILE_GPR
) {
2019 code
[0] = 0xfc01c003;
2020 code
[1] = 0x1a8e0000;
2021 srcId(i
->src(0), 20);
2023 code
[0] = 0x0001c004;
2024 code
[1] = 0x0c0e0000;
2025 if (i
->src(0).getFile() == FILE_IMMEDIATE
) {
2027 if (!i
->getSrc(0)->reg
.data
.u32
)
2030 srcId(i
->src(0), 20);
2033 defId(i
->def(0), 17);
2036 if (i
->src(0).getFile() == FILE_SYSTEM_VALUE
) {
2037 uint8_t sr
= getSRegEncoding(i
->src(0));
2039 if (i
->encSize
== 8) {
2040 code
[0] = 0x00000004 | (sr
<< 26);
2041 code
[1] = 0x2c000000;
2043 code
[0] = 0x40000008 | (sr
<< 20);
2045 defId(i
->def(0), 14);
2049 if (i
->encSize
== 8) {
2052 if (i
->src(0).getFile() == FILE_IMMEDIATE
)
2053 opc
= HEX64(18000000, 000001e2
);
2055 if (i
->src(0).getFile() == FILE_PREDICATE
)
2056 opc
= HEX64(080e0000
, 1c000004
);
2058 opc
= HEX64(28000000, 00000004);
2060 if (i
->src(0).getFile() != FILE_PREDICATE
)
2061 opc
|= i
->lanes
<< 5;
2065 // Explicitly emit the predicate source as emitForm_B skips it.
2066 if (i
->src(0).getFile() == FILE_PREDICATE
)
2067 srcId(i
->src(0), 20);
2071 if (i
->src(0).getFile() == FILE_IMMEDIATE
) {
2072 imm
= SDATA(i
->src(0)).u32
;
2073 if (imm
& 0xfff00000) {
2074 assert(!(imm
& 0x000fffff));
2075 code
[0] = 0x00000318 | imm
;
2077 assert(imm
< 0x800 && ((int32_t)imm
>= -0x800));
2078 code
[0] = 0x00000118 | (imm
<< 20);
2082 emitShortSrc2(i
->src(0));
2084 defId(i
->def(0), 14);
2091 CodeEmitterNVC0::emitATOM(const Instruction
*i
)
2093 const bool hasDst
= i
->defExists(0);
2094 const bool casOrExch
=
2095 i
->subOp
== NV50_IR_SUBOP_ATOM_EXCH
||
2096 i
->subOp
== NV50_IR_SUBOP_ATOM_CAS
;
2098 if (i
->dType
== TYPE_U64
) {
2100 case NV50_IR_SUBOP_ATOM_ADD
:
2103 code
[1] = 0x507e0000;
2105 code
[1] = 0x10000000;
2107 case NV50_IR_SUBOP_ATOM_EXCH
:
2109 code
[1] = 0x507e0000;
2111 case NV50_IR_SUBOP_ATOM_CAS
:
2113 code
[1] = 0x50000000;
2116 assert(!"invalid u64 red op");
2120 if (i
->dType
== TYPE_U32
) {
2122 case NV50_IR_SUBOP_ATOM_EXCH
:
2124 code
[1] = 0x507e0000;
2126 case NV50_IR_SUBOP_ATOM_CAS
:
2128 code
[1] = 0x50000000;
2131 code
[0] = 0x5 | (i
->subOp
<< 5);
2133 code
[1] = 0x507e0000;
2135 code
[1] = 0x10000000;
2139 if (i
->dType
== TYPE_S32
) {
2140 assert(i
->subOp
<= 2);
2141 code
[0] = 0x205 | (i
->subOp
<< 5);
2143 code
[1] = 0x587e0000;
2145 code
[1] = 0x18000000;
2147 if (i
->dType
== TYPE_F32
) {
2148 assert(i
->subOp
== NV50_IR_SUBOP_ATOM_ADD
);
2151 code
[1] = 0x687e0000;
2153 code
[1] = 0x28000000;
2158 srcId(i
->src(1), 14);
2161 defId(i
->def(0), 32 + 11);
2164 code
[1] |= 63 << 11;
2166 if (hasDst
|| casOrExch
) {
2167 const int32_t offset
= SDATA(i
->src(0)).offset
;
2168 assert(offset
< 0x80000 && offset
>= -0x80000);
2169 code
[0] |= offset
<< 26;
2170 code
[1] |= (offset
& 0x1ffc0) >> 6;
2171 code
[1] |= (offset
& 0xe0000) << 6;
2173 srcAddr32(i
->src(0), 26, 0);
2175 if (i
->getIndirect(0, 0)) {
2176 srcId(i
->getIndirect(0, 0), 20);
2177 if (i
->getIndirect(0, 0)->reg
.size
== 8)
2180 code
[0] |= 63 << 20;
2183 if (i
->subOp
== NV50_IR_SUBOP_ATOM_CAS
) {
2184 assert(i
->src(1).getSize() == 2 * typeSizeof(i
->sType
));
2185 code
[1] |= (SDATA(i
->src(1)).id
+ 1) << 17;
2190 CodeEmitterNVC0::emitMEMBAR(const Instruction
*i
)
2192 switch (NV50_IR_SUBOP_MEMBAR_SCOPE(i
->subOp
)) {
2193 case NV50_IR_SUBOP_MEMBAR_CTA
: code
[0] = 0x05; break;
2194 case NV50_IR_SUBOP_MEMBAR_GL
: code
[0] = 0x25; break;
2197 assert(NV50_IR_SUBOP_MEMBAR_SCOPE(i
->subOp
) == NV50_IR_SUBOP_MEMBAR_SYS
);
2200 code
[1] = 0xe0000000;
2206 CodeEmitterNVC0::emitCCTL(const Instruction
*i
)
2208 code
[0] = 0x00000005 | (i
->subOp
<< 5);
2210 if (i
->src(0).getFile() == FILE_MEMORY_GLOBAL
) {
2211 code
[1] = 0x98000000;
2212 srcAddr32(i
->src(0), 28, 2);
2214 code
[1] = 0xd0000000;
2215 setAddress24(i
->src(0));
2217 if (uses64bitAddress(i
))
2219 srcId(i
->src(0).getIndirect(0), 20);
2227 CodeEmitterNVC0::emitSUCLAMPMode(uint16_t subOp
)
2230 switch (subOp
& ~NV50_IR_SUBOP_SUCLAMP_2D
) {
2231 case NV50_IR_SUBOP_SUCLAMP_SD(0, 1): m
= 0; break;
2232 case NV50_IR_SUBOP_SUCLAMP_SD(1, 1): m
= 1; break;
2233 case NV50_IR_SUBOP_SUCLAMP_SD(2, 1): m
= 2; break;
2234 case NV50_IR_SUBOP_SUCLAMP_SD(3, 1): m
= 3; break;
2235 case NV50_IR_SUBOP_SUCLAMP_SD(4, 1): m
= 4; break;
2236 case NV50_IR_SUBOP_SUCLAMP_PL(0, 1): m
= 5; break;
2237 case NV50_IR_SUBOP_SUCLAMP_PL(1, 1): m
= 6; break;
2238 case NV50_IR_SUBOP_SUCLAMP_PL(2, 1): m
= 7; break;
2239 case NV50_IR_SUBOP_SUCLAMP_PL(3, 1): m
= 8; break;
2240 case NV50_IR_SUBOP_SUCLAMP_PL(4, 1): m
= 9; break;
2241 case NV50_IR_SUBOP_SUCLAMP_BL(0, 1): m
= 10; break;
2242 case NV50_IR_SUBOP_SUCLAMP_BL(1, 1): m
= 11; break;
2243 case NV50_IR_SUBOP_SUCLAMP_BL(2, 1): m
= 12; break;
2244 case NV50_IR_SUBOP_SUCLAMP_BL(3, 1): m
= 13; break;
2245 case NV50_IR_SUBOP_SUCLAMP_BL(4, 1): m
= 14; break;
2250 if (subOp
& NV50_IR_SUBOP_SUCLAMP_2D
)
2255 CodeEmitterNVC0::emitSUCalc(Instruction
*i
)
2257 ImmediateValue
*imm
= NULL
;
2260 if (i
->srcExists(2)) {
2261 imm
= i
->getSrc(2)->asImm();
2263 i
->setSrc(2, NULL
); // special case, make emitForm_A not assert
2267 case OP_SUCLAMP
: opc
= HEX64(58000000, 00000004); break;
2268 case OP_SUBFM
: opc
= HEX64(5c000000
, 00000004); break;
2269 case OP_SUEAU
: opc
= HEX64(60000000, 00000004); break;
2276 if (i
->op
== OP_SUCLAMP
) {
2277 if (i
->dType
== TYPE_S32
)
2279 emitSUCLAMPMode(i
->subOp
);
2282 if (i
->op
== OP_SUBFM
&& i
->subOp
== NV50_IR_SUBOP_SUBFM_3D
)
2285 if (i
->op
!= OP_SUEAU
) {
2286 if (i
->def(0).getFile() == FILE_PREDICATE
) { // p, #
2287 code
[0] |= 63 << 14;
2288 code
[1] |= i
->getDef(0)->reg
.data
.id
<< 23;
2290 if (i
->defExists(1)) { // r, p
2291 assert(i
->def(1).getFile() == FILE_PREDICATE
);
2292 code
[1] |= i
->getDef(1)->reg
.data
.id
<< 23;
2298 assert(i
->op
== OP_SUCLAMP
);
2300 code
[1] |= (imm
->reg
.data
.u32
& 0x3f) << 17; // sint6
2305 CodeEmitterNVC0::emitSUGType(DataType ty
)
2308 case TYPE_S32
: code
[1] |= 1 << 13; break;
2309 case TYPE_U8
: code
[1] |= 2 << 13; break;
2310 case TYPE_S8
: code
[1] |= 3 << 13; break;
2312 assert(ty
== TYPE_U32
);
2318 CodeEmitterNVC0::setSUConst16(const Instruction
*i
, const int s
)
2320 const uint32_t offset
= i
->getSrc(s
)->reg
.data
.offset
;
2322 assert(i
->src(s
).getFile() == FILE_MEMORY_CONST
);
2323 assert(offset
== (offset
& 0xfffc));
2326 code
[0] |= offset
<< 24;
2327 code
[1] |= offset
>> 8;
2328 code
[1] |= i
->getSrc(s
)->reg
.fileIndex
<< 8;
2332 CodeEmitterNVC0::setSUPred(const Instruction
*i
, const int s
)
2334 if (!i
->srcExists(s
) || (i
->predSrc
== s
)) {
2335 code
[1] |= 0x7 << 17;
2337 if (i
->src(s
).mod
== Modifier(NV50_IR_MOD_NOT
))
2339 srcId(i
->src(s
), 32 + 17);
2344 CodeEmitterNVC0::emitSULDGB(const TexInstruction
*i
)
2347 code
[1] = 0xd4000000 | (i
->subOp
<< 15);
2349 emitLoadStoreType(i
->dType
);
2350 emitSUGType(i
->sType
);
2351 emitCachingMode(i
->cache
);
2354 defId(i
->def(0), 14); // destination
2355 srcId(i
->src(0), 20); // address
2357 if (i
->src(1).getFile() == FILE_GPR
)
2358 srcId(i
->src(1), 26);
2365 CodeEmitterNVC0::emitSUSTGx(const TexInstruction
*i
)
2368 code
[1] = 0xdc000000 | (i
->subOp
<< 15);
2370 if (i
->op
== OP_SUSTP
)
2371 code
[1] |= i
->tex
.mask
<< 22;
2373 emitLoadStoreType(i
->dType
);
2374 emitSUGType(i
->sType
);
2375 emitCachingMode(i
->cache
);
2378 srcId(i
->src(0), 20); // address
2380 if (i
->src(1).getFile() == FILE_GPR
)
2381 srcId(i
->src(1), 26);
2384 srcId(i
->src(3), 14); // values
2389 CodeEmitterNVC0::emitSUAddr(const TexInstruction
*i
)
2391 assert(targ
->getChipset() < NVISA_GK104_CHIPSET
);
2393 if (i
->tex
.rIndirectSrc
< 0) {
2394 code
[1] |= 0x00004000;
2395 code
[0] |= i
->tex
.r
<< 26;
2397 srcId(i
, i
->tex
.rIndirectSrc
, 26);
2402 CodeEmitterNVC0::emitSUDim(const TexInstruction
*i
)
2404 assert(targ
->getChipset() < NVISA_GK104_CHIPSET
);
2406 code
[1] |= (i
->tex
.target
.getDim() - 1) << 12;
2407 if (i
->tex
.target
.isArray() || i
->tex
.target
.isCube() ||
2408 i
->tex
.target
.getDim() == 3) {
2409 // use e2d mode for 3-dim images, arrays and cubes.
2413 srcId(i
->src(0), 20);
2417 CodeEmitterNVC0::emitSULEA(const TexInstruction
*i
)
2419 assert(targ
->getChipset() < NVISA_GK104_CHIPSET
);
2422 code
[1] = 0xf0000000;
2425 emitLoadStoreType(i
->sType
);
2427 defId(i
->def(0), 14);
2429 if (i
->defExists(1)) {
2430 defId(i
->def(1), 32 + 22);
2440 CodeEmitterNVC0::emitSULDB(const TexInstruction
*i
)
2442 assert(targ
->getChipset() < NVISA_GK104_CHIPSET
);
2445 code
[1] = 0xd4000000 | (i
->subOp
<< 15);
2448 emitLoadStoreType(i
->dType
);
2450 defId(i
->def(0), 14);
2452 emitCachingMode(i
->cache
);
2458 CodeEmitterNVC0::emitSUSTx(const TexInstruction
*i
)
2460 assert(targ
->getChipset() < NVISA_GK104_CHIPSET
);
2463 code
[1] = 0xdc000000 | (i
->subOp
<< 15);
2465 if (i
->op
== OP_SUSTP
)
2466 code
[1] |= i
->tex
.mask
<< 17;
2468 emitLoadStoreType(i
->dType
);
2472 srcId(i
->src(1), 14);
2474 emitCachingMode(i
->cache
);
2480 CodeEmitterNVC0::emitVectorSubOp(const Instruction
*i
)
2482 switch (NV50_IR_SUBOP_Vn(i
->subOp
)) {
2484 code
[1] |= (i
->subOp
& 0x000f) << 12; // vsrc1
2485 code
[1] |= (i
->subOp
& 0x00e0) >> 5; // vsrc2
2486 code
[1] |= (i
->subOp
& 0x0100) << 7; // vsrc2
2487 code
[1] |= (i
->subOp
& 0x3c00) << 13; // vdst
2490 code
[1] |= (i
->subOp
& 0x000f) << 8; // v2src1
2491 code
[1] |= (i
->subOp
& 0x0010) << 11; // v2src1
2492 code
[1] |= (i
->subOp
& 0x01e0) >> 1; // v2src2
2493 code
[1] |= (i
->subOp
& 0x0200) << 6; // v2src2
2494 code
[1] |= (i
->subOp
& 0x3c00) << 2; // v4dst
2495 code
[1] |= (i
->mask
& 0x3) << 2;
2498 code
[1] |= (i
->subOp
& 0x000f) << 8; // v4src1
2499 code
[1] |= (i
->subOp
& 0x01e0) >> 1; // v4src2
2500 code
[1] |= (i
->subOp
& 0x3c00) << 2; // v4dst
2501 code
[1] |= (i
->mask
& 0x3) << 2;
2502 code
[1] |= (i
->mask
& 0xc) << 21;
2511 CodeEmitterNVC0::emitVSHL(const Instruction
*i
)
2515 switch (NV50_IR_SUBOP_Vn(i
->subOp
)) {
2516 case 0: opc
|= 0xe8ULL
<< 56; break;
2517 case 1: opc
|= 0xb4ULL
<< 56; break;
2518 case 2: opc
|= 0x94ULL
<< 56; break;
2523 if (NV50_IR_SUBOP_Vn(i
->subOp
) == 1) {
2524 if (isSignedType(i
->dType
)) opc
|= 1ULL << 0x2a;
2525 if (isSignedType(i
->sType
)) opc
|= (1 << 6) | (1 << 5);
2527 if (isSignedType(i
->dType
)) opc
|= 1ULL << 0x39;
2528 if (isSignedType(i
->sType
)) opc
|= 1 << 6;
2535 if (i
->flagsDef
>= 0)
2540 CodeEmitterNVC0::emitPIXLD(const Instruction
*i
)
2542 assert(i
->encSize
== 8);
2543 emitForm_A(i
, HEX64(10000000, 00000006));
2544 code
[0] |= i
->subOp
<< 5;
2545 code
[1] |= 0x00e00000;
2549 CodeEmitterNVC0::emitSHFL(const Instruction
*i
)
2551 const ImmediateValue
*imm
;
2553 assert(targ
->getChipset() >= NVISA_GK104_CHIPSET
);
2555 code
[0] = 0x00000005;
2556 code
[1] = 0x88000000 | (i
->subOp
<< 23);
2560 defId(i
->def(0), 14);
2561 srcId(i
->src(0), 20);
2563 switch (i
->src(1).getFile()) {
2565 srcId(i
->src(1), 26);
2567 case FILE_IMMEDIATE
:
2568 imm
= i
->getSrc(1)->asImm();
2569 assert(imm
&& imm
->reg
.data
.u32
< 0x20);
2570 code
[0] |= imm
->reg
.data
.u32
<< 26;
2574 assert(!"invalid src1 file");
2578 switch (i
->src(2).getFile()) {
2580 srcId(i
->src(2), 49);
2582 case FILE_IMMEDIATE
:
2583 imm
= i
->getSrc(2)->asImm();
2584 assert(imm
&& imm
->reg
.data
.u32
< 0x2000);
2585 code
[1] |= imm
->reg
.data
.u32
<< 10;
2589 assert(!"invalid src2 file");
2593 setPDSTL(i
, i
->defExists(1) ? 1 : -1);
2597 CodeEmitterNVC0::emitVOTE(const Instruction
*i
)
2599 const ImmediateValue
*imm
;
2602 code
[0] = 0x00000004 | (i
->subOp
<< 5);
2603 code
[1] = 0x48000000;
2608 for (int d
= 0; i
->defExists(d
); d
++) {
2609 if (i
->def(d
).getFile() == FILE_PREDICATE
) {
2612 defId(i
->def(d
), 32 + 22);
2613 } else if (i
->def(d
).getFile() == FILE_GPR
) {
2616 defId(i
->def(d
), 14);
2618 assert(!"Unhandled def");
2622 code
[0] |= 63 << 14;
2626 switch (i
->src(0).getFile()) {
2627 case FILE_PREDICATE
:
2628 if (i
->src(0).mod
== Modifier(NV50_IR_MOD_NOT
))
2630 srcId(i
->src(0), 20);
2632 case FILE_IMMEDIATE
:
2633 imm
= i
->getSrc(0)->asImm();
2635 u32
= imm
->reg
.data
.u32
;
2636 assert(u32
== 0 || u32
== 1);
2637 code
[0] |= (u32
== 1 ? 0x7 : 0xf) << 20;
2640 assert(!"Unhandled src");
2646 CodeEmitterNVC0::emitInstruction(Instruction
*insn
)
2648 unsigned int size
= insn
->encSize
;
2650 if (writeIssueDelays
&& !(codeSize
& 0x3f))
2653 if (!insn
->encSize
) {
2654 ERROR("skipping unencodable instruction: "); insn
->print();
2657 if (codeSize
+ size
> codeSizeLimit
) {
2658 ERROR("code emitter output buffer too small\n");
2662 if (writeIssueDelays
) {
2663 if (!(codeSize
& 0x3f)) {
2664 code
[0] = 0x00000007; // cf issue delay "instruction"
2665 code
[1] = 0x20000000;
2669 const unsigned int id
= (codeSize
& 0x3f) / 8 - 1;
2670 uint32_t *data
= code
- (id
* 2 + 2);
2672 data
[0] |= insn
->sched
<< (id
* 8 + 4);
2675 data
[0] |= insn
->sched
<< 28;
2676 data
[1] |= insn
->sched
>> 4;
2678 data
[1] |= insn
->sched
<< ((id
- 4) * 8 + 4);
2682 // assert that instructions with multiple defs don't corrupt registers
2683 for (int d
= 0; insn
->defExists(d
); ++d
)
2684 assert(insn
->asTex() || insn
->def(d
).rep()->reg
.data
.id
>= 0);
2721 if (insn
->dType
== TYPE_F64
)
2723 else if (isFloatType(insn
->dType
))
2729 if (insn
->dType
== TYPE_F64
)
2731 else if (isFloatType(insn
->dType
))
2738 if (insn
->dType
== TYPE_F64
)
2740 else if (isFloatType(insn
->dType
))
2755 emitLogicOp(insn
, 0);
2758 emitLogicOp(insn
, 1);
2761 emitLogicOp(insn
, 2);
2771 emitSET(insn
->asCmp());
2777 emitSLCT(insn
->asCmp());
2792 if (insn
->def(0).getFile() == FILE_PREDICATE
||
2793 insn
->src(0).getFile() == FILE_PREDICATE
)
2799 emitSFnOp(insn
, 5 + 2 * insn
->subOp
);
2802 emitSFnOp(insn
, 4 + 2 * insn
->subOp
);
2827 emitTEX(insn
->asTex());
2830 emitTXQ(insn
->asTex());
2844 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
2845 emitSULDGB(insn
->asTex());
2847 emitSULDB(insn
->asTex());
2851 if (targ
->getChipset() >= NVISA_GK104_CHIPSET
)
2852 emitSUSTGx(insn
->asTex());
2854 emitSUSTx(insn
->asTex());
2857 emitSULEA(insn
->asTex());
2879 emitQUADOP(insn
, insn
->subOp
, insn
->lanes
);
2882 emitQUADOP(insn
, insn
->src(0).mod
.neg() ? 0x66 : 0x99, 0x4);
2885 emitQUADOP(insn
, insn
->src(0).mod
.neg() ? 0x5a : 0xa5, 0x5);
2930 ERROR("operation should have been eliminated");
2936 ERROR("operation should have been lowered\n");
2939 ERROR("unknown op: %u\n", insn
->op
);
2945 assert(insn
->encSize
== 8);
2948 code
+= insn
->encSize
/ 4;
2949 codeSize
+= insn
->encSize
;
2954 CodeEmitterNVC0::getMinEncodingSize(const Instruction
*i
) const
2956 const Target::OpInfo
&info
= targ
->getOpInfo(i
);
2958 if (writeIssueDelays
|| info
.minEncSize
== 8 || 1)
2961 if (i
->ftz
|| i
->saturate
|| i
->join
)
2963 if (i
->rnd
!= ROUND_N
)
2965 if (i
->predSrc
>= 0 && i
->op
== OP_MAD
)
2968 if (i
->op
== OP_PINTERP
) {
2969 if (i
->getSampleMode() || 1) // XXX: grr, short op doesn't work
2972 if (i
->op
== OP_MOV
&& i
->lanes
!= 0xf) {
2976 for (int s
= 0; i
->srcExists(s
); ++s
) {
2977 if (i
->src(s
).isIndirect(0))
2980 if (i
->src(s
).getFile() == FILE_MEMORY_CONST
) {
2981 if (SDATA(i
->src(s
)).offset
>= 0x100)
2983 if (i
->getSrc(s
)->reg
.fileIndex
> 1 &&
2984 i
->getSrc(s
)->reg
.fileIndex
!= 16)
2987 if (i
->src(s
).getFile() == FILE_IMMEDIATE
) {
2988 if (i
->dType
== TYPE_F32
) {
2989 if (SDATA(i
->src(s
)).u32
>= 0x100)
2992 if (SDATA(i
->src(s
)).u32
> 0xff)
2997 if (i
->op
== OP_CVT
)
2999 if (i
->src(s
).mod
!= Modifier(0)) {
3000 if (i
->src(s
).mod
== Modifier(NV50_IR_MOD_ABS
))
3001 if (i
->op
!= OP_RSQ
)
3003 if (i
->src(s
).mod
== Modifier(NV50_IR_MOD_NEG
))
3004 if (i
->op
!= OP_ADD
|| s
!= 0)
3012 // Simplified, erring on safe side.
3013 class SchedDataCalculator
: public Pass
3016 SchedDataCalculator(const Target
*targ
) : targ(targ
) { }
3022 int st
[DATA_FILE_COUNT
]; // LD to LD delay 3
3023 int ld
[DATA_FILE_COUNT
]; // ST to ST delay 3
3024 int tex
; // TEX to non-TEX delay 17 (0x11)
3025 int sfu
; // SFU to SFU delay 3 (except PRE-ops)
3026 int imul
; // integer MUL to MUL delay 3
3036 void rebase(const int base
)
3038 const int delta
= this->base
- base
;
3043 for (int i
= 0; i
< regs
; ++i
) {
3047 for (int i
= 0; i
< 8; ++i
) {
3054 for (unsigned int f
= 0; f
< DATA_FILE_COUNT
; ++f
) {
3064 memset(&rd
, 0, sizeof(rd
));
3065 memset(&wr
, 0, sizeof(wr
));
3066 memset(&res
, 0, sizeof(res
));
3069 int getLatest(const ScoreData
& d
) const
3072 for (int i
= 0; i
< regs
; ++i
)
3075 for (int i
= 0; i
< 8; ++i
)
3082 inline int getLatestRd() const
3084 return getLatest(rd
);
3086 inline int getLatestWr() const
3088 return getLatest(wr
);
3090 inline int getLatest() const
3092 const int a
= getLatestRd();
3093 const int b
= getLatestWr();
3095 int max
= MAX2(a
, b
);
3096 for (unsigned int f
= 0; f
< DATA_FILE_COUNT
; ++f
) {
3097 max
= MAX2(res
.ld
[f
], max
);
3098 max
= MAX2(res
.st
[f
], max
);
3100 max
= MAX2(res
.sfu
, max
);
3101 max
= MAX2(res
.imul
, max
);
3102 max
= MAX2(res
.tex
, max
);
3105 void setMax(const RegScores
*that
)
3107 for (int i
= 0; i
< regs
; ++i
) {
3108 rd
.r
[i
] = MAX2(rd
.r
[i
], that
->rd
.r
[i
]);
3109 wr
.r
[i
] = MAX2(wr
.r
[i
], that
->wr
.r
[i
]);
3111 for (int i
= 0; i
< 8; ++i
) {
3112 rd
.p
[i
] = MAX2(rd
.p
[i
], that
->rd
.p
[i
]);
3113 wr
.p
[i
] = MAX2(wr
.p
[i
], that
->wr
.p
[i
]);
3115 rd
.c
= MAX2(rd
.c
, that
->rd
.c
);
3116 wr
.c
= MAX2(wr
.c
, that
->wr
.c
);
3118 for (unsigned int f
= 0; f
< DATA_FILE_COUNT
; ++f
) {
3119 res
.ld
[f
] = MAX2(res
.ld
[f
], that
->res
.ld
[f
]);
3120 res
.st
[f
] = MAX2(res
.st
[f
], that
->res
.st
[f
]);
3122 res
.sfu
= MAX2(res
.sfu
, that
->res
.sfu
);
3123 res
.imul
= MAX2(res
.imul
, that
->res
.imul
);
3124 res
.tex
= MAX2(res
.tex
, that
->res
.tex
);
3126 void print(int cycle
)
3128 for (int i
= 0; i
< regs
; ++i
) {
3129 if (rd
.r
[i
] > cycle
)
3130 INFO("rd $r%i @ %i\n", i
, rd
.r
[i
]);
3131 if (wr
.r
[i
] > cycle
)
3132 INFO("wr $r%i @ %i\n", i
, wr
.r
[i
]);
3134 for (int i
= 0; i
< 8; ++i
) {
3135 if (rd
.p
[i
] > cycle
)
3136 INFO("rd $p%i @ %i\n", i
, rd
.p
[i
]);
3137 if (wr
.p
[i
] > cycle
)
3138 INFO("wr $p%i @ %i\n", i
, wr
.p
[i
]);
3141 INFO("rd $c @ %i\n", rd
.c
);
3143 INFO("wr $c @ %i\n", wr
.c
);
3144 if (res
.sfu
> cycle
)
3145 INFO("sfu @ %i\n", res
.sfu
);
3146 if (res
.imul
> cycle
)
3147 INFO("imul @ %i\n", res
.imul
);
3148 if (res
.tex
> cycle
)
3149 INFO("tex @ %i\n", res
.tex
);
3153 RegScores
*score
; // for current BB
3154 std::vector
<RegScores
> scoreBoards
;
3160 bool visit(Function
*);
3161 bool visit(BasicBlock
*);
3163 void commitInsn(const Instruction
*, int cycle
);
3164 int calcDelay(const Instruction
*, int cycle
) const;
3165 void setDelay(Instruction
*, int delay
, Instruction
*next
);
3167 void recordRd(const Value
*, const int ready
);
3168 void recordWr(const Value
*, const int ready
);
3169 void checkRd(const Value
*, int cycle
, int& delay
) const;
3170 void checkWr(const Value
*, int cycle
, int& delay
) const;
3172 int getCycles(const Instruction
*, int origDelay
) const;
3176 SchedDataCalculator::setDelay(Instruction
*insn
, int delay
, Instruction
*next
)
3178 if (insn
->op
== OP_EXIT
|| insn
->op
== OP_RET
)
3179 delay
= MAX2(delay
, 14);
3181 if (insn
->op
== OP_TEXBAR
) {
3182 // TODO: except if results not used before EXIT
3185 if (insn
->op
== OP_JOIN
|| insn
->join
) {
3188 if (delay
>= 0 || prevData
== 0x04 ||
3189 !next
|| !targ
->canDualIssue(insn
, next
)) {
3190 insn
->sched
= static_cast<uint8_t>(MAX2(delay
, 0));
3191 if (prevOp
== OP_EXPORT
)
3192 insn
->sched
|= 0x40;
3194 insn
->sched
|= 0x20;
3196 insn
->sched
= 0x04; // dual-issue
3199 if (prevData
!= 0x04 || prevOp
!= OP_EXPORT
)
3200 if (insn
->sched
!= 0x04 || insn
->op
== OP_EXPORT
)
3203 prevData
= insn
->sched
;
3207 SchedDataCalculator::getCycles(const Instruction
*insn
, int origDelay
) const
3209 if (insn
->sched
& 0x80) {
3210 int c
= (insn
->sched
& 0x0f) * 2 + 1;
3211 if (insn
->op
== OP_TEXBAR
&& origDelay
> 0)
3215 if (insn
->sched
& 0x60)
3216 return (insn
->sched
& 0x1f) + 1;
3217 return (insn
->sched
== 0x04) ? 0 : 32;
3221 SchedDataCalculator::visit(Function
*func
)
3223 int regs
= targ
->getFileSize(FILE_GPR
) + 1;
3224 scoreBoards
.resize(func
->cfg
.getSize());
3225 for (size_t i
= 0; i
< scoreBoards
.size(); ++i
)
3226 scoreBoards
[i
].wipe(regs
);
3231 SchedDataCalculator::visit(BasicBlock
*bb
)
3234 Instruction
*next
= NULL
;
3240 score
= &scoreBoards
.at(bb
->getId());
3242 for (Graph::EdgeIterator ei
= bb
->cfg
.incident(); !ei
.end(); ei
.next()) {
3243 // back branches will wait until all target dependencies are satisfied
3244 if (ei
.getType() == Graph::Edge::BACK
) // sched would be uninitialized
3246 BasicBlock
*in
= BasicBlock::get(ei
.getNode());
3247 if (in
->getExit()) {
3248 if (prevData
!= 0x04)
3249 prevData
= in
->getExit()->sched
;
3250 prevOp
= in
->getExit()->op
;
3252 score
->setMax(&scoreBoards
.at(in
->getId()));
3254 if (bb
->cfg
.incidentCount() > 1)
3257 #ifdef NVC0_DEBUG_SCHED_DATA
3258 INFO("=== BB:%i initial scores\n", bb
->getId());
3259 score
->print(cycle
);
3262 for (insn
= bb
->getEntry(); insn
&& insn
->next
; insn
= insn
->next
) {
3265 commitInsn(insn
, cycle
);
3266 int delay
= calcDelay(next
, cycle
);
3267 setDelay(insn
, delay
, next
);
3268 cycle
+= getCycles(insn
, delay
);
3270 #ifdef NVC0_DEBUG_SCHED_DATA
3271 INFO("cycle %i, sched %02x\n", cycle
, insn
->sched
);
3278 commitInsn(insn
, cycle
);
3282 for (Graph::EdgeIterator ei
= bb
->cfg
.outgoing(); !ei
.end(); ei
.next()) {
3283 BasicBlock
*out
= BasicBlock::get(ei
.getNode());
3285 if (ei
.getType() != Graph::Edge::BACK
) {
3286 // only test the first instruction of the outgoing block
3287 next
= out
->getEntry();
3289 bbDelay
= MAX2(bbDelay
, calcDelay(next
, cycle
));
3291 // wait until all dependencies are satisfied
3292 const int regsFree
= score
->getLatest();
3293 next
= out
->getFirst();
3294 for (int c
= cycle
; next
&& c
< regsFree
; next
= next
->next
) {
3295 bbDelay
= MAX2(bbDelay
, calcDelay(next
, c
));
3296 c
+= getCycles(next
, bbDelay
);
3301 if (bb
->cfg
.outgoingCount() != 1)
3303 setDelay(insn
, bbDelay
, next
);
3304 cycle
+= getCycles(insn
, bbDelay
);
3306 score
->rebase(cycle
); // common base for initializing out blocks' scores
3310 #define NVE4_MAX_ISSUE_DELAY 0x1f
3312 SchedDataCalculator::calcDelay(const Instruction
*insn
, int cycle
) const
3314 int delay
= 0, ready
= cycle
;
3316 for (int s
= 0; insn
->srcExists(s
); ++s
)
3317 checkRd(insn
->getSrc(s
), cycle
, delay
);
3318 // WAR & WAW don't seem to matter
3319 // for (int s = 0; insn->srcExists(s); ++s)
3320 // recordRd(insn->getSrc(s), cycle);
3322 switch (Target::getOpClass(insn
->op
)) {
3324 ready
= score
->res
.sfu
;
3327 if (insn
->op
== OP_MUL
&& !isFloatType(insn
->dType
))
3328 ready
= score
->res
.imul
;
3330 case OPCLASS_TEXTURE
:
3331 ready
= score
->res
.tex
;
3334 ready
= score
->res
.ld
[insn
->src(0).getFile()];
3337 ready
= score
->res
.st
[insn
->src(0).getFile()];
3342 if (Target::getOpClass(insn
->op
) != OPCLASS_TEXTURE
)
3343 ready
= MAX2(ready
, score
->res
.tex
);
3345 delay
= MAX2(delay
, ready
- cycle
);
3347 // if can issue next cycle, delay is 0, not 1
3348 return MIN2(delay
- 1, NVE4_MAX_ISSUE_DELAY
);
3352 SchedDataCalculator::commitInsn(const Instruction
*insn
, int cycle
)
3354 const int ready
= cycle
+ targ
->getLatency(insn
);
3356 for (int d
= 0; insn
->defExists(d
); ++d
)
3357 recordWr(insn
->getDef(d
), ready
);
3358 // WAR & WAW don't seem to matter
3359 // for (int s = 0; insn->srcExists(s); ++s)
3360 // recordRd(insn->getSrc(s), cycle);
3362 switch (Target::getOpClass(insn
->op
)) {
3364 score
->res
.sfu
= cycle
+ 4;
3367 if (insn
->op
== OP_MUL
&& !isFloatType(insn
->dType
))
3368 score
->res
.imul
= cycle
+ 4;
3370 case OPCLASS_TEXTURE
:
3371 score
->res
.tex
= cycle
+ 18;
3374 if (insn
->src(0).getFile() == FILE_MEMORY_CONST
)
3376 score
->res
.ld
[insn
->src(0).getFile()] = cycle
+ 4;
3377 score
->res
.st
[insn
->src(0).getFile()] = ready
;
3380 score
->res
.st
[insn
->src(0).getFile()] = cycle
+ 4;
3381 score
->res
.ld
[insn
->src(0).getFile()] = ready
;
3384 if (insn
->op
== OP_TEXBAR
)
3385 score
->res
.tex
= cycle
;
3391 #ifdef NVC0_DEBUG_SCHED_DATA
3392 score
->print(cycle
);
3397 SchedDataCalculator::checkRd(const Value
*v
, int cycle
, int& delay
) const
3402 switch (v
->reg
.file
) {
3405 b
= a
+ v
->reg
.size
/ 4;
3406 for (int r
= a
; r
< b
; ++r
)
3407 ready
= MAX2(ready
, score
->rd
.r
[r
]);
3409 case FILE_PREDICATE
:
3410 ready
= MAX2(ready
, score
->rd
.p
[v
->reg
.data
.id
]);
3413 ready
= MAX2(ready
, score
->rd
.c
);
3415 case FILE_SHADER_INPUT
:
3416 case FILE_SHADER_OUTPUT
: // yes, TCPs can read outputs
3417 case FILE_MEMORY_LOCAL
:
3418 case FILE_MEMORY_CONST
:
3419 case FILE_MEMORY_SHARED
:
3420 case FILE_MEMORY_GLOBAL
:
3421 case FILE_SYSTEM_VALUE
:
3422 // TODO: any restrictions here ?
3424 case FILE_IMMEDIATE
:
3431 delay
= MAX2(delay
, ready
- cycle
);
3435 SchedDataCalculator::checkWr(const Value
*v
, int cycle
, int& delay
) const
3440 switch (v
->reg
.file
) {
3443 b
= a
+ v
->reg
.size
/ 4;
3444 for (int r
= a
; r
< b
; ++r
)
3445 ready
= MAX2(ready
, score
->wr
.r
[r
]);
3447 case FILE_PREDICATE
:
3448 ready
= MAX2(ready
, score
->wr
.p
[v
->reg
.data
.id
]);
3451 assert(v
->reg
.file
== FILE_FLAGS
);
3452 ready
= MAX2(ready
, score
->wr
.c
);
3456 delay
= MAX2(delay
, ready
- cycle
);
3460 SchedDataCalculator::recordWr(const Value
*v
, const int ready
)
3462 int a
= v
->reg
.data
.id
;
3464 if (v
->reg
.file
== FILE_GPR
) {
3465 int b
= a
+ v
->reg
.size
/ 4;
3466 for (int r
= a
; r
< b
; ++r
)
3467 score
->rd
.r
[r
] = ready
;
3469 // $c, $pX: shorter issue-to-read delay (at least as exec pred and carry)
3470 if (v
->reg
.file
== FILE_PREDICATE
) {
3471 score
->rd
.p
[a
] = ready
+ 4;
3473 assert(v
->reg
.file
== FILE_FLAGS
);
3474 score
->rd
.c
= ready
+ 4;
3479 SchedDataCalculator::recordRd(const Value
*v
, const int ready
)
3481 int a
= v
->reg
.data
.id
;
3483 if (v
->reg
.file
== FILE_GPR
) {
3484 int b
= a
+ v
->reg
.size
/ 4;
3485 for (int r
= a
; r
< b
; ++r
)
3486 score
->wr
.r
[r
] = ready
;
3488 if (v
->reg
.file
== FILE_PREDICATE
) {
3489 score
->wr
.p
[a
] = ready
;
3491 if (v
->reg
.file
== FILE_FLAGS
) {
3492 score
->wr
.c
= ready
;
3497 calculateSchedDataNVC0(const Target
*targ
, Function
*func
)
3499 SchedDataCalculator
sched(targ
);
3500 return sched
.run(func
, true, true);
3504 CodeEmitterNVC0::prepareEmission(Function
*func
)
3506 CodeEmitter::prepareEmission(func
);
3508 if (targ
->hasSWSched
)
3509 calculateSchedDataNVC0(targ
, func
);
3512 CodeEmitterNVC0::CodeEmitterNVC0(const TargetNVC0
*target
)
3513 : CodeEmitter(target
),
3515 writeIssueDelays(target
->hasSWSched
)
3518 codeSize
= codeSizeLimit
= 0;
3523 TargetNVC0::createCodeEmitterNVC0(Program::Type type
)
3525 CodeEmitterNVC0
*emit
= new CodeEmitterNVC0(this);
3526 emit
->setProgramType(type
);
3531 TargetNVC0::getCodeEmitter(Program::Type type
)
3533 if (chipset
>= NVISA_GK20A_CHIPSET
)
3534 return createCodeEmitterGK110(type
);
3535 return createCodeEmitterNVC0(type
);
3538 } // namespace nv50_ir