2 * Copyright 2014 Red Hat Inc.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
25 #include "codegen/nv50_ir_target_gm107.h"
27 //#define GM107_DEBUG_SCHED_DATA
31 class CodeEmitterGM107
: public CodeEmitter
34 CodeEmitterGM107(const TargetGM107
*);
36 virtual bool emitInstruction(Instruction
*);
37 virtual uint32_t getMinEncodingSize(const Instruction
*) const;
39 virtual void prepareEmission(Program
*);
40 virtual void prepareEmission(Function
*);
42 inline void setProgramType(Program::Type pType
) { progType
= pType
; }
45 const TargetGM107
*targGM107
;
47 Program::Type progType
;
49 const Instruction
*insn
;
50 const bool writeIssueDelays
;
54 inline void emitField(uint32_t *, int, int, uint32_t);
55 inline void emitField(int b
, int s
, uint32_t v
) { emitField(code
, b
, s
, v
); }
57 inline void emitInsn(uint32_t, bool);
58 inline void emitInsn(uint32_t o
) { emitInsn(o
, true); }
59 inline void emitPred();
60 inline void emitGPR(int, const Value
*);
61 inline void emitGPR(int pos
) {
62 emitGPR(pos
, (const Value
*)NULL
);
64 inline void emitGPR(int pos
, const ValueRef
&ref
) {
65 emitGPR(pos
, ref
.get() ? ref
.rep() : (const Value
*)NULL
);
67 inline void emitGPR(int pos
, const ValueRef
*ref
) {
68 emitGPR(pos
, ref
? ref
->rep() : (const Value
*)NULL
);
70 inline void emitGPR(int pos
, const ValueDef
&def
) {
71 emitGPR(pos
, def
.get() ? def
.rep() : (const Value
*)NULL
);
73 inline void emitSYS(int, const Value
*);
74 inline void emitSYS(int pos
, const ValueRef
&ref
) {
75 emitSYS(pos
, ref
.get() ? ref
.rep() : (const Value
*)NULL
);
77 inline void emitPRED(int, const Value
*);
78 inline void emitPRED(int pos
) {
79 emitPRED(pos
, (const Value
*)NULL
);
81 inline void emitPRED(int pos
, const ValueRef
&ref
) {
82 emitPRED(pos
, ref
.get() ? ref
.rep() : (const Value
*)NULL
);
84 inline void emitPRED(int pos
, const ValueDef
&def
) {
85 emitPRED(pos
, def
.get() ? def
.rep() : (const Value
*)NULL
);
87 inline void emitADDR(int, int, int, int, const ValueRef
&);
88 inline void emitCBUF(int, int, int, int, int, const ValueRef
&);
89 inline bool longIMMD(const ValueRef
&);
90 inline void emitIMMD(int, int, const ValueRef
&);
92 void emitCond3(int, CondCode
);
93 void emitCond4(int, CondCode
);
94 void emitCond5(int pos
, CondCode cc
) { emitCond4(pos
, cc
); }
95 inline void emitO(int);
96 inline void emitP(int);
97 inline void emitSAT(int);
98 inline void emitCC(int);
99 inline void emitX(int);
100 inline void emitABS(int, const ValueRef
&);
101 inline void emitNEG(int, const ValueRef
&);
102 inline void emitNEG2(int, const ValueRef
&, const ValueRef
&);
103 inline void emitFMZ(int, int);
104 inline void emitRND(int, RoundMode
, int);
105 inline void emitRND(int pos
) {
106 emitRND(pos
, insn
->rnd
, -1);
108 inline void emitPDIV(int);
109 inline void emitINV(int, const ValueRef
&);
170 void emitLDSTs(int, DataType
);
210 void emitSUHandle(const int s
);
216 /*******************************************************************************
217 * general instruction layout/fields
218 ******************************************************************************/
221 CodeEmitterGM107::emitField(uint32_t *data
, int b
, int s
, uint32_t v
)
224 uint32_t m
= ((1ULL << s
) - 1);
225 uint64_t d
= (uint64_t)(v
& m
) << b
;
226 assert(!(v
& ~m
) || (v
& ~m
) == ~m
);
233 CodeEmitterGM107::emitPred()
235 if (insn
->predSrc
>= 0) {
236 emitField(16, 3, insn
->getSrc(insn
->predSrc
)->rep()->reg
.data
.id
);
237 emitField(19, 1, insn
->cc
== CC_NOT_P
);
244 CodeEmitterGM107::emitInsn(uint32_t hi
, bool pred
)
246 code
[0] = 0x00000000;
253 CodeEmitterGM107::emitGPR(int pos
, const Value
*val
)
255 emitField(pos
, 8, val
&& !val
->inFile(FILE_FLAGS
) ?
256 val
->reg
.data
.id
: 255);
260 CodeEmitterGM107::emitSYS(int pos
, const Value
*val
)
262 int id
= val
? val
->reg
.data
.id
: -1;
265 case SV_LANEID
: id
= 0x00; break;
266 case SV_VERTEX_COUNT
: id
= 0x10; break;
267 case SV_INVOCATION_ID
: id
= 0x11; break;
268 case SV_THREAD_KILL
: id
= 0x13; break;
269 case SV_INVOCATION_INFO
: id
= 0x1d; break;
270 case SV_TID
: id
= 0x21 + val
->reg
.data
.sv
.index
; break;
271 case SV_CTAID
: id
= 0x25 + val
->reg
.data
.sv
.index
; break;
273 assert(!"invalid system value");
278 emitField(pos
, 8, id
);
282 CodeEmitterGM107::emitPRED(int pos
, const Value
*val
)
284 emitField(pos
, 3, val
? val
->reg
.data
.id
: 7);
288 CodeEmitterGM107::emitADDR(int gpr
, int off
, int len
, int shr
,
291 const Value
*v
= ref
.get();
292 assert(!(v
->reg
.data
.offset
& ((1 << shr
) - 1)));
294 emitGPR(gpr
, ref
.getIndirect(0));
295 emitField(off
, len
, v
->reg
.data
.offset
>> shr
);
299 CodeEmitterGM107::emitCBUF(int buf
, int gpr
, int off
, int len
, int shr
,
302 const Value
*v
= ref
.get();
303 const Symbol
*s
= v
->asSym();
305 assert(!(s
->reg
.data
.offset
& ((1 << shr
) - 1)));
307 emitField(buf
, 5, v
->reg
.fileIndex
);
309 emitGPR(gpr
, ref
.getIndirect(0));
310 emitField(off
, 16, s
->reg
.data
.offset
>> shr
);
314 CodeEmitterGM107::longIMMD(const ValueRef
&ref
)
316 if (ref
.getFile() == FILE_IMMEDIATE
) {
317 const ImmediateValue
*imm
= ref
.get()->asImm();
318 if (isFloatType(insn
->sType
)) {
319 if ((imm
->reg
.data
.u32
& 0x00000fff) != 0x00000000)
322 if ((imm
->reg
.data
.u32
& 0xfff00000) != 0x00000000 &&
323 (imm
->reg
.data
.u32
& 0xfff00000) != 0xfff00000)
331 CodeEmitterGM107::emitIMMD(int pos
, int len
, const ValueRef
&ref
)
333 const ImmediateValue
*imm
= ref
.get()->asImm();
334 uint32_t val
= imm
->reg
.data
.u32
;
337 if (insn
->sType
== TYPE_F32
|| insn
->sType
== TYPE_F16
) {
338 assert(!(val
& 0x00000fff));
340 } else if (insn
->sType
== TYPE_F64
) {
341 assert(!(imm
->reg
.data
.u64
& 0x00000fffffffffffULL
));
342 val
= imm
->reg
.data
.u64
>> 44;
344 assert(!(val
& 0xfff00000) || (val
& 0xfff00000) == 0xfff00000);
345 emitField( 56, 1, (val
& 0x80000) >> 19);
346 emitField(pos
, len
, (val
& 0x7ffff));
348 emitField(pos
, len
, val
);
352 /*******************************************************************************
354 ******************************************************************************/
357 CodeEmitterGM107::emitCond3(int pos
, CondCode code
)
362 case CC_FL
: data
= 0x00; break;
364 case CC_LT
: data
= 0x01; break;
366 case CC_EQ
: data
= 0x02; break;
368 case CC_LE
: data
= 0x03; break;
370 case CC_GT
: data
= 0x04; break;
372 case CC_NE
: data
= 0x05; break;
374 case CC_GE
: data
= 0x06; break;
375 case CC_TR
: data
= 0x07; break;
377 assert(!"invalid cond3");
381 emitField(pos
, 3, data
);
385 CodeEmitterGM107::emitCond4(int pos
, CondCode code
)
390 case CC_FL
: data
= 0x00; break;
391 case CC_LT
: data
= 0x01; break;
392 case CC_EQ
: data
= 0x02; break;
393 case CC_LE
: data
= 0x03; break;
394 case CC_GT
: data
= 0x04; break;
395 case CC_NE
: data
= 0x05; break;
396 case CC_GE
: data
= 0x06; break;
397 // case CC_NUM: data = 0x07; break;
398 // case CC_NAN: data = 0x08; break;
399 case CC_LTU
: data
= 0x09; break;
400 case CC_EQU
: data
= 0x0a; break;
401 case CC_LEU
: data
= 0x0b; break;
402 case CC_GTU
: data
= 0x0c; break;
403 case CC_NEU
: data
= 0x0d; break;
404 case CC_GEU
: data
= 0x0e; break;
405 case CC_TR
: data
= 0x0f; break;
407 assert(!"invalid cond4");
411 emitField(pos
, 4, data
);
415 CodeEmitterGM107::emitO(int pos
)
417 emitField(pos
, 1, insn
->getSrc(0)->reg
.file
== FILE_SHADER_OUTPUT
);
421 CodeEmitterGM107::emitP(int pos
)
423 emitField(pos
, 1, insn
->perPatch
);
427 CodeEmitterGM107::emitSAT(int pos
)
429 emitField(pos
, 1, insn
->saturate
);
433 CodeEmitterGM107::emitCC(int pos
)
435 emitField(pos
, 1, insn
->flagsDef
>= 0);
439 CodeEmitterGM107::emitX(int pos
)
441 emitField(pos
, 1, insn
->flagsSrc
>= 0);
445 CodeEmitterGM107::emitABS(int pos
, const ValueRef
&ref
)
447 emitField(pos
, 1, ref
.mod
.abs());
451 CodeEmitterGM107::emitNEG(int pos
, const ValueRef
&ref
)
453 emitField(pos
, 1, ref
.mod
.neg());
457 CodeEmitterGM107::emitNEG2(int pos
, const ValueRef
&a
, const ValueRef
&b
)
459 emitField(pos
, 1, a
.mod
.neg() ^ b
.mod
.neg());
463 CodeEmitterGM107::emitFMZ(int pos
, int len
)
465 emitField(pos
, len
, insn
->dnz
<< 1 | insn
->ftz
);
469 CodeEmitterGM107::emitRND(int rmp
, RoundMode rnd
, int rip
)
473 case ROUND_NI
: ri
= 1;
474 case ROUND_N
: rm
= 0; break;
475 case ROUND_MI
: ri
= 1;
476 case ROUND_M
: rm
= 1; break;
477 case ROUND_PI
: ri
= 1;
478 case ROUND_P
: rm
= 2; break;
479 case ROUND_ZI
: ri
= 1;
480 case ROUND_Z
: rm
= 3; break;
482 assert(!"invalid round mode");
485 emitField(rip
, 1, ri
);
486 emitField(rmp
, 2, rm
);
490 CodeEmitterGM107::emitPDIV(int pos
)
492 assert(insn
->postFactor
>= -3 && insn
->postFactor
<= 3);
493 if (insn
->postFactor
> 0)
494 emitField(pos
, 3, 7 - insn
->postFactor
);
496 emitField(pos
, 3, 0 - insn
->postFactor
);
500 CodeEmitterGM107::emitINV(int pos
, const ValueRef
&ref
)
502 emitField(pos
, 1, !!(ref
.mod
& Modifier(NV50_IR_MOD_NOT
)));
505 /*******************************************************************************
507 ******************************************************************************/
510 CodeEmitterGM107::emitEXIT()
512 emitInsn (0xe3000000);
513 emitCond5(0x00, CC_TR
);
517 CodeEmitterGM107::emitBRA()
519 const FlowInstruction
*insn
= this->insn
->asFlow();
522 if (insn
->indirect
) {
524 emitInsn(0xe2000000); // JMX
526 emitInsn(0xe2500000); // BRX
530 emitInsn(0xe2100000); // JMP
532 emitInsn(0xe2400000); // BRA
533 emitField(0x07, 1, insn
->allWarp
);
536 emitField(0x06, 1, insn
->limit
);
537 emitCond5(0x00, CC_TR
);
539 if (!insn
->srcExists(0) || insn
->src(0).getFile() != FILE_MEMORY_CONST
) {
540 int32_t pos
= insn
->target
.bb
->binPos
;
541 if (writeIssueDelays
&& !(pos
& 0x1f))
544 emitField(0x14, 24, pos
- (codeSize
+ 8));
546 emitField(0x14, 32, pos
);
548 emitCBUF (0x24, gpr
, 20, 16, 0, insn
->src(0));
549 emitField(0x05, 1, 1);
554 CodeEmitterGM107::emitCAL()
556 const FlowInstruction
*insn
= this->insn
->asFlow();
558 if (insn
->absolute
) {
559 emitInsn(0xe2200000, 0); // JCAL
561 emitInsn(0xe2600000, 0); // CAL
564 if (!insn
->srcExists(0) || insn
->src(0).getFile() != FILE_MEMORY_CONST
) {
566 emitField(0x14, 24, insn
->target
.bb
->binPos
- (codeSize
+ 8));
569 int pcAbs
= targGM107
->getBuiltinOffset(insn
->target
.builtin
);
570 addReloc(RelocEntry::TYPE_BUILTIN
, 0, pcAbs
, 0xfff00000, 20);
571 addReloc(RelocEntry::TYPE_BUILTIN
, 1, pcAbs
, 0x000fffff, -12);
573 emitField(0x14, 32, insn
->target
.bb
->binPos
);
577 emitCBUF (0x24, -1, 20, 16, 0, insn
->src(0));
578 emitField(0x05, 1, 1);
583 CodeEmitterGM107::emitPCNT()
585 const FlowInstruction
*insn
= this->insn
->asFlow();
587 emitInsn(0xe2b00000, 0);
589 if (!insn
->srcExists(0) || insn
->src(0).getFile() != FILE_MEMORY_CONST
) {
590 emitField(0x14, 24, insn
->target
.bb
->binPos
- (codeSize
+ 8));
592 emitCBUF (0x24, -1, 20, 16, 0, insn
->src(0));
593 emitField(0x05, 1, 1);
598 CodeEmitterGM107::emitCONT()
600 emitInsn (0xe3500000);
601 emitCond5(0x00, CC_TR
);
605 CodeEmitterGM107::emitPBK()
607 const FlowInstruction
*insn
= this->insn
->asFlow();
609 emitInsn(0xe2a00000, 0);
611 if (!insn
->srcExists(0) || insn
->src(0).getFile() != FILE_MEMORY_CONST
) {
612 emitField(0x14, 24, insn
->target
.bb
->binPos
- (codeSize
+ 8));
614 emitCBUF (0x24, -1, 20, 16, 0, insn
->src(0));
615 emitField(0x05, 1, 1);
620 CodeEmitterGM107::emitBRK()
622 emitInsn (0xe3400000);
623 emitCond5(0x00, CC_TR
);
627 CodeEmitterGM107::emitPRET()
629 const FlowInstruction
*insn
= this->insn
->asFlow();
631 emitInsn(0xe2700000, 0);
633 if (!insn
->srcExists(0) || insn
->src(0).getFile() != FILE_MEMORY_CONST
) {
634 emitField(0x14, 24, insn
->target
.bb
->binPos
- (codeSize
+ 8));
636 emitCBUF (0x24, -1, 20, 16, 0, insn
->src(0));
637 emitField(0x05, 1, 1);
642 CodeEmitterGM107::emitRET()
644 emitInsn (0xe3200000);
645 emitCond5(0x00, CC_TR
);
649 CodeEmitterGM107::emitSSY()
651 const FlowInstruction
*insn
= this->insn
->asFlow();
653 emitInsn(0xe2900000, 0);
655 if (!insn
->srcExists(0) || insn
->src(0).getFile() != FILE_MEMORY_CONST
) {
656 emitField(0x14, 24, insn
->target
.bb
->binPos
- (codeSize
+ 8));
658 emitCBUF (0x24, -1, 20, 16, 0, insn
->src(0));
659 emitField(0x05, 1, 1);
664 CodeEmitterGM107::emitSYNC()
666 emitInsn (0xf0f80000);
667 emitCond5(0x00, CC_TR
);
671 CodeEmitterGM107::emitSAM()
673 emitInsn(0xe3700000, 0);
677 CodeEmitterGM107::emitRAM()
679 emitInsn(0xe3800000, 0);
682 /*******************************************************************************
684 ******************************************************************************/
686 /*******************************************************************************
687 * movement / conversion
688 ******************************************************************************/
691 CodeEmitterGM107::emitMOV()
693 if (insn
->src(0).getFile() != FILE_IMMEDIATE
) {
694 switch (insn
->src(0).getFile()) {
696 if (insn
->def(0).getFile() == FILE_PREDICATE
) {
697 emitInsn(0x5b6a0000);
700 emitInsn(0x5c980000);
702 emitGPR (0x14, insn
->src(0));
704 case FILE_MEMORY_CONST
:
705 emitInsn(0x4c980000);
706 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
709 emitInsn(0x38980000);
710 emitIMMD(0x14, 19, insn
->src(0));
713 emitInsn(0x50880000);
714 emitPRED(0x0c, insn
->src(0));
719 assert(!"bad src file");
722 if (insn
->def(0).getFile() != FILE_PREDICATE
&&
723 insn
->src(0).getFile() != FILE_PREDICATE
)
724 emitField(0x27, 4, insn
->lanes
);
726 emitInsn (0x01000000);
727 emitIMMD (0x14, 32, insn
->src(0));
728 emitField(0x0c, 4, insn
->lanes
);
731 if (insn
->def(0).getFile() == FILE_PREDICATE
) {
733 emitPRED(0x03, insn
->def(0));
736 emitGPR(0x00, insn
->def(0));
741 CodeEmitterGM107::emitS2R()
743 emitInsn(0xf0c80000);
744 emitSYS (0x14, insn
->src(0));
745 emitGPR (0x00, insn
->def(0));
749 CodeEmitterGM107::emitF2F()
751 RoundMode rnd
= insn
->rnd
;
754 case OP_FLOOR
: rnd
= ROUND_MI
; break;
755 case OP_CEIL
: rnd
= ROUND_PI
; break;
756 case OP_TRUNC
: rnd
= ROUND_ZI
; break;
761 switch (insn
->src(0).getFile()) {
763 emitInsn(0x5ca80000);
764 emitGPR (0x14, insn
->src(0));
766 case FILE_MEMORY_CONST
:
767 emitInsn(0x4ca80000);
768 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
771 emitInsn(0x38a80000);
772 emitIMMD(0x14, 19, insn
->src(0));
775 assert(!"bad src0 file");
779 emitField(0x32, 1, (insn
->op
== OP_SAT
) || insn
->saturate
);
780 emitField(0x31, 1, (insn
->op
== OP_ABS
) || insn
->src(0).mod
.abs());
782 emitField(0x2d, 1, (insn
->op
== OP_NEG
) || insn
->src(0).mod
.neg());
784 emitField(0x29, 1, insn
->subOp
);
785 emitRND (0x27, rnd
, 0x2a);
786 emitField(0x0a, 2, util_logbase2(typeSizeof(insn
->sType
)));
787 emitField(0x08, 2, util_logbase2(typeSizeof(insn
->dType
)));
788 emitGPR (0x00, insn
->def(0));
792 CodeEmitterGM107::emitF2I()
794 RoundMode rnd
= insn
->rnd
;
797 case OP_FLOOR
: rnd
= ROUND_M
; break;
798 case OP_CEIL
: rnd
= ROUND_P
; break;
799 case OP_TRUNC
: rnd
= ROUND_Z
; break;
804 switch (insn
->src(0).getFile()) {
806 emitInsn(0x5cb00000);
807 emitGPR (0x14, insn
->src(0));
809 case FILE_MEMORY_CONST
:
810 emitInsn(0x4cb00000);
811 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
814 emitInsn(0x38b00000);
815 emitIMMD(0x14, 19, insn
->src(0));
818 assert(!"bad src0 file");
822 emitField(0x31, 1, (insn
->op
== OP_ABS
) || insn
->src(0).mod
.abs());
824 emitField(0x2d, 1, (insn
->op
== OP_NEG
) || insn
->src(0).mod
.neg());
826 emitRND (0x27, rnd
, 0x2a);
827 emitField(0x0c, 1, isSignedType(insn
->dType
));
828 emitField(0x0a, 2, util_logbase2(typeSizeof(insn
->sType
)));
829 emitField(0x08, 2, util_logbase2(typeSizeof(insn
->dType
)));
830 emitGPR (0x00, insn
->def(0));
834 CodeEmitterGM107::emitI2F()
836 RoundMode rnd
= insn
->rnd
;
839 case OP_FLOOR
: rnd
= ROUND_M
; break;
840 case OP_CEIL
: rnd
= ROUND_P
; break;
841 case OP_TRUNC
: rnd
= ROUND_Z
; break;
846 switch (insn
->src(0).getFile()) {
848 emitInsn(0x5cb80000);
849 emitGPR (0x14, insn
->src(0));
851 case FILE_MEMORY_CONST
:
852 emitInsn(0x4cb80000);
853 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
856 emitInsn(0x38b80000);
857 emitIMMD(0x14, 19, insn
->src(0));
860 assert(!"bad src0 file");
864 emitField(0x31, 1, (insn
->op
== OP_ABS
) || insn
->src(0).mod
.abs());
866 emitField(0x2d, 1, (insn
->op
== OP_NEG
) || insn
->src(0).mod
.neg());
867 emitField(0x29, 2, insn
->subOp
);
868 emitRND (0x27, rnd
, -1);
869 emitField(0x0d, 1, isSignedType(insn
->sType
));
870 emitField(0x0a, 2, util_logbase2(typeSizeof(insn
->sType
)));
871 emitField(0x08, 2, util_logbase2(typeSizeof(insn
->dType
)));
872 emitGPR (0x00, insn
->def(0));
876 CodeEmitterGM107::emitI2I()
878 switch (insn
->src(0).getFile()) {
880 emitInsn(0x5ce00000);
881 emitGPR (0x14, insn
->src(0));
883 case FILE_MEMORY_CONST
:
884 emitInsn(0x4ce00000);
885 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
888 emitInsn(0x38e00000);
889 emitIMMD(0x14, 19, insn
->src(0));
892 assert(!"bad src0 file");
897 emitField(0x31, 1, (insn
->op
== OP_ABS
) || insn
->src(0).mod
.abs());
899 emitField(0x2d, 1, (insn
->op
== OP_NEG
) || insn
->src(0).mod
.neg());
900 emitField(0x29, 2, insn
->subOp
);
901 emitField(0x0d, 1, isSignedType(insn
->sType
));
902 emitField(0x0c, 1, isSignedType(insn
->dType
));
903 emitField(0x0a, 2, util_logbase2(typeSizeof(insn
->sType
)));
904 emitField(0x08, 2, util_logbase2(typeSizeof(insn
->dType
)));
905 emitGPR (0x00, insn
->def(0));
909 selpFlip(const FixupEntry
*entry
, uint32_t *code
, const FixupData
& data
)
911 int loc
= entry
->loc
;
912 if (data
.force_persample_interp
)
913 code
[loc
+ 1] |= 1 << 10;
915 code
[loc
+ 1] &= ~(1 << 10);
919 CodeEmitterGM107::emitSEL()
921 switch (insn
->src(1).getFile()) {
923 emitInsn(0x5ca00000);
924 emitGPR (0x14, insn
->src(1));
926 case FILE_MEMORY_CONST
:
927 emitInsn(0x4ca00000);
928 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
931 emitInsn(0x38a00000);
932 emitIMMD(0x14, 19, insn
->src(1));
935 assert(!"bad src1 file");
939 emitINV (0x2a, insn
->src(2));
940 emitPRED(0x27, insn
->src(2));
941 emitGPR (0x08, insn
->src(0));
942 emitGPR (0x00, insn
->def(0));
944 if (insn
->subOp
== 1) {
945 addInterp(0, 0, selpFlip
);
950 CodeEmitterGM107::emitSHFL()
954 emitInsn (0xef100000);
956 switch (insn
->src(1).getFile()) {
958 emitGPR(0x14, insn
->src(1));
961 emitIMMD(0x14, 5, insn
->src(1));
965 assert(!"invalid src1 file");
969 /*XXX: what is this arg? hardcode immediate for now */
970 emitField(0x22, 13, 0x1c03);
974 emitField(0x1e, 2, insn
->subOp
);
975 emitField(0x1c, 2, type
);
976 emitGPR (0x08, insn
->src(0));
977 emitGPR (0x00, insn
->def(0));
980 /*******************************************************************************
982 ******************************************************************************/
985 CodeEmitterGM107::emitDADD()
987 switch (insn
->src(1).getFile()) {
989 emitInsn(0x5c700000);
990 emitGPR (0x14, insn
->src(1));
992 case FILE_MEMORY_CONST
:
993 emitInsn(0x4c700000);
994 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
997 emitInsn(0x38700000);
998 emitIMMD(0x14, 19, insn
->src(1));
1001 assert(!"bad src1 file");
1004 emitABS(0x31, insn
->src(1));
1005 emitNEG(0x30, insn
->src(0));
1007 emitABS(0x2e, insn
->src(0));
1008 emitNEG(0x2d, insn
->src(1));
1010 if (insn
->op
== OP_SUB
)
1011 code
[1] ^= 0x00002000;
1013 emitGPR(0x08, insn
->src(0));
1014 emitGPR(0x00, insn
->def(0));
1018 CodeEmitterGM107::emitDMUL()
1020 switch (insn
->src(1).getFile()) {
1022 emitInsn(0x5c800000);
1023 emitGPR (0x14, insn
->src(1));
1025 case FILE_MEMORY_CONST
:
1026 emitInsn(0x4c800000);
1027 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1029 case FILE_IMMEDIATE
:
1030 emitInsn(0x38800000);
1031 emitIMMD(0x14, 19, insn
->src(1));
1034 assert(!"bad src1 file");
1038 emitNEG2(0x30, insn
->src(0), insn
->src(1));
1041 emitGPR (0x08, insn
->src(0));
1042 emitGPR (0x00, insn
->def(0));
1046 CodeEmitterGM107::emitDFMA()
1048 switch(insn
->src(2).getFile()) {
1050 switch (insn
->src(1).getFile()) {
1052 emitInsn(0x5b700000);
1053 emitGPR (0x14, insn
->src(1));
1055 case FILE_MEMORY_CONST
:
1056 emitInsn(0x4b700000);
1057 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1059 case FILE_IMMEDIATE
:
1060 emitInsn(0x36700000);
1061 emitIMMD(0x14, 19, insn
->src(1));
1064 assert(!"bad src1 file");
1067 emitGPR (0x27, insn
->src(2));
1069 case FILE_MEMORY_CONST
:
1070 emitInsn(0x53700000);
1071 emitGPR (0x27, insn
->src(1));
1072 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
1075 assert(!"bad src2 file");
1080 emitNEG (0x31, insn
->src(2));
1081 emitNEG2(0x30, insn
->src(0), insn
->src(1));
1083 emitGPR (0x08, insn
->src(0));
1084 emitGPR (0x00, insn
->def(0));
1088 CodeEmitterGM107::emitDMNMX()
1090 switch (insn
->src(1).getFile()) {
1092 emitInsn(0x5c500000);
1093 emitGPR (0x14, insn
->src(1));
1095 case FILE_MEMORY_CONST
:
1096 emitInsn(0x4c500000);
1097 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1099 case FILE_IMMEDIATE
:
1100 emitInsn(0x38500000);
1101 emitIMMD(0x14, 19, insn
->src(1));
1104 assert(!"bad src1 file");
1108 emitABS (0x31, insn
->src(1));
1109 emitNEG (0x30, insn
->src(0));
1111 emitABS (0x2e, insn
->src(0));
1112 emitNEG (0x2d, insn
->src(1));
1113 emitField(0x2a, 1, insn
->op
== OP_MAX
);
1115 emitGPR (0x08, insn
->src(0));
1116 emitGPR (0x00, insn
->def(0));
1120 CodeEmitterGM107::emitDSET()
1122 const CmpInstruction
*insn
= this->insn
->asCmp();
1124 switch (insn
->src(1).getFile()) {
1126 emitInsn(0x59000000);
1127 emitGPR (0x14, insn
->src(1));
1129 case FILE_MEMORY_CONST
:
1130 emitInsn(0x49000000);
1131 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1133 case FILE_IMMEDIATE
:
1134 emitInsn(0x32000000);
1135 emitIMMD(0x14, 19, insn
->src(1));
1138 assert(!"bad src1 file");
1142 if (insn
->op
!= OP_SET
) {
1144 case OP_SET_AND
: emitField(0x2d, 2, 0); break;
1145 case OP_SET_OR
: emitField(0x2d, 2, 1); break;
1146 case OP_SET_XOR
: emitField(0x2d, 2, 2); break;
1148 assert(!"invalid set op");
1151 emitPRED(0x27, insn
->src(2));
1156 emitABS (0x36, insn
->src(0));
1157 emitNEG (0x35, insn
->src(1));
1158 emitField(0x34, 1, insn
->dType
== TYPE_F32
);
1159 emitCond4(0x30, insn
->setCond
);
1161 emitABS (0x2c, insn
->src(1));
1162 emitNEG (0x2b, insn
->src(0));
1163 emitGPR (0x08, insn
->src(0));
1164 emitGPR (0x00, insn
->def(0));
1168 CodeEmitterGM107::emitDSETP()
1170 const CmpInstruction
*insn
= this->insn
->asCmp();
1172 switch (insn
->src(1).getFile()) {
1174 emitInsn(0x5b800000);
1175 emitGPR (0x14, insn
->src(1));
1177 case FILE_MEMORY_CONST
:
1178 emitInsn(0x4b800000);
1179 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1181 case FILE_IMMEDIATE
:
1182 emitInsn(0x36800000);
1183 emitIMMD(0x14, 19, insn
->src(1));
1186 assert(!"bad src1 file");
1190 if (insn
->op
!= OP_SET
) {
1192 case OP_SET_AND
: emitField(0x2d, 2, 0); break;
1193 case OP_SET_OR
: emitField(0x2d, 2, 1); break;
1194 case OP_SET_XOR
: emitField(0x2d, 2, 2); break;
1196 assert(!"invalid set op");
1199 emitPRED(0x27, insn
->src(2));
1204 emitCond4(0x30, insn
->setCond
);
1205 emitABS (0x2c, insn
->src(1));
1206 emitNEG (0x2b, insn
->src(0));
1207 emitGPR (0x08, insn
->src(0));
1208 emitABS (0x07, insn
->src(0));
1209 emitNEG (0x06, insn
->src(1));
1210 emitPRED (0x03, insn
->def(0));
1211 if (insn
->defExists(1))
1212 emitPRED(0x00, insn
->def(1));
1217 /*******************************************************************************
1219 ******************************************************************************/
1222 CodeEmitterGM107::emitFADD()
1224 if (!longIMMD(insn
->src(1))) {
1225 switch (insn
->src(1).getFile()) {
1227 emitInsn(0x5c580000);
1228 emitGPR (0x14, insn
->src(1));
1230 case FILE_MEMORY_CONST
:
1231 emitInsn(0x4c580000);
1232 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1234 case FILE_IMMEDIATE
:
1235 emitInsn(0x38580000);
1236 emitIMMD(0x14, 19, insn
->src(1));
1239 assert(!"bad src1 file");
1243 emitABS(0x31, insn
->src(1));
1244 emitNEG(0x30, insn
->src(0));
1246 emitABS(0x2e, insn
->src(0));
1247 emitNEG(0x2d, insn
->src(1));
1250 if (insn
->op
== OP_SUB
)
1251 code
[1] ^= 0x00002000;
1253 emitInsn(0x08000000);
1254 emitABS(0x39, insn
->src(1));
1255 emitNEG(0x38, insn
->src(0));
1257 emitABS(0x36, insn
->src(0));
1258 emitNEG(0x35, insn
->src(1));
1260 emitIMMD(0x14, 32, insn
->src(1));
1262 if (insn
->op
== OP_SUB
)
1263 code
[1] ^= 0x00080000;
1266 emitGPR(0x08, insn
->src(0));
1267 emitGPR(0x00, insn
->def(0));
1271 CodeEmitterGM107::emitFMUL()
1273 if (!longIMMD(insn
->src(1))) {
1274 switch (insn
->src(1).getFile()) {
1276 emitInsn(0x5c680000);
1277 emitGPR (0x14, insn
->src(1));
1279 case FILE_MEMORY_CONST
:
1280 emitInsn(0x4c680000);
1281 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1283 case FILE_IMMEDIATE
:
1284 emitInsn(0x38680000);
1285 emitIMMD(0x14, 19, insn
->src(1));
1288 assert(!"bad src1 file");
1292 emitNEG2(0x30, insn
->src(0), insn
->src(1));
1298 emitInsn(0x1e000000);
1302 emitIMMD(0x14, 32, insn
->src(1));
1303 if (insn
->src(0).mod
.neg() ^ insn
->src(1).mod
.neg())
1304 code
[1] ^= 0x00080000; /* flip immd sign bit */
1307 emitGPR(0x08, insn
->src(0));
1308 emitGPR(0x00, insn
->def(0));
1312 CodeEmitterGM107::emitFFMA()
1314 /*XXX: ffma32i exists, but not using it as third src overlaps dst */
1315 switch(insn
->src(2).getFile()) {
1317 switch (insn
->src(1).getFile()) {
1319 emitInsn(0x59800000);
1320 emitGPR (0x14, insn
->src(1));
1322 case FILE_MEMORY_CONST
:
1323 emitInsn(0x49800000);
1324 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1326 case FILE_IMMEDIATE
:
1327 emitInsn(0x32800000);
1328 emitIMMD(0x14, 19, insn
->src(1));
1331 assert(!"bad src1 file");
1334 emitGPR (0x27, insn
->src(2));
1336 case FILE_MEMORY_CONST
:
1337 emitInsn(0x51800000);
1338 emitGPR (0x27, insn
->src(1));
1339 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
1342 assert(!"bad src2 file");
1347 emitNEG (0x31, insn
->src(2));
1348 emitNEG2(0x30, insn
->src(0), insn
->src(1));
1352 emitGPR(0x08, insn
->src(0));
1353 emitGPR(0x00, insn
->def(0));
1357 CodeEmitterGM107::emitMUFU()
1362 case OP_COS
: mufu
= 0; break;
1363 case OP_SIN
: mufu
= 1; break;
1364 case OP_EX2
: mufu
= 2; break;
1365 case OP_LG2
: mufu
= 3; break;
1366 case OP_RCP
: mufu
= 4 + 2 * insn
->subOp
; break;
1367 case OP_RSQ
: mufu
= 5 + 2 * insn
->subOp
; break;
1369 assert(!"invalid mufu");
1373 emitInsn (0x50800000);
1375 emitNEG (0x30, insn
->src(0));
1376 emitABS (0x2e, insn
->src(0));
1377 emitField(0x14, 3, mufu
);
1378 emitGPR (0x08, insn
->src(0));
1379 emitGPR (0x00, insn
->def(0));
1383 CodeEmitterGM107::emitFMNMX()
1385 switch (insn
->src(1).getFile()) {
1387 emitInsn(0x5c600000);
1388 emitGPR (0x14, insn
->src(1));
1390 case FILE_MEMORY_CONST
:
1391 emitInsn(0x4c600000);
1392 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1394 case FILE_IMMEDIATE
:
1395 emitInsn(0x38600000);
1396 emitIMMD(0x14, 19, insn
->src(1));
1399 assert(!"bad src1 file");
1403 emitField(0x2a, 1, insn
->op
== OP_MAX
);
1406 emitABS(0x31, insn
->src(1));
1407 emitNEG(0x30, insn
->src(0));
1409 emitABS(0x2e, insn
->src(0));
1410 emitNEG(0x2d, insn
->src(1));
1412 emitGPR(0x08, insn
->src(0));
1413 emitGPR(0x00, insn
->def(0));
1417 CodeEmitterGM107::emitRRO()
1419 switch (insn
->src(0).getFile()) {
1421 emitInsn(0x5c900000);
1422 emitGPR (0x14, insn
->src(0));
1424 case FILE_MEMORY_CONST
:
1425 emitInsn(0x4c900000);
1426 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
1428 case FILE_IMMEDIATE
:
1429 emitInsn(0x38900000);
1430 emitIMMD(0x14, 19, insn
->src(0));
1433 assert(!"bad src file");
1437 emitABS (0x31, insn
->src(0));
1438 emitNEG (0x2d, insn
->src(0));
1439 emitField(0x27, 1, insn
->op
== OP_PREEX2
);
1440 emitGPR (0x00, insn
->def(0));
1444 CodeEmitterGM107::emitFCMP()
1446 const CmpInstruction
*insn
= this->insn
->asCmp();
1447 CondCode cc
= insn
->setCond
;
1449 if (insn
->src(2).mod
.neg())
1450 cc
= reverseCondCode(cc
);
1452 switch(insn
->src(2).getFile()) {
1454 switch (insn
->src(1).getFile()) {
1456 emitInsn(0x5ba00000);
1457 emitGPR (0x14, insn
->src(1));
1459 case FILE_MEMORY_CONST
:
1460 emitInsn(0x4ba00000);
1461 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1463 case FILE_IMMEDIATE
:
1464 emitInsn(0x36a00000);
1465 emitIMMD(0x14, 19, insn
->src(1));
1468 assert(!"bad src1 file");
1471 emitGPR (0x27, insn
->src(2));
1473 case FILE_MEMORY_CONST
:
1474 emitInsn(0x53a00000);
1475 emitGPR (0x27, insn
->src(1));
1476 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
1479 assert(!"bad src2 file");
1483 emitCond4(0x30, cc
);
1485 emitGPR (0x08, insn
->src(0));
1486 emitGPR (0x00, insn
->def(0));
1490 CodeEmitterGM107::emitFSET()
1492 const CmpInstruction
*insn
= this->insn
->asCmp();
1494 switch (insn
->src(1).getFile()) {
1496 emitInsn(0x58000000);
1497 emitGPR (0x14, insn
->src(1));
1499 case FILE_MEMORY_CONST
:
1500 emitInsn(0x48000000);
1501 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1503 case FILE_IMMEDIATE
:
1504 emitInsn(0x30000000);
1505 emitIMMD(0x14, 19, insn
->src(1));
1508 assert(!"bad src1 file");
1512 if (insn
->op
!= OP_SET
) {
1514 case OP_SET_AND
: emitField(0x2d, 2, 0); break;
1515 case OP_SET_OR
: emitField(0x2d, 2, 1); break;
1516 case OP_SET_XOR
: emitField(0x2d, 2, 2); break;
1518 assert(!"invalid set op");
1521 emitPRED(0x27, insn
->src(2));
1527 emitABS (0x36, insn
->src(0));
1528 emitNEG (0x35, insn
->src(1));
1529 emitField(0x34, 1, insn
->dType
== TYPE_F32
);
1530 emitCond4(0x30, insn
->setCond
);
1532 emitABS (0x2c, insn
->src(1));
1533 emitNEG (0x2b, insn
->src(0));
1534 emitGPR (0x08, insn
->src(0));
1535 emitGPR (0x00, insn
->def(0));
1539 CodeEmitterGM107::emitFSETP()
1541 const CmpInstruction
*insn
= this->insn
->asCmp();
1543 switch (insn
->src(1).getFile()) {
1545 emitInsn(0x5bb00000);
1546 emitGPR (0x14, insn
->src(1));
1548 case FILE_MEMORY_CONST
:
1549 emitInsn(0x4bb00000);
1550 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1552 case FILE_IMMEDIATE
:
1553 emitInsn(0x36b00000);
1554 emitIMMD(0x14, 19, insn
->src(1));
1557 assert(!"bad src1 file");
1561 if (insn
->op
!= OP_SET
) {
1563 case OP_SET_AND
: emitField(0x2d, 2, 0); break;
1564 case OP_SET_OR
: emitField(0x2d, 2, 1); break;
1565 case OP_SET_XOR
: emitField(0x2d, 2, 2); break;
1567 assert(!"invalid set op");
1570 emitPRED(0x27, insn
->src(2));
1575 emitCond4(0x30, insn
->setCond
);
1577 emitABS (0x2c, insn
->src(1));
1578 emitNEG (0x2b, insn
->src(0));
1579 emitGPR (0x08, insn
->src(0));
1580 emitABS (0x07, insn
->src(0));
1581 emitNEG (0x06, insn
->src(1));
1582 emitPRED (0x03, insn
->def(0));
1583 if (insn
->defExists(1))
1584 emitPRED(0x00, insn
->def(1));
1590 CodeEmitterGM107::emitFSWZADD()
1592 emitInsn (0x50f80000);
1596 emitField(0x26, 1, insn
->lanes
); /* abused for .ndv */
1597 emitField(0x1c, 8, insn
->subOp
);
1598 if (insn
->predSrc
!= 1)
1599 emitGPR (0x14, insn
->src(1));
1602 emitGPR (0x08, insn
->src(0));
1603 emitGPR (0x00, insn
->def(0));
1606 /*******************************************************************************
1608 ******************************************************************************/
1611 CodeEmitterGM107::emitLOP()
1616 case OP_AND
: lop
= 0; break;
1617 case OP_OR
: lop
= 1; break;
1618 case OP_XOR
: lop
= 2; break;
1620 assert(!"invalid lop");
1624 if (insn
->src(1).getFile() != FILE_IMMEDIATE
) {
1625 switch (insn
->src(1).getFile()) {
1627 emitInsn(0x5c400000);
1628 emitGPR (0x14, insn
->src(1));
1630 case FILE_MEMORY_CONST
:
1631 emitInsn(0x4c400000);
1632 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1634 case FILE_IMMEDIATE
:
1635 emitInsn(0x38400000);
1636 emitIMMD(0x14, 19, insn
->src(1));
1639 assert(!"bad src1 file");
1645 emitField(0x29, 2, lop
);
1646 emitINV (0x28, insn
->src(1));
1647 emitINV (0x27, insn
->src(0));
1649 emitInsn (0x04000000);
1651 emitINV (0x38, insn
->src(1));
1652 emitINV (0x37, insn
->src(0));
1653 emitField(0x35, 2, lop
);
1655 emitIMMD (0x14, 32, insn
->src(1));
1658 emitGPR (0x08, insn
->src(0));
1659 emitGPR (0x00, insn
->def(0));
1662 /* special-case of emitLOP(): lop pass_b dst 0 ~src */
1664 CodeEmitterGM107::emitNOT()
1666 if (!longIMMD(insn
->src(0))) {
1667 switch (insn
->src(0).getFile()) {
1669 emitInsn(0x5c400700);
1670 emitGPR (0x14, insn
->src(0));
1672 case FILE_MEMORY_CONST
:
1673 emitInsn(0x4c400700);
1674 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
1676 case FILE_IMMEDIATE
:
1677 emitInsn(0x38400700);
1678 emitIMMD(0x14, 19, insn
->src(0));
1681 assert(!"bad src1 file");
1686 emitInsn (0x05600000);
1687 emitIMMD (0x14, 32, insn
->src(1));
1691 emitGPR(0x00, insn
->def(0));
1695 CodeEmitterGM107::emitIADD()
1697 if (insn
->src(1).getFile() != FILE_IMMEDIATE
) {
1698 switch (insn
->src(1).getFile()) {
1700 emitInsn(0x5c100000);
1701 emitGPR (0x14, insn
->src(1));
1703 case FILE_MEMORY_CONST
:
1704 emitInsn(0x4c100000);
1705 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1707 case FILE_IMMEDIATE
:
1708 emitInsn(0x38100000);
1709 emitIMMD(0x14, 19, insn
->src(1));
1712 assert(!"bad src1 file");
1716 emitNEG(0x31, insn
->src(0));
1717 emitNEG(0x30, insn
->src(1));
1721 emitInsn(0x1c000000);
1722 emitNEG (0x38, insn
->src(0));
1726 emitIMMD(0x14, 32, insn
->src(1));
1729 if (insn
->op
== OP_SUB
)
1730 code
[1] ^= 0x00010000;
1732 emitGPR(0x08, insn
->src(0));
1733 emitGPR(0x00, insn
->def(0));
1737 CodeEmitterGM107::emitIMUL()
1739 if (insn
->src(1).getFile() != FILE_IMMEDIATE
) {
1740 switch (insn
->src(1).getFile()) {
1742 emitInsn(0x5c380000);
1743 emitGPR (0x14, insn
->src(1));
1745 case FILE_MEMORY_CONST
:
1746 emitInsn(0x4c380000);
1747 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1749 case FILE_IMMEDIATE
:
1750 emitInsn(0x38380000);
1751 emitIMMD(0x14, 19, insn
->src(1));
1754 assert(!"bad src1 file");
1758 emitField(0x29, 1, isSignedType(insn
->sType
));
1759 emitField(0x28, 1, isSignedType(insn
->dType
));
1760 emitField(0x27, 1, insn
->subOp
== NV50_IR_SUBOP_MUL_HIGH
);
1762 emitInsn (0x1f000000);
1763 emitField(0x37, 1, isSignedType(insn
->sType
));
1764 emitField(0x36, 1, isSignedType(insn
->dType
));
1765 emitField(0x35, 1, insn
->subOp
== NV50_IR_SUBOP_MUL_HIGH
);
1767 emitIMMD (0x14, 32, insn
->src(1));
1770 emitGPR(0x08, insn
->src(0));
1771 emitGPR(0x00, insn
->def(0));
1775 CodeEmitterGM107::emitIMAD()
1777 /*XXX: imad32i exists, but not using it as third src overlaps dst */
1778 switch(insn
->src(2).getFile()) {
1780 switch (insn
->src(1).getFile()) {
1782 emitInsn(0x5a000000);
1783 emitGPR (0x14, insn
->src(1));
1785 case FILE_MEMORY_CONST
:
1786 emitInsn(0x4a000000);
1787 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1789 case FILE_IMMEDIATE
:
1790 emitInsn(0x34000000);
1791 emitIMMD(0x14, 19, insn
->src(1));
1794 assert(!"bad src1 file");
1797 emitGPR (0x27, insn
->src(2));
1799 case FILE_MEMORY_CONST
:
1800 emitInsn(0x52000000);
1801 emitGPR (0x27, insn
->src(1));
1802 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
1805 assert(!"bad src2 file");
1809 emitField(0x36, 1, insn
->subOp
== NV50_IR_SUBOP_MUL_HIGH
);
1810 emitField(0x35, 1, isSignedType(insn
->sType
));
1811 emitNEG (0x34, insn
->src(2));
1812 emitNEG2 (0x33, insn
->src(0), insn
->src(1));
1815 emitField(0x30, 1, isSignedType(insn
->dType
));
1817 emitGPR (0x08, insn
->src(0));
1818 emitGPR (0x00, insn
->def(0));
1822 CodeEmitterGM107::emitISCADD()
1824 switch (insn
->src(2).getFile()) {
1826 emitInsn(0x5c180000);
1827 emitGPR (0x14, insn
->src(2));
1829 case FILE_MEMORY_CONST
:
1830 emitInsn(0x4c180000);
1831 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
1833 case FILE_IMMEDIATE
:
1834 emitInsn(0x38180000);
1835 emitIMMD(0x14, 19, insn
->src(2));
1838 assert(!"bad src1 file");
1841 emitNEG (0x31, insn
->src(0));
1842 emitNEG (0x30, insn
->src(2));
1844 emitIMMD(0x27, 5, insn
->src(1));
1845 emitGPR (0x08, insn
->src(0));
1846 emitGPR (0x00, insn
->def(0));
1850 CodeEmitterGM107::emitIMNMX()
1852 switch (insn
->src(1).getFile()) {
1854 emitInsn(0x5c200000);
1855 emitGPR (0x14, insn
->src(1));
1857 case FILE_MEMORY_CONST
:
1858 emitInsn(0x4c200000);
1859 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1861 case FILE_IMMEDIATE
:
1862 emitInsn(0x38200000);
1863 emitIMMD(0x14, 19, insn
->src(1));
1866 assert(!"bad src1 file");
1870 emitField(0x30, 1, isSignedType(insn
->dType
));
1872 emitField(0x2b, 2, insn
->subOp
);
1873 emitField(0x2a, 1, insn
->op
== OP_MAX
);
1875 emitGPR (0x08, insn
->src(0));
1876 emitGPR (0x00, insn
->def(0));
1880 CodeEmitterGM107::emitICMP()
1882 const CmpInstruction
*insn
= this->insn
->asCmp();
1883 CondCode cc
= insn
->setCond
;
1885 if (insn
->src(2).mod
.neg())
1886 cc
= reverseCondCode(cc
);
1888 switch(insn
->src(2).getFile()) {
1890 switch (insn
->src(1).getFile()) {
1892 emitInsn(0x5b400000);
1893 emitGPR (0x14, insn
->src(1));
1895 case FILE_MEMORY_CONST
:
1896 emitInsn(0x4b400000);
1897 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1899 case FILE_IMMEDIATE
:
1900 emitInsn(0x36400000);
1901 emitIMMD(0x14, 19, insn
->src(1));
1904 assert(!"bad src1 file");
1907 emitGPR (0x27, insn
->src(2));
1909 case FILE_MEMORY_CONST
:
1910 emitInsn(0x53400000);
1911 emitGPR (0x27, insn
->src(1));
1912 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
1915 assert(!"bad src2 file");
1919 emitCond3(0x31, cc
);
1920 emitField(0x30, 1, isSignedType(insn
->sType
));
1921 emitGPR (0x08, insn
->src(0));
1922 emitGPR (0x00, insn
->def(0));
1926 CodeEmitterGM107::emitISET()
1928 const CmpInstruction
*insn
= this->insn
->asCmp();
1930 switch (insn
->src(1).getFile()) {
1932 emitInsn(0x5b500000);
1933 emitGPR (0x14, insn
->src(1));
1935 case FILE_MEMORY_CONST
:
1936 emitInsn(0x4b500000);
1937 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1939 case FILE_IMMEDIATE
:
1940 emitInsn(0x36500000);
1941 emitIMMD(0x14, 19, insn
->src(1));
1944 assert(!"bad src1 file");
1948 if (insn
->op
!= OP_SET
) {
1950 case OP_SET_AND
: emitField(0x2d, 2, 0); break;
1951 case OP_SET_OR
: emitField(0x2d, 2, 1); break;
1952 case OP_SET_XOR
: emitField(0x2d, 2, 2); break;
1954 assert(!"invalid set op");
1957 emitPRED(0x27, insn
->src(2));
1962 emitCond3(0x31, insn
->setCond
);
1963 emitField(0x30, 1, isSignedType(insn
->sType
));
1965 emitField(0x2c, 1, insn
->dType
== TYPE_F32
);
1967 emitGPR (0x08, insn
->src(0));
1968 emitGPR (0x00, insn
->def(0));
1972 CodeEmitterGM107::emitISETP()
1974 const CmpInstruction
*insn
= this->insn
->asCmp();
1976 switch (insn
->src(1).getFile()) {
1978 emitInsn(0x5b600000);
1979 emitGPR (0x14, insn
->src(1));
1981 case FILE_MEMORY_CONST
:
1982 emitInsn(0x4b600000);
1983 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
1985 case FILE_IMMEDIATE
:
1986 emitInsn(0x36600000);
1987 emitIMMD(0x14, 19, insn
->src(1));
1990 assert(!"bad src1 file");
1994 if (insn
->op
!= OP_SET
) {
1996 case OP_SET_AND
: emitField(0x2d, 2, 0); break;
1997 case OP_SET_OR
: emitField(0x2d, 2, 1); break;
1998 case OP_SET_XOR
: emitField(0x2d, 2, 2); break;
2000 assert(!"invalid set op");
2003 emitPRED(0x27, insn
->src(2));
2008 emitCond3(0x31, insn
->setCond
);
2009 emitField(0x30, 1, isSignedType(insn
->sType
));
2011 emitGPR (0x08, insn
->src(0));
2012 emitPRED (0x03, insn
->def(0));
2013 if (insn
->defExists(1))
2014 emitPRED(0x00, insn
->def(1));
2020 CodeEmitterGM107::emitSHL()
2022 switch (insn
->src(1).getFile()) {
2024 emitInsn(0x5c480000);
2025 emitGPR (0x14, insn
->src(1));
2027 case FILE_MEMORY_CONST
:
2028 emitInsn(0x4c480000);
2029 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
2031 case FILE_IMMEDIATE
:
2032 emitInsn(0x38480000);
2033 emitIMMD(0x14, 19, insn
->src(1));
2036 assert(!"bad src1 file");
2042 emitField(0x27, 1, insn
->subOp
== NV50_IR_SUBOP_SHIFT_WRAP
);
2043 emitGPR (0x08, insn
->src(0));
2044 emitGPR (0x00, insn
->def(0));
2048 CodeEmitterGM107::emitSHR()
2050 switch (insn
->src(1).getFile()) {
2052 emitInsn(0x5c280000);
2053 emitGPR (0x14, insn
->src(1));
2055 case FILE_MEMORY_CONST
:
2056 emitInsn(0x4c280000);
2057 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
2059 case FILE_IMMEDIATE
:
2060 emitInsn(0x38280000);
2061 emitIMMD(0x14, 19, insn
->src(1));
2064 assert(!"bad src1 file");
2068 emitField(0x30, 1, isSignedType(insn
->dType
));
2071 emitField(0x27, 1, insn
->subOp
== NV50_IR_SUBOP_SHIFT_WRAP
);
2072 emitGPR (0x08, insn
->src(0));
2073 emitGPR (0x00, insn
->def(0));
2077 CodeEmitterGM107::emitSHF()
2081 switch (insn
->src(1).getFile()) {
2083 emitInsn(insn
->op
== OP_SHL
? 0x5bf80000 : 0x5cf80000);
2084 emitGPR(0x14, insn
->src(1));
2086 case FILE_IMMEDIATE
:
2087 emitInsn(insn
->op
== OP_SHL
? 0x36f80000 : 0x38f80000);
2088 emitIMMD(0x14, 19, insn
->src(1));
2091 assert(!"bad src1 file");
2095 switch (insn
->sType
) {
2107 emitField(0x32, 1, !!(insn
->subOp
& NV50_IR_SUBOP_SHIFT_WRAP
));
2109 emitField(0x30, 1, !!(insn
->subOp
& NV50_IR_SUBOP_SHIFT_HIGH
));
2111 emitGPR (0x27, insn
->src(2));
2112 emitField(0x25, 2, type
);
2113 emitGPR (0x08, insn
->src(0));
2114 emitGPR (0x00, insn
->def(0));
2118 CodeEmitterGM107::emitPOPC()
2120 switch (insn
->src(0).getFile()) {
2122 emitInsn(0x5c080000);
2123 emitGPR (0x14, insn
->src(0));
2125 case FILE_MEMORY_CONST
:
2126 emitInsn(0x4c080000);
2127 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
2129 case FILE_IMMEDIATE
:
2130 emitInsn(0x38080000);
2131 emitIMMD(0x14, 19, insn
->src(0));
2134 assert(!"bad src1 file");
2138 emitINV(0x28, insn
->src(0));
2139 emitGPR(0x00, insn
->def(0));
2143 CodeEmitterGM107::emitBFI()
2145 switch(insn
->src(2).getFile()) {
2147 switch (insn
->src(1).getFile()) {
2149 emitInsn(0x5bf00000);
2150 emitGPR (0x14, insn
->src(1));
2152 case FILE_MEMORY_CONST
:
2153 emitInsn(0x4bf00000);
2154 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
2156 case FILE_IMMEDIATE
:
2157 emitInsn(0x36f00000);
2158 emitIMMD(0x14, 19, insn
->src(1));
2161 assert(!"bad src1 file");
2164 emitGPR (0x27, insn
->src(2));
2166 case FILE_MEMORY_CONST
:
2167 emitInsn(0x53f00000);
2168 emitGPR (0x27, insn
->src(1));
2169 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(2));
2172 assert(!"bad src2 file");
2177 emitGPR (0x08, insn
->src(0));
2178 emitGPR (0x00, insn
->def(0));
2182 CodeEmitterGM107::emitBFE()
2184 switch (insn
->src(1).getFile()) {
2186 emitInsn(0x5c000000);
2187 emitGPR (0x14, insn
->src(1));
2189 case FILE_MEMORY_CONST
:
2190 emitInsn(0x4c000000);
2191 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
2193 case FILE_IMMEDIATE
:
2194 emitInsn(0x38000000);
2195 emitIMMD(0x14, 19, insn
->src(1));
2198 assert(!"bad src1 file");
2202 emitField(0x30, 1, isSignedType(insn
->dType
));
2204 emitField(0x28, 1, insn
->subOp
== NV50_IR_SUBOP_EXTBF_REV
);
2205 emitGPR (0x08, insn
->src(0));
2206 emitGPR (0x00, insn
->def(0));
2210 CodeEmitterGM107::emitFLO()
2212 switch (insn
->src(0).getFile()) {
2214 emitInsn(0x5c300000);
2215 emitGPR (0x14, insn
->src(0));
2217 case FILE_MEMORY_CONST
:
2218 emitInsn(0x4c300000);
2219 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(0));
2221 case FILE_IMMEDIATE
:
2222 emitInsn(0x38300000);
2223 emitIMMD(0x14, 19, insn
->src(0));
2226 assert(!"bad src1 file");
2230 emitField(0x30, 1, isSignedType(insn
->dType
));
2232 emitField(0x29, 1, insn
->subOp
== NV50_IR_SUBOP_BFIND_SAMT
);
2233 emitINV (0x28, insn
->src(0));
2234 emitGPR (0x00, insn
->def(0));
2237 /*******************************************************************************
2239 ******************************************************************************/
2242 CodeEmitterGM107::emitLDSTs(int pos
, DataType type
)
2246 switch (typeSizeof(type
)) {
2247 case 1: data
= isSignedType(type
) ? 1 : 0; break;
2248 case 2: data
= isSignedType(type
) ? 3 : 2; break;
2249 case 4: data
= 4; break;
2250 case 8: data
= 5; break;
2251 case 16: data
= 6; break;
2253 assert(!"bad type");
2257 emitField(pos
, 3, data
);
2261 CodeEmitterGM107::emitLDSTc(int pos
)
2265 switch (insn
->cache
) {
2266 case CACHE_CA
: mode
= 0; break;
2267 case CACHE_CG
: mode
= 1; break;
2268 case CACHE_CS
: mode
= 2; break;
2269 case CACHE_CV
: mode
= 3; break;
2271 assert(!"invalid caching mode");
2275 emitField(pos
, 2, mode
);
2279 CodeEmitterGM107::emitLDC()
2281 emitInsn (0xef900000);
2282 emitLDSTs(0x30, insn
->dType
);
2283 emitField(0x2c, 2, insn
->subOp
);
2284 emitCBUF (0x24, 0x08, 0x14, 16, 0, insn
->src(0));
2285 emitGPR (0x00, insn
->def(0));
2289 CodeEmitterGM107::emitLDL()
2291 emitInsn (0xef400000);
2292 emitLDSTs(0x30, insn
->dType
);
2294 emitADDR (0x08, 0x14, 24, 0, insn
->src(0));
2295 emitGPR (0x00, insn
->def(0));
2299 CodeEmitterGM107::emitLDS()
2301 emitInsn (0xef480000);
2302 emitLDSTs(0x30, insn
->dType
);
2303 emitADDR (0x08, 0x14, 24, 0, insn
->src(0));
2304 emitGPR (0x00, insn
->def(0));
2308 CodeEmitterGM107::emitLD()
2310 emitInsn (0x80000000);
2313 emitLDSTs(0x35, insn
->dType
);
2314 emitField(0x34, 1, insn
->src(0).getIndirect(0)->getSize() == 8);
2315 emitADDR (0x08, 0x14, 32, 0, insn
->src(0));
2316 emitGPR (0x00, insn
->def(0));
2320 CodeEmitterGM107::emitSTL()
2322 emitInsn (0xef500000);
2323 emitLDSTs(0x30, insn
->dType
);
2325 emitADDR (0x08, 0x14, 24, 0, insn
->src(0));
2326 emitGPR (0x00, insn
->src(1));
2330 CodeEmitterGM107::emitSTS()
2332 emitInsn (0xef580000);
2333 emitLDSTs(0x30, insn
->dType
);
2334 emitADDR (0x08, 0x14, 24, 0, insn
->src(0));
2335 emitGPR (0x00, insn
->src(1));
2339 CodeEmitterGM107::emitST()
2341 emitInsn (0xa0000000);
2344 emitLDSTs(0x35, insn
->dType
);
2345 emitField(0x34, 1, insn
->src(0).getIndirect(0)->getSize() == 8);
2346 emitADDR (0x08, 0x14, 32, 0, insn
->src(0));
2347 emitGPR (0x00, insn
->src(1));
2351 CodeEmitterGM107::emitALD()
2353 emitInsn (0xefd80000);
2354 emitField(0x2f, 2, (insn
->getDef(0)->reg
.size
/ 4) - 1);
2355 emitGPR (0x27, insn
->src(0).getIndirect(1));
2358 emitADDR (0x08, 20, 10, 0, insn
->src(0));
2359 emitGPR (0x00, insn
->def(0));
2363 CodeEmitterGM107::emitAST()
2365 emitInsn (0xeff00000);
2366 emitField(0x2f, 2, (typeSizeof(insn
->dType
) / 4) - 1);
2367 emitGPR (0x27, insn
->src(0).getIndirect(1));
2369 emitADDR (0x08, 20, 10, 0, insn
->src(0));
2370 emitGPR (0x00, insn
->src(1));
2374 CodeEmitterGM107::emitISBERD()
2376 emitInsn(0xefd00000);
2377 emitGPR (0x08, insn
->src(0));
2378 emitGPR (0x00, insn
->def(0));
2382 CodeEmitterGM107::emitAL2P()
2384 emitInsn (0xefa00000);
2385 emitField(0x2f, 2, (insn
->getDef(0)->reg
.size
/ 4) - 1);
2388 emitField(0x14, 11, insn
->src(0).get()->reg
.data
.offset
);
2389 emitGPR (0x08, insn
->src(0).getIndirect(0));
2390 emitGPR (0x00, insn
->def(0));
2394 interpApply(const FixupEntry
*entry
, uint32_t *code
, const FixupData
& data
)
2396 int ipa
= entry
->ipa
;
2397 int reg
= entry
->reg
;
2398 int loc
= entry
->loc
;
2400 if (data
.flatshade
&&
2401 (ipa
& NV50_IR_INTERP_MODE_MASK
) == NV50_IR_INTERP_SC
) {
2402 ipa
= NV50_IR_INTERP_FLAT
;
2404 } else if (data
.force_persample_interp
&&
2405 (ipa
& NV50_IR_INTERP_SAMPLE_MASK
) == NV50_IR_INTERP_DEFAULT
&&
2406 (ipa
& NV50_IR_INTERP_MODE_MASK
) != NV50_IR_INTERP_FLAT
) {
2407 ipa
|= NV50_IR_INTERP_CENTROID
;
2409 code
[loc
+ 1] &= ~(0xf << 0x14);
2410 code
[loc
+ 1] |= (ipa
& 0x3) << 0x16;
2411 code
[loc
+ 1] |= (ipa
& 0xc) << (0x14 - 2);
2412 code
[loc
+ 0] &= ~(0xff << 0x14);
2413 code
[loc
+ 0] |= reg
<< 0x14;
2417 CodeEmitterGM107::emitIPA()
2419 int ipam
= 0, ipas
= 0;
2421 switch (insn
->getInterpMode()) {
2422 case NV50_IR_INTERP_LINEAR
: ipam
= 0; break;
2423 case NV50_IR_INTERP_PERSPECTIVE
: ipam
= 1; break;
2424 case NV50_IR_INTERP_FLAT
: ipam
= 2; break;
2425 case NV50_IR_INTERP_SC
: ipam
= 3; break;
2427 assert(!"invalid ipa mode");
2431 switch (insn
->getSampleMode()) {
2432 case NV50_IR_INTERP_DEFAULT
: ipas
= 0; break;
2433 case NV50_IR_INTERP_CENTROID
: ipas
= 1; break;
2434 case NV50_IR_INTERP_OFFSET
: ipas
= 2; break;
2436 assert(!"invalid ipa sample mode");
2440 emitInsn (0xe0000000);
2441 emitField(0x36, 2, ipam
);
2442 emitField(0x34, 2, ipas
);
2444 emitField(0x2f, 3, 7);
2445 emitADDR (0x08, 0x1c, 10, 0, insn
->src(0));
2446 if ((code
[0] & 0x0000ff00) != 0x0000ff00)
2447 code
[1] |= 0x00000040; /* .idx */
2448 emitGPR(0x00, insn
->def(0));
2450 if (insn
->op
== OP_PINTERP
) {
2451 emitGPR(0x14, insn
->src(1));
2452 if (insn
->getSampleMode() == NV50_IR_INTERP_OFFSET
)
2453 emitGPR(0x27, insn
->src(2));
2454 addInterp(insn
->ipa
, insn
->getSrc(1)->reg
.data
.id
, interpApply
);
2456 if (insn
->getSampleMode() == NV50_IR_INTERP_OFFSET
)
2457 emitGPR(0x27, insn
->src(1));
2459 addInterp(insn
->ipa
, 0xff, interpApply
);
2462 if (insn
->getSampleMode() != NV50_IR_INTERP_OFFSET
)
2467 CodeEmitterGM107::emitATOM()
2469 unsigned dType
, subOp
;
2471 if (insn
->subOp
== NV50_IR_SUBOP_ATOM_CAS
) {
2472 switch (insn
->dType
) {
2473 case TYPE_U32
: dType
= 0; break;
2474 case TYPE_U64
: dType
= 1; break;
2475 default: assert(!"unexpected dType"); dType
= 0; break;
2479 emitInsn (0xee000000);
2481 switch (insn
->dType
) {
2482 case TYPE_U32
: dType
= 0; break;
2483 case TYPE_S32
: dType
= 1; break;
2484 case TYPE_U64
: dType
= 2; break;
2485 case TYPE_F32
: dType
= 3; break;
2486 case TYPE_B128
: dType
= 4; break;
2487 case TYPE_S64
: dType
= 5; break;
2488 default: assert(!"unexpected dType"); dType
= 0; break;
2490 if (insn
->subOp
== NV50_IR_SUBOP_ATOM_EXCH
)
2493 subOp
= insn
->subOp
;
2495 emitInsn (0xed000000);
2498 emitField(0x34, 4, subOp
);
2499 emitField(0x31, 3, dType
);
2500 emitField(0x30, 1, insn
->src(0).getIndirect(0)->getSize() == 8);
2501 emitGPR (0x14, insn
->src(1));
2502 emitADDR (0x08, 0x1c, 20, 0, insn
->src(0));
2503 emitGPR (0x00, insn
->def(0));
2507 CodeEmitterGM107::emitATOMS()
2509 unsigned dType
, subOp
;
2511 if (insn
->subOp
== NV50_IR_SUBOP_ATOM_CAS
) {
2512 switch (insn
->dType
) {
2513 case TYPE_U32
: dType
= 0; break;
2514 case TYPE_U64
: dType
= 1; break;
2515 default: assert(!"unexpected dType"); dType
= 0; break;
2519 emitInsn (0xee000000);
2520 emitField(0x34, 1, dType
);
2522 switch (insn
->dType
) {
2523 case TYPE_U32
: dType
= 0; break;
2524 case TYPE_S32
: dType
= 1; break;
2525 case TYPE_U64
: dType
= 2; break;
2526 case TYPE_S64
: dType
= 3; break;
2527 default: assert(!"unexpected dType"); dType
= 0; break;
2530 if (insn
->subOp
== NV50_IR_SUBOP_ATOM_EXCH
)
2533 subOp
= insn
->subOp
;
2535 emitInsn (0xec000000);
2536 emitField(0x1c, 3, dType
);
2539 emitField(0x34, 4, subOp
);
2540 emitGPR (0x14, insn
->src(1));
2541 emitADDR (0x08, 0x12, 22, 0, insn
->src(0));
2542 emitGPR (0x00, insn
->def(0));
2546 CodeEmitterGM107::emitRED()
2550 switch (insn
->dType
) {
2551 case TYPE_U32
: dType
= 0; break;
2552 case TYPE_S32
: dType
= 1; break;
2553 case TYPE_U64
: dType
= 2; break;
2554 case TYPE_F32
: dType
= 3; break;
2555 case TYPE_B128
: dType
= 4; break;
2556 case TYPE_S64
: dType
= 5; break;
2557 default: assert(!"unexpected dType"); dType
= 0; break;
2560 emitInsn (0xebf80000);
2561 emitField(0x30, 1, insn
->src(0).getIndirect(0)->getSize() == 8);
2562 emitField(0x17, 3, insn
->subOp
);
2563 emitField(0x14, 3, dType
);
2564 emitADDR (0x08, 0x1c, 20, 0, insn
->src(0));
2565 emitGPR (0x00, insn
->src(1));
2569 CodeEmitterGM107::emitCCTL()
2572 if (insn
->src(0).getFile() == FILE_MEMORY_GLOBAL
) {
2573 emitInsn(0xef600000);
2576 emitInsn(0xef800000);
2579 emitField(0x34, 1, insn
->src(0).getIndirect(0)->getSize() == 8);
2580 emitADDR (0x08, 0x16, width
, 2, insn
->src(0));
2581 emitField(0x00, 4, insn
->subOp
);
2584 /*******************************************************************************
2586 ******************************************************************************/
2589 CodeEmitterGM107::emitPIXLD()
2591 emitInsn (0xefe80000);
2593 emitField(0x1f, 3, insn
->subOp
);
2594 emitGPR (0x08, insn
->src(0));
2595 emitGPR (0x00, insn
->def(0));
2598 /*******************************************************************************
2600 ******************************************************************************/
2603 CodeEmitterGM107::emitTEXs(int pos
)
2605 int src1
= insn
->predSrc
== 1 ? 2 : 1;
2606 if (insn
->srcExists(src1
))
2607 emitGPR(pos
, insn
->src(src1
));
2613 CodeEmitterGM107::emitTEX()
2615 const TexInstruction
*insn
= this->insn
->asTex();
2618 if (!insn
->tex
.levelZero
) {
2620 case OP_TEX
: lodm
= 0; break;
2621 case OP_TXB
: lodm
= 2; break;
2622 case OP_TXL
: lodm
= 3; break;
2624 assert(!"invalid tex op");
2631 if (insn
->tex
.rIndirectSrc
>= 0) {
2632 emitInsn (0xdeb80000);
2633 emitField(0x25, 2, lodm
);
2634 emitField(0x24, 1, insn
->tex
.useOffsets
== 1);
2636 emitInsn (0xc0380000);
2637 emitField(0x37, 2, lodm
);
2638 emitField(0x36, 1, insn
->tex
.useOffsets
== 1);
2639 emitField(0x24, 13, insn
->tex
.r
);
2642 emitField(0x32, 1, insn
->tex
.target
.isShadow());
2643 emitField(0x31, 1, insn
->tex
.liveOnly
);
2644 emitField(0x23, 1, insn
->tex
.derivAll
);
2645 emitField(0x1f, 4, insn
->tex
.mask
);
2646 emitField(0x1d, 2, insn
->tex
.target
.isCube() ? 3 :
2647 insn
->tex
.target
.getDim() - 1);
2648 emitField(0x1c, 1, insn
->tex
.target
.isArray());
2650 emitGPR (0x08, insn
->src(0));
2651 emitGPR (0x00, insn
->def(0));
2655 CodeEmitterGM107::emitTLD()
2657 const TexInstruction
*insn
= this->insn
->asTex();
2659 if (insn
->tex
.rIndirectSrc
>= 0) {
2660 emitInsn (0xdd380000);
2662 emitInsn (0xdc380000);
2663 emitField(0x24, 13, insn
->tex
.r
);
2666 emitField(0x37, 1, insn
->tex
.levelZero
== 0);
2667 emitField(0x32, 1, insn
->tex
.target
.isMS());
2668 emitField(0x31, 1, insn
->tex
.liveOnly
);
2669 emitField(0x23, 1, insn
->tex
.useOffsets
== 1);
2670 emitField(0x1f, 4, insn
->tex
.mask
);
2671 emitField(0x1d, 2, insn
->tex
.target
.isCube() ? 3 :
2672 insn
->tex
.target
.getDim() - 1);
2673 emitField(0x1c, 1, insn
->tex
.target
.isArray());
2675 emitGPR (0x08, insn
->src(0));
2676 emitGPR (0x00, insn
->def(0));
2680 CodeEmitterGM107::emitTLD4()
2682 const TexInstruction
*insn
= this->insn
->asTex();
2684 if (insn
->tex
.rIndirectSrc
>= 0) {
2685 emitInsn (0xdef80000);
2686 emitField(0x26, 2, insn
->tex
.gatherComp
);
2687 emitField(0x25, 2, insn
->tex
.useOffsets
== 4);
2688 emitField(0x24, 2, insn
->tex
.useOffsets
== 1);
2690 emitInsn (0xc8380000);
2691 emitField(0x38, 2, insn
->tex
.gatherComp
);
2692 emitField(0x37, 2, insn
->tex
.useOffsets
== 4);
2693 emitField(0x36, 2, insn
->tex
.useOffsets
== 1);
2694 emitField(0x24, 13, insn
->tex
.r
);
2697 emitField(0x32, 1, insn
->tex
.target
.isShadow());
2698 emitField(0x31, 1, insn
->tex
.liveOnly
);
2699 emitField(0x23, 1, insn
->tex
.derivAll
);
2700 emitField(0x1f, 4, insn
->tex
.mask
);
2701 emitField(0x1d, 2, insn
->tex
.target
.isCube() ? 3 :
2702 insn
->tex
.target
.getDim() - 1);
2703 emitField(0x1c, 1, insn
->tex
.target
.isArray());
2705 emitGPR (0x08, insn
->src(0));
2706 emitGPR (0x00, insn
->def(0));
2710 CodeEmitterGM107::emitTXD()
2712 const TexInstruction
*insn
= this->insn
->asTex();
2714 if (insn
->tex
.rIndirectSrc
>= 0) {
2715 emitInsn (0xde780000);
2717 emitInsn (0xde380000);
2718 emitField(0x24, 13, insn
->tex
.r
);
2721 emitField(0x31, 1, insn
->tex
.liveOnly
);
2722 emitField(0x23, 1, insn
->tex
.useOffsets
== 1);
2723 emitField(0x1f, 4, insn
->tex
.mask
);
2724 emitField(0x1d, 2, insn
->tex
.target
.isCube() ? 3 :
2725 insn
->tex
.target
.getDim() - 1);
2726 emitField(0x1c, 1, insn
->tex
.target
.isArray());
2728 emitGPR (0x08, insn
->src(0));
2729 emitGPR (0x00, insn
->def(0));
2733 CodeEmitterGM107::emitTMML()
2735 const TexInstruction
*insn
= this->insn
->asTex();
2737 if (insn
->tex
.rIndirectSrc
>= 0) {
2738 emitInsn (0xdf600000);
2740 emitInsn (0xdf580000);
2741 emitField(0x24, 13, insn
->tex
.r
);
2744 emitField(0x31, 1, insn
->tex
.liveOnly
);
2745 emitField(0x23, 1, insn
->tex
.derivAll
);
2746 emitField(0x1f, 4, insn
->tex
.mask
);
2747 emitField(0x1d, 2, insn
->tex
.target
.isCube() ? 3 :
2748 insn
->tex
.target
.getDim() - 1);
2749 emitField(0x1c, 1, insn
->tex
.target
.isArray());
2751 emitGPR (0x08, insn
->src(0));
2752 emitGPR (0x00, insn
->def(0));
2756 CodeEmitterGM107::emitTXQ()
2758 const TexInstruction
*insn
= this->insn
->asTex();
2761 switch (insn
->tex
.query
) {
2762 case TXQ_DIMS
: type
= 0x01; break;
2763 case TXQ_TYPE
: type
= 0x02; break;
2764 case TXQ_SAMPLE_POSITION
: type
= 0x05; break;
2765 case TXQ_FILTER
: type
= 0x10; break;
2766 case TXQ_LOD
: type
= 0x12; break;
2767 case TXQ_WRAP
: type
= 0x14; break;
2768 case TXQ_BORDER_COLOUR
: type
= 0x16; break;
2770 assert(!"invalid txq query");
2774 if (insn
->tex
.rIndirectSrc
>= 0) {
2775 emitInsn (0xdf500000);
2777 emitInsn (0xdf480000);
2778 emitField(0x24, 13, insn
->tex
.r
);
2781 emitField(0x31, 1, insn
->tex
.liveOnly
);
2782 emitField(0x1f, 4, insn
->tex
.mask
);
2783 emitField(0x16, 6, type
);
2784 emitGPR (0x08, insn
->src(0));
2785 emitGPR (0x00, insn
->def(0));
2789 CodeEmitterGM107::emitDEPBAR()
2791 emitInsn (0xf0f00000);
2792 emitField(0x1d, 1, 1); /* le */
2793 emitField(0x1a, 3, 5);
2794 emitField(0x14, 6, insn
->subOp
);
2795 emitField(0x00, 6, insn
->subOp
);
2798 /*******************************************************************************
2800 ******************************************************************************/
2803 CodeEmitterGM107::emitNOP()
2805 emitInsn(0x50b00000);
2809 CodeEmitterGM107::emitKIL()
2811 emitInsn (0xe3300000);
2812 emitCond5(0x00, CC_TR
);
2816 CodeEmitterGM107::emitOUT()
2818 const int cut
= insn
->op
== OP_RESTART
|| insn
->subOp
;
2819 const int emit
= insn
->op
== OP_EMIT
;
2821 switch (insn
->src(1).getFile()) {
2823 emitInsn(0xfbe00000);
2824 emitGPR (0x14, insn
->src(1));
2826 case FILE_IMMEDIATE
:
2827 emitInsn(0xf6e00000);
2828 emitIMMD(0x14, 19, insn
->src(1));
2830 case FILE_MEMORY_CONST
:
2831 emitInsn(0xebe00000);
2832 emitCBUF(0x22, -1, 0x14, 16, 2, insn
->src(1));
2835 assert(!"bad src1 file");
2839 emitField(0x27, 2, (cut
<< 1) | emit
);
2840 emitGPR (0x08, insn
->src(0));
2841 emitGPR (0x00, insn
->def(0));
2845 CodeEmitterGM107::emitBAR()
2849 emitInsn (0xf0a80000);
2851 switch (insn
->subOp
) {
2852 case NV50_IR_SUBOP_BAR_RED_POPC
: subop
= 0x02; break;
2853 case NV50_IR_SUBOP_BAR_RED_AND
: subop
= 0x0a; break;
2854 case NV50_IR_SUBOP_BAR_RED_OR
: subop
= 0x12; break;
2855 case NV50_IR_SUBOP_BAR_ARRIVE
: subop
= 0x81; break;
2858 assert(insn
->subOp
== NV50_IR_SUBOP_BAR_SYNC
);
2862 emitField(0x20, 8, subop
);
2865 if (insn
->src(0).getFile() == FILE_GPR
) {
2866 emitGPR(0x08, insn
->src(0));
2868 ImmediateValue
*imm
= insn
->getSrc(0)->asImm();
2870 emitField(0x08, 8, imm
->reg
.data
.u32
);
2871 emitField(0x2b, 1, 1);
2875 if (insn
->src(1).getFile() == FILE_GPR
) {
2876 emitGPR(0x14, insn
->src(1));
2878 ImmediateValue
*imm
= insn
->getSrc(0)->asImm();
2880 emitField(0x14, 12, imm
->reg
.data
.u32
);
2881 emitField(0x2c, 1, 1);
2884 if (insn
->srcExists(2) && (insn
->predSrc
!= 2)) {
2885 emitPRED (0x27, insn
->src(2));
2886 emitField(0x2a, 1, insn
->src(2).mod
== Modifier(NV50_IR_MOD_NOT
));
2888 emitField(0x27, 3, 7);
2893 CodeEmitterGM107::emitMEMBAR()
2895 emitInsn (0xef980000);
2896 emitField(0x08, 2, insn
->subOp
>> 2);
2900 CodeEmitterGM107::emitVOTE()
2902 assert(insn
->src(0).getFile() == FILE_PREDICATE
);
2905 for (int i
= 0; insn
->defExists(i
); i
++) {
2906 if (insn
->def(i
).getFile() == FILE_GPR
)
2908 else if (insn
->def(i
).getFile() == FILE_PREDICATE
)
2912 emitInsn (0x50d80000);
2913 emitField(0x30, 2, insn
->subOp
);
2915 emitGPR (0x00, insn
->def(r
));
2919 emitPRED (0x2d, insn
->def(p
));
2922 emitField(0x2a, 1, insn
->src(0).mod
== Modifier(NV50_IR_MOD_NOT
));
2923 emitPRED (0x27, insn
->src(0));
2927 CodeEmitterGM107::emitSUTarget()
2929 const TexInstruction
*insn
= this->insn
->asTex();
2932 assert(insn
->op
>= OP_SULDB
&& insn
->op
<= OP_SUREDP
);
2934 if (insn
->tex
.target
== TEX_TARGET_BUFFER
) {
2936 } else if (insn
->tex
.target
== TEX_TARGET_1D_ARRAY
) {
2938 } else if (insn
->tex
.target
== TEX_TARGET_2D
||
2939 insn
->tex
.target
== TEX_TARGET_RECT
) {
2941 } else if (insn
->tex
.target
== TEX_TARGET_2D_ARRAY
||
2942 insn
->tex
.target
== TEX_TARGET_CUBE
||
2943 insn
->tex
.target
== TEX_TARGET_CUBE_ARRAY
) {
2945 } else if (insn
->tex
.target
== TEX_TARGET_3D
) {
2948 assert(insn
->tex
.target
== TEX_TARGET_1D
);
2950 emitField(0x20, 4, target
);
2954 CodeEmitterGM107::emitSUHandle(const int s
)
2956 const TexInstruction
*insn
= this->insn
->asTex();
2958 assert(insn
->op
>= OP_SULDB
&& insn
->op
<= OP_SUREDP
);
2960 if (insn
->src(s
).getFile() == FILE_GPR
) {
2961 emitGPR(0x27, insn
->src(s
));
2963 ImmediateValue
*imm
= insn
->getSrc(s
)->asImm();
2965 emitField(0x33, 1, 1);
2966 emitField(0x24, 13, imm
->reg
.data
.u32
);
2971 CodeEmitterGM107::emitSUSTx()
2973 const TexInstruction
*insn
= this->insn
->asTex();
2975 emitInsn(0xeb200000);
2976 if (insn
->op
== OP_SUSTB
)
2977 emitField(0x34, 1, 1);
2981 emitField(0x14, 4, 0xf); // rgba
2982 emitGPR (0x08, insn
->src(0));
2983 emitGPR (0x00, insn
->src(1));
2989 CodeEmitterGM107::emitSULDx()
2991 const TexInstruction
*insn
= this->insn
->asTex();
2994 emitInsn(0xeb000000);
2995 if (insn
->op
== OP_SULDB
)
2996 emitField(0x34, 1, 1);
2999 switch (insn
->dType
) {
3000 case TYPE_S8
: type
= 1; break;
3001 case TYPE_U16
: type
= 2; break;
3002 case TYPE_S16
: type
= 3; break;
3003 case TYPE_U32
: type
= 4; break;
3004 case TYPE_U64
: type
= 5; break;
3005 case TYPE_B128
: type
= 6; break;
3007 assert(insn
->dType
== TYPE_U8
);
3011 emitField(0x14, 3, type
);
3012 emitGPR (0x00, insn
->def(0));
3013 emitGPR (0x08, insn
->src(0));
3019 CodeEmitterGM107::emitSUREDx()
3021 const TexInstruction
*insn
= this->insn
->asTex();
3022 uint8_t type
= 0, subOp
;
3024 if (insn
->subOp
== NV50_IR_SUBOP_ATOM_CAS
)
3025 emitInsn(0xeac00000);
3027 emitInsn(0xea600000);
3029 if (insn
->op
== OP_SUREDB
)
3030 emitField(0x34, 1, 1);
3034 switch (insn
->dType
) {
3035 case TYPE_S32
: type
= 1; break;
3036 case TYPE_U64
: type
= 2; break;
3037 case TYPE_F32
: type
= 3; break;
3038 case TYPE_S64
: type
= 5; break;
3040 assert(insn
->dType
== TYPE_U32
);
3045 if (insn
->subOp
== NV50_IR_SUBOP_ATOM_CAS
) {
3047 } else if (insn
->subOp
== NV50_IR_SUBOP_ATOM_EXCH
) {
3050 subOp
= insn
->subOp
;
3053 emitField(0x24, 3, type
);
3054 emitField(0x1d, 4, subOp
);
3055 emitGPR (0x14, insn
->src(1));
3056 emitGPR (0x08, insn
->src(0));
3057 emitGPR (0x00, insn
->def(0));
3062 /*******************************************************************************
3063 * assembler front-end
3064 ******************************************************************************/
3067 CodeEmitterGM107::emitInstruction(Instruction
*i
)
3069 const unsigned int size
= (writeIssueDelays
&& !(codeSize
& 0x1f)) ? 16 : 8;
3074 if (insn
->encSize
!= 8) {
3075 ERROR("skipping undecodable instruction: "); insn
->print();
3078 if (codeSize
+ size
> codeSizeLimit
) {
3079 ERROR("code emitter output buffer too small\n");
3083 if (writeIssueDelays
) {
3084 int n
= ((codeSize
& 0x1f) / 8) - 1;
3087 data
[0] = 0x00000000;
3088 data
[1] = 0x00000000;
3094 emitField(data
, n
* 21, 21, insn
->sched
);
3150 if (insn
->op
== OP_CVT
&& (insn
->def(0).getFile() == FILE_PREDICATE
||
3151 insn
->src(0).getFile() == FILE_PREDICATE
)) {
3153 } else if (isFloatType(insn
->dType
)) {
3154 if (isFloatType(insn
->sType
))
3159 if (isFloatType(insn
->sType
))
3170 if (isFloatType(insn
->dType
)) {
3171 if (insn
->dType
== TYPE_F64
)
3180 if (isFloatType(insn
->dType
)) {
3181 if (insn
->dType
== TYPE_F64
)
3191 if (isFloatType(insn
->dType
)) {
3192 if (insn
->dType
== TYPE_F64
)
3205 if (isFloatType(insn
->dType
)) {
3206 if (insn
->dType
== TYPE_F64
)
3215 if (typeSizeof(insn
->sType
) == 8)
3221 if (typeSizeof(insn
->sType
) == 8)
3239 if (isFloatType(insn
->dType
))
3248 if (insn
->def(0).getFile() != FILE_PREDICATE
) {
3249 if (isFloatType(insn
->sType
))
3250 if (insn
->sType
== TYPE_F64
)
3257 if (isFloatType(insn
->sType
))
3258 if (insn
->sType
== TYPE_F64
)
3290 switch (insn
->src(0).getFile()) {
3291 case FILE_MEMORY_CONST
: emitLDC(); break;
3292 case FILE_MEMORY_LOCAL
: emitLDL(); break;
3293 case FILE_MEMORY_SHARED
: emitLDS(); break;
3294 case FILE_MEMORY_GLOBAL
: emitLD(); break;
3296 assert(!"invalid load");
3302 switch (insn
->src(0).getFile()) {
3303 case FILE_MEMORY_LOCAL
: emitSTL(); break;
3304 case FILE_MEMORY_SHARED
: emitSTS(); break;
3305 case FILE_MEMORY_GLOBAL
: emitST(); break;
3307 assert(!"invalid store");
3313 if (insn
->src(0).getFile() == FILE_MEMORY_SHARED
)
3316 if (!insn
->defExists(0) && insn
->subOp
< NV50_IR_SUBOP_ATOM_CAS
)
3401 assert(!"invalid opcode");
3417 CodeEmitterGM107::getMinEncodingSize(const Instruction
*i
) const
3422 /*******************************************************************************
3423 * sched data calculator
3424 ******************************************************************************/
3426 class SchedDataCalculatorGM107
: public Pass
3429 SchedDataCalculatorGM107(const TargetGM107
*targ
) : targ(targ
) {}
3441 void rebase(const int base
)
3443 const int delta
= this->base
- base
;
3448 for (int i
= 0; i
< 256; ++i
) {
3452 for (int i
= 0; i
< 8; ++i
) {
3461 memset(&rd
, 0, sizeof(rd
));
3462 memset(&wr
, 0, sizeof(wr
));
3464 int getLatest(const ScoreData
& d
) const
3467 for (int i
= 0; i
< 256; ++i
)
3470 for (int i
= 0; i
< 8; ++i
)
3477 inline int getLatestRd() const
3479 return getLatest(rd
);
3481 inline int getLatestWr() const
3483 return getLatest(wr
);
3485 inline int getLatest() const
3487 return MAX2(getLatestRd(), getLatestWr());
3489 void setMax(const RegScores
*that
)
3491 for (int i
= 0; i
< 256; ++i
) {
3492 rd
.r
[i
] = MAX2(rd
.r
[i
], that
->rd
.r
[i
]);
3493 wr
.r
[i
] = MAX2(wr
.r
[i
], that
->wr
.r
[i
]);
3495 for (int i
= 0; i
< 8; ++i
) {
3496 rd
.p
[i
] = MAX2(rd
.p
[i
], that
->rd
.p
[i
]);
3497 wr
.p
[i
] = MAX2(wr
.p
[i
], that
->wr
.p
[i
]);
3499 rd
.c
= MAX2(rd
.c
, that
->rd
.c
);
3500 wr
.c
= MAX2(wr
.c
, that
->wr
.c
);
3502 void print(int cycle
)
3504 for (int i
= 0; i
< 256; ++i
) {
3505 if (rd
.r
[i
] > cycle
)
3506 INFO("rd $r%i @ %i\n", i
, rd
.r
[i
]);
3507 if (wr
.r
[i
] > cycle
)
3508 INFO("wr $r%i @ %i\n", i
, wr
.r
[i
]);
3510 for (int i
= 0; i
< 8; ++i
) {
3511 if (rd
.p
[i
] > cycle
)
3512 INFO("rd $p%i @ %i\n", i
, rd
.p
[i
]);
3513 if (wr
.p
[i
] > cycle
)
3514 INFO("wr $p%i @ %i\n", i
, wr
.p
[i
]);
3517 INFO("rd $c @ %i\n", rd
.c
);
3519 INFO("wr $c @ %i\n", wr
.c
);
3523 RegScores
*score
; // for current BB
3524 std::vector
<RegScores
> scoreBoards
;
3526 const TargetGM107
*targ
;
3527 bool visit(Function
*);
3528 bool visit(BasicBlock
*);
3530 void commitInsn(const Instruction
*, int);
3531 int calcDelay(const Instruction
*, int) const;
3532 void setDelay(Instruction
*, int, const Instruction
*);
3533 void recordWr(const Value
*, int, int);
3534 void checkRd(const Value
*, int, int&) const;
3536 inline void emitYield(Instruction
*);
3537 inline void emitStall(Instruction
*, uint8_t);
3538 inline void emitReuse(Instruction
*, uint8_t);
3539 inline void emitWrDepBar(Instruction
*, uint8_t);
3540 inline void emitRdDepBar(Instruction
*, uint8_t);
3541 inline void emitWtDepBar(Instruction
*, uint8_t);
3543 inline int getStall(const Instruction
*) const;
3544 inline int getWrDepBar(const Instruction
*) const;
3545 inline int getRdDepBar(const Instruction
*) const;
3546 inline int getWtDepBar(const Instruction
*) const;
3548 void setReuseFlag(Instruction
*);
3550 inline void printSchedInfo(int, const Instruction
*) const;
3553 LiveBarUse(Instruction
*insn
, Instruction
*usei
)
3554 : insn(insn
), usei(usei
) { }
3560 LiveBarDef(Instruction
*insn
, Instruction
*defi
)
3561 : insn(insn
), defi(defi
) { }
3566 bool insertBarriers(BasicBlock
*);
3568 Instruction
*findFirstUse(const Instruction
*) const;
3569 Instruction
*findFirstDef(const Instruction
*) const;
3571 bool needRdDepBar(const Instruction
*) const;
3572 bool needWrDepBar(const Instruction
*) const;
3576 SchedDataCalculatorGM107::emitStall(Instruction
*insn
, uint8_t cnt
)
3583 SchedDataCalculatorGM107::emitYield(Instruction
*insn
)
3585 insn
->sched
|= 1 << 4;
3589 SchedDataCalculatorGM107::emitWrDepBar(Instruction
*insn
, uint8_t id
)
3592 if ((insn
->sched
& 0xe0) == 0xe0)
3593 insn
->sched
^= 0xe0;
3594 insn
->sched
|= id
<< 5;
3598 SchedDataCalculatorGM107::emitRdDepBar(Instruction
*insn
, uint8_t id
)
3601 if ((insn
->sched
& 0x700) == 0x700)
3602 insn
->sched
^= 0x700;
3603 insn
->sched
|= id
<< 8;
3607 SchedDataCalculatorGM107::emitWtDepBar(Instruction
*insn
, uint8_t id
)
3610 insn
->sched
|= 1 << (11 + id
);
3614 SchedDataCalculatorGM107::emitReuse(Instruction
*insn
, uint8_t id
)
3617 insn
->sched
|= 1 << (17 + id
);
3621 SchedDataCalculatorGM107::printSchedInfo(int cycle
,
3622 const Instruction
*insn
) const
3624 uint8_t st
, yl
, wr
, rd
, wt
, ru
;
3626 st
= (insn
->sched
& 0x00000f) >> 0;
3627 yl
= (insn
->sched
& 0x000010) >> 4;
3628 wr
= (insn
->sched
& 0x0000e0) >> 5;
3629 rd
= (insn
->sched
& 0x000700) >> 8;
3630 wt
= (insn
->sched
& 0x01f800) >> 11;
3631 ru
= (insn
->sched
& 0x1e0000) >> 17;
3633 INFO("cycle %i, (st 0x%x, yl 0x%x, wr 0x%x, rd 0x%x, wt 0x%x, ru 0x%x)\n",
3634 cycle
, st
, yl
, wr
, rd
, wt
, ru
);
3638 SchedDataCalculatorGM107::getStall(const Instruction
*insn
) const
3640 return insn
->sched
& 0xf;
3644 SchedDataCalculatorGM107::getWrDepBar(const Instruction
*insn
) const
3646 return (insn
->sched
& 0x0000e0) >> 5;
3650 SchedDataCalculatorGM107::getRdDepBar(const Instruction
*insn
) const
3652 return (insn
->sched
& 0x000700) >> 8;
3656 SchedDataCalculatorGM107::getWtDepBar(const Instruction
*insn
) const
3658 return (insn
->sched
& 0x01f800) >> 11;
3661 // Emit the reuse flag which allows to make use of the new memory hierarchy
3662 // introduced since Maxwell, the operand reuse cache.
3664 // It allows to reduce bank conflicts by caching operands. Each time you issue
3665 // an instruction, that flag can tell the hw which operands are going to be
3666 // re-used by the next instruction. Note that the next instruction has to use
3667 // the same GPR id in the same operand slot.
3669 SchedDataCalculatorGM107::setReuseFlag(Instruction
*insn
)
3671 Instruction
*next
= insn
->next
;
3672 BitSet
defs(255, 1);
3674 if (!targ
->isReuseSupported(insn
))
3677 for (int d
= 0; insn
->defExists(d
); ++d
) {
3678 const Value
*def
= insn
->def(d
).rep();
3679 if (insn
->def(d
).getFile() != FILE_GPR
)
3681 if (typeSizeof(insn
->dType
) != 4 || def
->reg
.data
.id
== 255)
3683 defs
.set(def
->reg
.data
.id
);
3686 for (int s
= 0; insn
->srcExists(s
); s
++) {
3687 const Value
*src
= insn
->src(s
).rep();
3688 if (insn
->src(s
).getFile() != FILE_GPR
)
3690 if (typeSizeof(insn
->sType
) != 4 || src
->reg
.data
.id
== 255)
3692 if (defs
.test(src
->reg
.data
.id
))
3694 if (!next
->srcExists(s
) || next
->src(s
).getFile() != FILE_GPR
)
3696 if (src
->reg
.data
.id
!= next
->getSrc(s
)->reg
.data
.id
)
3704 SchedDataCalculatorGM107::recordWr(const Value
*v
, int cycle
, int ready
)
3706 int a
= v
->reg
.data
.id
, b
;
3708 switch (v
->reg
.file
) {
3710 b
= a
+ v
->reg
.size
/ 4;
3711 for (int r
= a
; r
< b
; ++r
)
3712 score
->rd
.r
[r
] = ready
;
3714 case FILE_PREDICATE
:
3715 // To immediately use a predicate set by any instructions, the minimum
3716 // number of stall counts is 13.
3717 score
->rd
.p
[a
] = cycle
+ 13;
3720 score
->rd
.c
= ready
;
3728 SchedDataCalculatorGM107::checkRd(const Value
*v
, int cycle
, int &delay
) const
3730 int a
= v
->reg
.data
.id
, b
;
3733 switch (v
->reg
.file
) {
3735 b
= a
+ v
->reg
.size
/ 4;
3736 for (int r
= a
; r
< b
; ++r
)
3737 ready
= MAX2(ready
, score
->rd
.r
[r
]);
3739 case FILE_PREDICATE
:
3740 ready
= MAX2(ready
, score
->rd
.p
[a
]);
3743 ready
= MAX2(ready
, score
->rd
.c
);
3749 delay
= MAX2(delay
, ready
- cycle
);
3753 SchedDataCalculatorGM107::commitInsn(const Instruction
*insn
, int cycle
)
3755 const int ready
= cycle
+ targ
->getLatency(insn
);
3757 for (int d
= 0; insn
->defExists(d
); ++d
)
3758 recordWr(insn
->getDef(d
), cycle
, ready
);
3760 #ifdef GM107_DEBUG_SCHED_DATA
3761 score
->print(cycle
);
3765 #define GM107_MIN_ISSUE_DELAY 0x1
3766 #define GM107_MAX_ISSUE_DELAY 0xf
3769 SchedDataCalculatorGM107::calcDelay(const Instruction
*insn
, int cycle
) const
3771 int delay
= 0, ready
= cycle
;
3773 for (int s
= 0; insn
->srcExists(s
); ++s
)
3774 checkRd(insn
->getSrc(s
), cycle
, delay
);
3776 // TODO: make use of getReadLatency()!
3778 return MAX2(delay
, ready
- cycle
);
3782 SchedDataCalculatorGM107::setDelay(Instruction
*insn
, int delay
,
3783 const Instruction
*next
)
3785 const OpClass cl
= targ
->getOpClass(insn
->op
);
3788 if (insn
->op
== OP_EXIT
||
3789 insn
->op
== OP_BAR
||
3790 insn
->op
== OP_MEMBAR
) {
3791 delay
= GM107_MAX_ISSUE_DELAY
;
3793 if (insn
->op
== OP_QUADON
||
3794 insn
->op
== OP_QUADPOP
) {
3797 if (cl
== OPCLASS_FLOW
|| insn
->join
) {
3801 if (!next
|| !targ
->canDualIssue(insn
, next
)) {
3802 delay
= CLAMP(delay
, GM107_MIN_ISSUE_DELAY
, GM107_MAX_ISSUE_DELAY
);
3804 delay
= 0x0; // dual-issue
3807 wr
= getWrDepBar(insn
);
3808 rd
= getRdDepBar(insn
);
3810 if (delay
== GM107_MIN_ISSUE_DELAY
&& (wr
& rd
) != 7) {
3811 // Barriers take one additional clock cycle to become active on top of
3812 // the clock consumed by the instruction producing it.
3813 if (!next
|| insn
->bb
!= next
->bb
) {
3816 int wt
= getWtDepBar(next
);
3817 if ((wt
& (1 << wr
)) | (wt
& (1 << rd
)))
3822 emitStall(insn
, delay
);
3826 // Return true when the given instruction needs to emit a read dependency
3827 // barrier (for WaR hazards) because it doesn't operate at a fixed latency, and
3828 // setting the maximum number of stall counts is not enough.
3830 SchedDataCalculatorGM107::needRdDepBar(const Instruction
*insn
) const
3832 BitSet
srcs(255, 1), defs(255, 1);
3835 if (!targ
->isBarrierRequired(insn
))
3838 // Do not emit a read dependency barrier when the instruction doesn't use
3839 // any GPR (like st s[0x4] 0x0) as input because it's unnecessary.
3840 for (int s
= 0; insn
->srcExists(s
); ++s
) {
3841 const Value
*src
= insn
->src(s
).rep();
3842 if (insn
->src(s
).getFile() != FILE_GPR
)
3844 if (src
->reg
.data
.id
== 255)
3847 a
= src
->reg
.data
.id
;
3848 b
= a
+ src
->reg
.size
/ 4;
3849 for (int r
= a
; r
< b
; ++r
)
3853 if (!srcs
.popCount())
3856 // Do not emit a read dependency barrier when the output GPRs are equal to
3857 // the input GPRs (like rcp $r0 $r0) because a write dependency barrier will
3858 // be produced and WaR hazards are prevented.
3859 for (int d
= 0; insn
->defExists(d
); ++d
) {
3860 const Value
*def
= insn
->def(d
).rep();
3861 if (insn
->def(d
).getFile() != FILE_GPR
)
3863 if (def
->reg
.data
.id
== 255)
3866 a
= def
->reg
.data
.id
;
3867 b
= a
+ def
->reg
.size
/ 4;
3868 for (int r
= a
; r
< b
; ++r
)
3873 if (!srcs
.popCount())
3879 // Return true when the given instruction needs to emit a write dependency
3880 // barrier (for RaW hazards) because it doesn't operate at a fixed latency, and
3881 // setting the maximum number of stall counts is not enough. This is only legal
3882 // if the instruction output something.
3884 SchedDataCalculatorGM107::needWrDepBar(const Instruction
*insn
) const
3886 if (!targ
->isBarrierRequired(insn
))
3889 for (int d
= 0; insn
->defExists(d
); ++d
) {
3890 if (insn
->def(d
).getFile() == FILE_GPR
||
3891 insn
->def(d
).getFile() == FILE_PREDICATE
)
3897 // Find the next instruction inside the same basic block which uses the output
3898 // of the given instruction in order to avoid RaW hazards.
3900 SchedDataCalculatorGM107::findFirstUse(const Instruction
*bari
) const
3902 Instruction
*insn
, *next
;
3905 if (!bari
->defExists(0))
3908 minGPR
= bari
->def(0).rep()->reg
.data
.id
;
3909 maxGPR
= minGPR
+ bari
->def(0).rep()->reg
.size
/ 4 - 1;
3911 for (insn
= bari
->next
; insn
!= NULL
; insn
= next
) {
3914 for (int s
= 0; insn
->srcExists(s
); ++s
) {
3915 const Value
*src
= insn
->src(s
).rep();
3916 if (bari
->def(0).getFile() == FILE_GPR
) {
3917 if (insn
->src(s
).getFile() != FILE_GPR
||
3918 src
->reg
.data
.id
+ src
->reg
.size
/ 4 - 1 < minGPR
||
3919 src
->reg
.data
.id
> maxGPR
)
3923 if (bari
->def(0).getFile() == FILE_PREDICATE
) {
3924 if (insn
->src(s
).getFile() != FILE_PREDICATE
||
3925 src
->reg
.data
.id
!= minGPR
)
3934 // Find the next instruction inside the same basic block which overwrites, at
3935 // least, one source of the given instruction in order to avoid WaR hazards.
3937 SchedDataCalculatorGM107::findFirstDef(const Instruction
*bari
) const
3939 Instruction
*insn
, *next
;
3942 for (insn
= bari
->next
; insn
!= NULL
; insn
= next
) {
3945 for (int d
= 0; insn
->defExists(d
); ++d
) {
3946 const Value
*def
= insn
->def(d
).rep();
3947 if (insn
->def(d
).getFile() != FILE_GPR
)
3950 minGPR
= def
->reg
.data
.id
;
3951 maxGPR
= minGPR
+ def
->reg
.size
/ 4 - 1;
3953 for (int s
= 0; bari
->srcExists(s
); ++s
) {
3954 const Value
*src
= bari
->src(s
).rep();
3955 if (bari
->src(s
).getFile() != FILE_GPR
||
3956 src
->reg
.data
.id
+ src
->reg
.size
/ 4 - 1 < minGPR
||
3957 src
->reg
.data
.id
> maxGPR
)
3966 // Dependency barriers:
3967 // This pass is a bit ugly and could probably be improved by performing a
3968 // better allocation.
3970 // The main idea is to avoid WaR and RaW hazards by emitting read/write
3971 // dependency barriers using the control codes.
3973 SchedDataCalculatorGM107::insertBarriers(BasicBlock
*bb
)
3975 std::list
<LiveBarUse
> live_uses
;
3976 std::list
<LiveBarDef
> live_defs
;
3977 Instruction
*insn
, *next
;
3981 for (insn
= bb
->getEntry(); insn
!= NULL
; insn
= next
) {
3982 Instruction
*usei
= NULL
, *defi
= NULL
;
3983 bool need_wr_bar
, need_rd_bar
;
3987 // Expire old barrier uses.
3988 for (std::list
<LiveBarUse
>::iterator it
= live_uses
.begin();
3989 it
!= live_uses
.end();) {
3990 if (insn
->serial
>= it
->usei
->serial
) {
3991 int wr
= getWrDepBar(it
->insn
);
3992 emitWtDepBar(insn
, wr
);
3993 bars
.clr(wr
); // free barrier
3994 it
= live_uses
.erase(it
);
4000 // Expire old barrier defs.
4001 for (std::list
<LiveBarDef
>::iterator it
= live_defs
.begin();
4002 it
!= live_defs
.end();) {
4003 if (insn
->serial
>= it
->defi
->serial
) {
4004 int rd
= getRdDepBar(it
->insn
);
4005 emitWtDepBar(insn
, rd
);
4006 bars
.clr(rd
); // free barrier
4007 it
= live_defs
.erase(it
);
4013 need_wr_bar
= needWrDepBar(insn
);
4014 need_rd_bar
= needRdDepBar(insn
);
4017 // When the instruction requires to emit a write dependency barrier
4018 // (all which write something at a variable latency), find the next
4019 // instruction which reads the outputs.
4020 usei
= findFirstUse(insn
);
4022 // Allocate and emit a new barrier.
4023 bar_id
= bars
.findFreeRange(1);
4027 emitWrDepBar(insn
, bar_id
);
4029 live_uses
.push_back(LiveBarUse(insn
, usei
));
4033 // When the instruction requires to emit a read dependency barrier
4034 // (all which read something at a variable latency), find the next
4035 // instruction which will write the inputs.
4036 defi
= findFirstDef(insn
);
4038 if (usei
&& defi
&& usei
->serial
<= defi
->serial
)
4041 // Allocate and emit a new barrier.
4042 bar_id
= bars
.findFreeRange(1);
4046 emitRdDepBar(insn
, bar_id
);
4048 live_defs
.push_back(LiveBarDef(insn
, defi
));
4052 // Remove unnecessary barrier waits.
4053 BitSet
alive_bars(6, 1);
4054 for (insn
= bb
->getEntry(); insn
!= NULL
; insn
= next
) {
4059 wr
= getWrDepBar(insn
);
4060 rd
= getRdDepBar(insn
);
4061 wt
= getWtDepBar(insn
);
4063 for (int idx
= 0; idx
< 6; ++idx
) {
4064 if (!(wt
& (1 << idx
)))
4066 if (!alive_bars
.test(idx
)) {
4067 insn
->sched
&= ~(1 << (11 + idx
));
4069 alive_bars
.clr(idx
);
4083 SchedDataCalculatorGM107::visit(Function
*func
)
4087 func
->orderInstructions(insns
);
4089 scoreBoards
.resize(func
->cfg
.getSize());
4090 for (size_t i
= 0; i
< scoreBoards
.size(); ++i
)
4091 scoreBoards
[i
].wipe();
4096 SchedDataCalculatorGM107::visit(BasicBlock
*bb
)
4098 Instruction
*insn
, *next
= NULL
;
4101 for (Instruction
*insn
= bb
->getEntry(); insn
; insn
= insn
->next
) {
4103 insn
->sched
= 0x7e0;
4106 if (!debug_get_bool_option("NV50_PROG_SCHED", true))
4109 // Insert read/write dependency barriers for instructions which don't
4110 // operate at a fixed latency.
4113 score
= &scoreBoards
.at(bb
->getId());
4115 for (Graph::EdgeIterator ei
= bb
->cfg
.incident(); !ei
.end(); ei
.next()) {
4116 // back branches will wait until all target dependencies are satisfied
4117 if (ei
.getType() == Graph::Edge::BACK
) // sched would be uninitialized
4119 BasicBlock
*in
= BasicBlock::get(ei
.getNode());
4120 score
->setMax(&scoreBoards
.at(in
->getId()));
4123 #ifdef GM107_DEBUG_SCHED_DATA
4124 INFO("=== BB:%i initial scores\n", bb
->getId());
4125 score
->print(cycle
);
4128 // Because barriers are allocated locally (intra-BB), we have to make sure
4129 // that all produced barriers have been consumed before entering inside a
4130 // new basic block. The best way is to do a global allocation pre RA but
4131 // it's really more difficult, especially because of the phi nodes. Anyways,
4132 // it seems like that waiting on a barrier which has already been consumed
4133 // doesn't add any additional cost, it's just not elegant!
4134 Instruction
*start
= bb
->getEntry();
4135 if (start
&& bb
->cfg
.incidentCount() > 0) {
4136 for (int b
= 0; b
< 6; b
++)
4137 emitWtDepBar(start
, b
);
4140 for (insn
= bb
->getEntry(); insn
&& insn
->next
; insn
= insn
->next
) {
4143 commitInsn(insn
, cycle
);
4144 int delay
= calcDelay(next
, cycle
);
4145 setDelay(insn
, delay
, next
);
4146 cycle
+= getStall(insn
);
4150 // XXX: The yield flag seems to destroy a bunch of things when it is
4151 // set on every instruction, need investigation.
4154 #ifdef GM107_DEBUG_SCHED_DATA
4155 printSchedInfo(cycle
, insn
);
4163 commitInsn(insn
, cycle
);
4167 #ifdef GM107_DEBUG_SCHED_DATA
4168 fprintf(stderr
, "last instruction is : ");
4170 fprintf(stderr
, "cycle=%d\n", cycle
);
4173 for (Graph::EdgeIterator ei
= bb
->cfg
.outgoing(); !ei
.end(); ei
.next()) {
4174 BasicBlock
*out
= BasicBlock::get(ei
.getNode());
4176 if (ei
.getType() != Graph::Edge::BACK
) {
4177 // Only test the first instruction of the outgoing block.
4178 next
= out
->getEntry();
4180 bbDelay
= MAX2(bbDelay
, calcDelay(next
, cycle
));
4182 // When the outgoing BB is empty, make sure to set the number of
4183 // stall counts needed by the instruction because we don't know the
4184 // next instruction.
4185 bbDelay
= MAX2(bbDelay
, targ
->getLatency(insn
));
4188 // Wait until all dependencies are satisfied.
4189 const int regsFree
= score
->getLatest();
4190 next
= out
->getFirst();
4191 for (int c
= cycle
; next
&& c
< regsFree
; next
= next
->next
) {
4192 bbDelay
= MAX2(bbDelay
, calcDelay(next
, c
));
4193 c
+= getStall(next
);
4198 if (bb
->cfg
.outgoingCount() != 1)
4200 setDelay(insn
, bbDelay
, next
);
4201 cycle
+= getStall(insn
);
4203 score
->rebase(cycle
); // common base for initializing out blocks' scores
4207 /*******************************************************************************
4209 ******************************************************************************/
4212 CodeEmitterGM107::prepareEmission(Function
*func
)
4214 SchedDataCalculatorGM107
sched(targGM107
);
4215 CodeEmitter::prepareEmission(func
);
4216 sched
.run(func
, true, true);
4219 static inline uint32_t sizeToBundlesGM107(uint32_t size
)
4221 return (size
+ 23) / 24;
4225 CodeEmitterGM107::prepareEmission(Program
*prog
)
4227 for (ArrayList::Iterator fi
= prog
->allFuncs
.iterator();
4228 !fi
.end(); fi
.next()) {
4229 Function
*func
= reinterpret_cast<Function
*>(fi
.get());
4230 func
->binPos
= prog
->binSize
;
4231 prepareEmission(func
);
4233 // adjust sizes & positions for schedulding info:
4234 if (prog
->getTarget()->hasSWSched
) {
4235 uint32_t adjPos
= func
->binPos
;
4236 BasicBlock
*bb
= NULL
;
4237 for (int i
= 0; i
< func
->bbCount
; ++i
) {
4238 bb
= func
->bbArray
[i
];
4239 int32_t adjSize
= bb
->binSize
;
4241 adjSize
-= 32 - adjPos
% 32;
4245 adjSize
= bb
->binSize
+ sizeToBundlesGM107(adjSize
) * 8;
4246 bb
->binPos
= adjPos
;
4247 bb
->binSize
= adjSize
;
4251 func
->binSize
= adjPos
- func
->binPos
;
4254 prog
->binSize
+= func
->binSize
;
4258 CodeEmitterGM107::CodeEmitterGM107(const TargetGM107
*target
)
4259 : CodeEmitter(target
),
4261 writeIssueDelays(target
->hasSWSched
)
4264 codeSize
= codeSizeLimit
= 0;
4269 TargetGM107::createCodeEmitterGM107(Program::Type type
)
4271 CodeEmitterGM107
*emit
= new CodeEmitterGM107(this);
4272 emit
->setProgramType(type
);
4276 } // namespace nv50_ir