nv50_ir_emit_gk110.cpp revision 08505549ab938a6650024aab68f7713989c5c6fe
13433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller/*
23433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * Copyright 2012 Christoph Bumiller
33433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller *
43433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * Permission is hereby granted, free of charge, to any person obtaining a
53433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * copy of this software and associated documentation files (the "Software"),
63433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * to deal in the Software without restriction, including without limitation
73433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * the rights to use, copy, modify, merge, publish, distribute, sublicense,
83433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * and/or sell copies of the Software, and to permit persons to whom the
93433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * Software is furnished to do so, subject to the following conditions:
103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller *
113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * The above copyright notice and this permission notice shall be included in
123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * all copies or substantial portions of the Software.
133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller *
143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
173d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
183d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
193d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
203d8d5b298a268b119d840bc9bae0ee9e0c9244a9Kenneth Graunke * OTHER DEALINGS IN THE SOFTWARE.
213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller */
223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
235eb7ff1175a644ffe3b0f1a75cb235400355f9fbJohannes Obermayr#include "codegen/nv50_ir_target_nvc0.h"
243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller// CodeEmitter for GK110 encoding of the Fermi/Kepler ISA.
263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillernamespace nv50_ir {
283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerclass CodeEmitterGK110 : public CodeEmitter
303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerpublic:
323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   CodeEmitterGK110(const TargetNVC0 *);
333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   virtual bool emitInstruction(Instruction *);
353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   virtual uint32_t getMinEncodingSize(const Instruction *) const;
363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   virtual void prepareEmission(Function *);
373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline void setProgramType(Program::Type pType) { progType = pType; }
393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerprivate:
413741b7d844f7357fac984e8c565dedb248947487Christoph Bumiller   const TargetNVC0 *targNVC0;
423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   Program::Type progType;
443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool writeIssueDelays;
463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerprivate:
483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitForm_21(const Instruction *, uint32_t opc2, uint32_t opc1);
493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitForm_C(const Instruction *, uint32_t opc, uint8_t ctg);
503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitForm_L(const Instruction *, uint32_t opc, uint8_t ctg, Modifier);
513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitPredicate(const Instruction *);
533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void setCAddress14(const ValueRef&);
553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void setShortImmediate(const Instruction *, const int s);
563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void setImmediate32(const Instruction *, const int s, Modifier);
573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void modNegAbsF32_3b(const Instruction *, const int s);
593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitCondCode(CondCode cc, int pos, uint8_t mask);
613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitInterpMode(const Instruction *);
623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitLoadStoreType(DataType ty, const int pos);
633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitCachingMode(CacheMode c, const int pos);
643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline uint8_t getSRegEncoding(const ValueRef&);
663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitRoundMode(RoundMode, const int pos, const int rintPos);
683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitRoundModeF(RoundMode, const int pos);
693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitRoundModeI(RoundMode, const int pos);
703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitNegAbs12(const Instruction *);
723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitNOP(const Instruction *);
743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitLOAD(const Instruction *);
763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitSTORE(const Instruction *);
773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitMOV(const Instruction *);
783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitINTERP(const Instruction *);
803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitPFETCH(const Instruction *);
813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitVFETCH(const Instruction *);
823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitEXPORT(const Instruction *);
833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitOUT(const Instruction *);
843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitUADD(const Instruction *);
863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitFADD(const Instruction *);
873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitIMUL(const Instruction *);
883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitFMUL(const Instruction *);
893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitIMAD(const Instruction *);
903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitISAD(const Instruction *);
913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitFMAD(const Instruction *);
923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitNOT(const Instruction *);
943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitLogicOp(const Instruction *, uint8_t subOp);
953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitPOPC(const Instruction *);
963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitINSBF(const Instruction *);
973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitShift(const Instruction *);
983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitSFnOp(const Instruction *, uint8_t subOp);
1003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitCVT(const Instruction *);
1023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitMINMAX(const Instruction *);
1033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitPreOp(const Instruction *);
1043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitSET(const CmpInstruction *);
1063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitSLCT(const CmpInstruction *);
1073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitSELP(const Instruction *);
1083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitTEXBAR(const Instruction *);
1103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitTEX(const TexInstruction *);
1113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitTEXCSAA(const TexInstruction *);
1123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitTXQ(const TexInstruction *);
1133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitQUADOP(const Instruction *, uint8_t qOp, uint8_t laneMask);
1153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   void emitFlow(const Instruction *);
1173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline void defId(const ValueDef&, const int pos);
1193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline void srcId(const ValueRef&, const int pos);
1203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline void srcId(const ValueRef *, const int pos);
1213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline void srcId(const Instruction *, int s, const int pos);
1223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline void srcAddr32(const ValueRef&, const int pos); // address / 4
1243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   inline bool isLIMM(const ValueRef&, DataType ty, bool mod = false);
1263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller};
1273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define GK110_GPR_ZERO 255
1293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define NEG_(b, s) \
1313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(s).mod.neg()) code[(0x##b) / 32] |= 1 << ((0x##b) % 32)
1323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define ABS_(b, s) \
1333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(s).mod.abs()) code[(0x##b) / 32] |= 1 << ((0x##b) % 32)
1343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define NOT_(b, s) if (i->src(s).mod & Modifier(NV50_IR_MOD_NOT))       \
1363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[(0x##b) / 32] |= 1 << ((0x##b) % 32)
1373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define FTZ_(b) if (i->ftz) code[(0x##b) / 32] |= 1 << ((0x##b) % 32)
1393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define SAT_(b) if (i->saturate) code[(0x##b) / 32] |= 1 << ((0x##b) % 32)
1413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define RND_(b, t) emitRoundMode##t(i->rnd, 0x##b)
1433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define SDATA(a) ((a).rep()->reg.data)
1453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller#define DDATA(a) ((a).rep()->reg.data)
1463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::srcId(const ValueRef& src, const int pos)
1483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= (src.get() ? SDATA(src).id : GK110_GPR_ZERO) << (pos % 32);
1503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
1513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::srcId(const ValueRef *src, const int pos)
1533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= (src ? SDATA(*src).id : GK110_GPR_ZERO) << (pos % 32);
1553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
1563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::srcId(const Instruction *insn, int s, int pos)
1583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   int r = insn->srcExists(s) ? SDATA(insn->src(s)).id : GK110_GPR_ZERO;
1603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= r << (pos % 32);
1613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
1623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::srcAddr32(const ValueRef& src, const int pos)
1643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= (SDATA(src).offset >> 2) << (pos % 32);
1663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
1673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::defId(const ValueDef& def, const int pos)
1693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= (def.get() ? DDATA(def).id : GK110_GPR_ZERO) << (pos % 32);
1713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
1723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerbool CodeEmitterGK110::isLIMM(const ValueRef& ref, DataType ty, bool mod)
1743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const ImmediateValue *imm = ref.get()->asImm();
1763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   return imm && (imm->reg.data.u32 & ((ty == TYPE_F32) ? 0xfff : 0xfff00000));
1783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
1793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
1813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitRoundMode(RoundMode rnd, const int pos, const int rintPos)
1823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   bool rint = false;
1843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t n;
1853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (rnd) {
1873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_MI: rint = true; /* fall through */ case ROUND_M: n = 1; break;
1883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_PI: rint = true; /* fall through */ case ROUND_P: n = 2; break;
1893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_ZI: rint = true; /* fall through */ case ROUND_Z: n = 3; break;
1903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
1913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      rint = rnd == ROUND_NI;
1923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
1933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(rnd == ROUND_N || rnd == ROUND_NI);
1943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
1953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
1963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= n << (pos % 32);
1973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (rint && rintPos >= 0)
1983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[rintPos / 32] |= 1 << (rintPos % 32);
1993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
2003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
2023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitRoundModeF(RoundMode rnd, const int pos)
2033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
2043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t n;
2053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (rnd) {
2073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_M: n = 1; break;
2083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_P: n = 2; break;
2093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_Z: n = 3; break;
2103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
2113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
2123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(rnd == ROUND_N);
2133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
2143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
2153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= n << (pos % 32);
2163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
2173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
2193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitRoundModeI(RoundMode rnd, const int pos)
2203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
2213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t n;
2223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (rnd) {
2243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_MI: n = 1; break;
2253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_PI: n = 2; break;
2263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case ROUND_ZI: n = 3; break;
2273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
2283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
2293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(rnd == ROUND_NI);
2303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
2313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
2323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= n << (pos % 32);
2333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
2343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::emitCondCode(CondCode cc, int pos, uint8_t mask)
2363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
2373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t n;
2383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (cc) {
2403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_FL:  n = 0x00; break;
2413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_LT:  n = 0x01; break;
2423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_EQ:  n = 0x02; break;
2433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_LE:  n = 0x03; break;
2443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_GT:  n = 0x04; break;
2453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_NE:  n = 0x05; break;
2463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_GE:  n = 0x06; break;
2473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_LTU: n = 0x09; break;
2483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_EQU: n = 0x0a; break;
2493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_LEU: n = 0x0b; break;
2503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_GTU: n = 0x0c; break;
2513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_NEU: n = 0x0d; break;
2523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_GEU: n = 0x0e; break;
2533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_TR:  n = 0x0f; break;
2543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_NO:  n = 0x10; break;
2553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_NC:  n = 0x11; break;
2563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_NS:  n = 0x12; break;
2573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_NA:  n = 0x13; break;
2583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_A:   n = 0x14; break;
2593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_S:   n = 0x15; break;
2603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_C:   n = 0x16; break;
2613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CC_O:   n = 0x17; break;
2623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
2633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
2643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid condition code");
2653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
2663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
2673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= (n & mask) << (pos % 32);
2683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
2693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
2713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitPredicate(const Instruction *i)
2723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
2733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->predSrc >= 0) {
2743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      srcId(i->src(i->predSrc), 18);
2753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->cc == CC_NOT_P)
2763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[0] |= 8 << 18; // negate
2773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(i->getPredicate()->reg.file == FILE_PREDICATE);
2783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
2793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= 7 << 18;
2803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
2813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
2823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
2843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::setCAddress14(const ValueRef& src)
2853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
2863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const int32_t addr = src.get()->asSym()->reg.data.offset / 4;
2873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] |= (addr & 0x01ff) << 23;
2893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= (addr & 0x3e00) >> 9;
2903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
2913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
2933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::setShortImmediate(const Instruction *i, const int s)
2943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
2953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const uint32_t u32 = i->getSrc(s)->asImm()->reg.data.u32;
2963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const uint64_t u64 = i->getSrc(s)->asImm()->reg.data.u64;
2973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
2983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->sType == TYPE_F32) {
2993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!(u32 & 0x00000fff));
3003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= ((u32 & 0x001ff000) >> 12) << 23;
3013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= ((u32 & 0x7fe00000) >> 21);
3023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= ((u32 & 0x80000000) >> 4);
3033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
3043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->sType == TYPE_F64) {
3053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!(u64 & 0x00000fffffffffffULL));
3063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= ((u64 & 0x001ff00000000000ULL) >> 44) << 23;
3073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= ((u64 & 0x7fe0000000000000ULL) >> 53);
3083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= ((u64 & 0x8000000000000000ULL) >> 36);
3093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
3103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert((u32 & 0xfff00000) == 0 || (u32 & 0xfff00000) == 0xfff00000);
3113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= (u32 & 0x001ff) << 23;
3123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= (u32 & 0x7fe00) >> 9;
3133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= (u32 & 0x80000) << 8;
3143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
3153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
3163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
3183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::setImmediate32(const Instruction *i, const int s,
3193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller                                 Modifier mod)
3203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
3213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint32_t u32 = i->getSrc(s)->asImm()->reg.data.u32;
3223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (mod) {
3243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ImmediateValue imm(i->getSrc(s)->asImm(), i->sType);
3253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      mod.applyTo(imm);
3263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      u32 = imm.reg.data.u32;
3273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
3283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] |= u32 << 23;
3303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= u32 >> 9;
3313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
3323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
3343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitForm_L(const Instruction *i, uint32_t opc, uint8_t ctg,
3353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller                             Modifier mod)
3363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
3373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = ctg;
3383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] = opc << 20;
3393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
3413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
3433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   for (int s = 0; s < 3 && i->srcExists(s); ++s) {
3453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->src(s).getFile()) {
3463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case FILE_GPR:
3473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         srcId(i->src(s), s ? 42 : 10);
3483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
3493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case FILE_IMMEDIATE:
3503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         setImmediate32(i, s, mod);
3513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
3523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
3533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
3543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
3553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
3563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
3573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
3603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitForm_C(const Instruction *i, uint32_t opc, uint8_t ctg)
3613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
3623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = ctg;
3633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] = opc << 20;
3643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
3663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
3683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->src(0).getFile()) {
3703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_CONST:
3713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0x4 << 28;
3723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      setCAddress14(i->src(0));
3733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
3743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_GPR:
3753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0xc << 28;
3763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      srcId(i->src(0), 23);
3773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
3783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
3793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(0);
3803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
3813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
3823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
3833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller// 0x2 for GPR, c[] and 0x1 for short immediate
3853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
3863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitForm_21(const Instruction *i, uint32_t opc2,
3873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller                              uint32_t opc1)
3883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
3893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool imm = i->srcExists(1) && i->src(1).getFile() == FILE_IMMEDIATE;
3903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   int s1 = 23;
3923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->srcExists(2) && i->src(2).getFile() == FILE_MEMORY_CONST)
3933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      s1 = 42;
3943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
3953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (imm) {
3963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x1;
3973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] = opc1 << 20;
3983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
3993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x2;
4003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] = (0xc << 28) | (opc2 << 20);
4013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
4023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
4043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
4063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   for (int s = 0; s < 3 && i->srcExists(s); ++s) {
4083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->src(s).getFile()) {
4093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case FILE_MEMORY_CONST:
4103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] &= (s == 2) ? ~(0x4 << 28) : ~(0x8 << 28);
4113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         setCAddress14(i->src(s));
4123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= i->getSrc(s)->reg.fileIndex << 5;
4133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
4143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case FILE_IMMEDIATE:
4153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         setShortImmediate(i, s);
4163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
4173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case FILE_GPR:
4183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         srcId(i->src(s), s ? ((s == 2) ? 42 : s1) : 10);
4193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
4203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
4213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         // ignore here, can be predicate or flags, but must not be address
4223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
4233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
4243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
4253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // 0x0 = invalid
4263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // 0xc = rrr
4273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // 0x8 = rrc
4283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // 0x4 = rcr
4293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(imm || (code[1] & (0xc << 28)));
4303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
4313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerinline void
4333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::modNegAbsF32_3b(const Instruction *i, const int s)
4343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
4353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(s).mod.abs()) code[1] &= ~(1 << 27);
4363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(s).mod.neg()) code[1] ^=  (1 << 27);
4373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
4383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
4403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitNOP(const Instruction *i)
4413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
4423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = 0x00003c02;
4433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] = 0x85800000;
4443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i)
4463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPredicate(i);
4473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   else
4483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x001c3c02;
4493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
4503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
4523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitFMAD(const Instruction *i)
4533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
4543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!isLIMM(i->src(1), TYPE_F32));
4553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x0c0, 0x940);
4573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   NEG_(34, 2);
4593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   SAT_(35);
4603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   RND_(36, F);
4613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   FTZ_(38);
4623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   bool neg1 = (i->src(0).mod ^ i->src(1).mod).neg();
4643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (code[0] & 0x1) {
4663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (neg1)
4673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] ^= 1 << 27;
4683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
4693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (neg1) {
4703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 19;
4713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
4723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
4733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
4753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitFMUL(const Instruction *i)
4763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
4773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   bool neg = (i->src(0).mod ^ i->src(1).mod).neg();
4783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(i->postFactor >= -3 && i->postFactor <= 3);
4803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (isLIMM(i->src(1), TYPE_F32)) {
4823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_L(i, 0x200, 0x2, Modifier(0));
4833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(38);
4853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      SAT_(3a);
4863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (neg)
4873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] ^= 1 << 22;
4883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(i->postFactor == 0);
4903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
4913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x234, 0xc34);
4923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      RND_(2a, F);
4943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(2f);
4953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      SAT_(35);
4963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
4973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (code[0] & 0x1) {
4983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         if (neg)
4993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller            code[1] ^= 1 << 27;
5003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      } else
5013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (neg) {
5023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 19;
5033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
5043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
5053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
5063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
5083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitIMUL(const Instruction *i)
5093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
5103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!i->src(0).mod.neg() && !i->src(1).mod.neg());
5113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!i->src(0).mod.abs() && !i->src(1).mod.abs());
5123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (isLIMM(i->src(1), TYPE_S32)) {
5143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_L(i, 0x280, 2, Modifier(0));
5153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(i->subOp != NV50_IR_SUBOP_MUL_HIGH);
5173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->sType == TYPE_S32)
5193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 3 << 25;
5203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
5213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x21c, 0xc1c);
5223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->subOp == NV50_IR_SUBOP_MUL_HIGH)
5243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 10;
5253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->sType == TYPE_S32)
5263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 3 << 11;
5273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
5283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
5293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
5313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitFADD(const Instruction *i)
5323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
5333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (isLIMM(i->src(1), TYPE_F32)) {
5343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(i->rnd == ROUND_N);
5353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!i->saturate);
5363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_L(i, 0x400, 0, i->src(1).mod);
5383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(3a);
5403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NEG_(3b, 0);
5413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ABS_(39, 0);
5423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
5433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x22c, 0xc2c);
5443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(2f);
5463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      RND_(2a, F);
5473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ABS_(31, 0);
5483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NEG_(33, 0);
5493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (code[0] & 0x1) {
5513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         modNegAbsF32_3b(i, 1);
5523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      } else {
5533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         ABS_(34, 1);
5543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         NEG_(30, 1);
5553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
5563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
5573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
5583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
5603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitUADD(const Instruction *i)
5613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
5623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t addOp = (i->src(0).mod.neg() << 1) | i->src(1).mod.neg();
5633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->op == OP_SUB)
5653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      addOp ^= 1;
5663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!i->src(0).mod.abs() && !i->src(1).mod.abs());
5683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (isLIMM(i->src(1), TYPE_S32)) {
5703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_L(i, 0x400, 1, Modifier((addOp & 1) ? NV50_IR_MOD_NEG : 0));
5713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (addOp & 2)
5733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 27;
5743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!i->defExists(1));
5763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(i->flagsSrc < 0);
5773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      SAT_(39);
5793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
5803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x208, 0xc08);
5813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(addOp != 3); // would be add-plus-one
5833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= addOp << 19;
5853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->defExists(1))
5873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 18; // write carry
5883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->flagsSrc >= 0)
5893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 14; // add carry
5903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      SAT_(35);
5923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
5933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
5943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
5953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller// TODO: shl-add
5963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
5973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitIMAD(const Instruction *i)
5983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
5993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t addOp =
6003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      (i->src(2).mod.neg() << 1) | (i->src(0).mod.neg() ^ i->src(1).mod.neg());
6013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x100, 0xa00);
6033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(addOp != 3);
6053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= addOp << 26;
6063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->sType == TYPE_S32)
6083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= (1 << 19) | (1 << 24);
6093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (code[0] & 0x1) {
6113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!i->subOp);
6123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      SAT_(39);
6133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
6143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->subOp == NV50_IR_SUBOP_MUL_HIGH)
6153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 25;
6163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      SAT_(35);
6173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
6183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
6193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
6213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitISAD(const Instruction *i)
6223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
6233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(i->dType == TYPE_S32 || i->dType == TYPE_U32);
6243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x1fc, 0xb74);
6263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->dType == TYPE_S32)
6283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 19;
6293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
6303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
6323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitNOT(const Instruction *i)
6333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
6343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = 0x0003fc02; // logop(mov2) dst, 0, not src
6353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] = 0x22003800;
6363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
6383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
6403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->src(0).getFile()) {
6423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_GPR:
6433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0xc << 28;
6443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      srcId(i->src(0), 23);
6453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
6463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_CONST:
6473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0x4 << 28;
6483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      setCAddress14(i->src(1));
6493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
6503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
6513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(0);
6523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
6533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
6543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
6553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
6573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitLogicOp(const Instruction *i, uint8_t subOp)
6583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
6593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!(i->src(0).mod & Modifier(NV50_IR_MOD_NOT))); // XXX: find me
6603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (isLIMM(i->src(1), TYPE_S32)) {
6623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_L(i, 0x200, 0, i->src(1).mod);
6633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= subOp << 24;
6643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
6653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x220, 0xc20);
6663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= subOp << 12;
6673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NOT_(2b, 1);
6683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
6693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!(code[0] & 0x1) || !(i->src(1).mod & Modifier(NV50_IR_MOD_NOT)));
6703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
6713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
6733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitPOPC(const Instruction *i)
6743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
6753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   assert(!isLIMM(i->src(1), TYPE_S32, true));
6763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x204, 0xc04);
6783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   NOT_(2a, 0);
6803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (!(code[0] & 0x1))
6813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NOT_(2b, 1);
6823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
6833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
6853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitINSBF(const Instruction *i)
6863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
6873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x1f8, 0xb78);
6883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
6893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
6913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitShift(const Instruction *i)
6923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
6933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool sar = i->op == OP_SHR && isSignedType(i->sType);
6943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
6953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (sar) {
6963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x214, 0x014);
6973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 19;
6983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
6993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->op == OP_SHR) {
7003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // this is actually RSHF
7013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x27c, 0x87c);
7023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= GK110_GPR_ZERO << 10;
7033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
7043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // this is actually LSHF
7053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x1fc, 0xb7c);
7063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= GK110_GPR_ZERO << 10;
7073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
7083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->subOp == NV50_IR_SUBOP_SHIFT_WRAP) {
7103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (!sar)
7113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= 1 << 21;
7123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // XXX: find wrap modifier for SHR S32
7133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
7143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
7153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
7173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitPreOp(const Instruction *i)
7183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
7193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x248, -1);
7203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->op == OP_PREEX2)
7223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 10;
7233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   NEG_(30, 0);
7253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   ABS_(34, 0);
7263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
7273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
7293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitSFnOp(const Instruction *i, uint8_t subOp)
7303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
7313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = 0x00000002 | (subOp << 23);
7323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] = 0x84000000;
7333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
7353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
7373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   srcId(i->src(0), 10);
7383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   NEG_(33, 0);
7403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   ABS_(31, 0);
741ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   SAT_(35);
7423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
7433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
7453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitMINMAX(const Instruction *i)
7463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
7473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint32_t op2, op1;
7483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->dType) {
7503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_U32:
7513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_S32:
7523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op2 = 0x210;
7533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op1 = 0xc10;
7543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
7553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_F32:
7563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op2 = 0x230;
7573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op1 = 0xc30;
7583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
7593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_F64:
7603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op2 = 0x228;
7613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op1 = 0xc28;
7623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
7633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
7643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(0);
7653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op2 = 0;
7663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      op1 = 0;
7673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
7683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
7693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, op2, op1);
7703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->dType == TYPE_S32)
7723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 19;
7733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= (i->op == OP_MIN) ? 0x1c00 : 0x3c00; // [!]pt
7743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   FTZ_(2f);
7763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   ABS_(31, 0);
7773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   NEG_(33, 0);
7783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (code[0] & 0x1) {
7793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      modNegAbsF32_3b(i, 1);
7803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
7813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ABS_(34, 1);
7823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NEG_(30, 1);
7833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
7843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
7853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
7873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitCVT(const Instruction *i)
7883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
7893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool f2f = isFloatType(i->dType) && isFloatType(i->sType);
7903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool f2i = !isFloatType(i->dType) && isFloatType(i->sType);
7913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool i2f = isFloatType(i->dType) && !isFloatType(i->sType);
7923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   bool sat = i->saturate;
7943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   bool abs = i->src(0).mod.abs();
7953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   bool neg = i->src(0).mod.neg();
7963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   RoundMode rnd = i->rnd;
7983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
7993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->op) {
8003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CEIL:  rnd = f2f ? ROUND_PI : ROUND_P; break;
8013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_FLOOR: rnd = f2f ? ROUND_MI : ROUND_M; break;
8023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TRUNC: rnd = f2f ? ROUND_ZI : ROUND_Z; break;
8033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SAT: sat = true; break;
8043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_NEG: neg = !neg; break;
8053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_ABS: abs = true; neg = false; break;
8063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
8073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
8083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
8093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
81018d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin   DataType dType;
81118d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin
81218d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin   if (i->op == OP_NEG && i->dType == TYPE_U32)
81318d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin      dType = TYPE_S32;
81418d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin   else
81518d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin      dType = i->dType;
81618d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin
81718d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin
8183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint32_t op;
8193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if      (f2f) op = 0x254;
8213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   else if (f2i) op = 0x258;
8223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   else if (i2f) op = 0x25c;
8233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   else          op = 0x260;
8243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_C(i, op, 0x2);
8263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   FTZ_(2f);
8283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (neg) code[1] |= 1 << 16;
8293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (abs) code[1] |= 1 << 20;
8303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (sat) code[1] |= 1 << 21;
8313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitRoundMode(rnd, 32 + 10, f2f ? (32 + 13) : -1);
8333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
83418d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin   code[0] |= typeSizeofLog2(dType) << 10;
8353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] |= typeSizeofLog2(i->sType) << 12;
8363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
83718d97a8df776863c89c52294055160a17fc0f9e6Ilia Mirkin   if (isSignedIntType(dType))
8383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= 0x4000;
8393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (isSignedIntType(i->sType))
8403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= 0x8000;
8413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
8423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
8443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitSET(const CmpInstruction *i)
8453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
8463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint16_t op1, op2;
8473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->def(0).getFile() == FILE_PREDICATE) {
8493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->sType) {
8503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case TYPE_F32: op2 = 0x1d8; op1 = 0xb58; break;
8513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case TYPE_F64: op2 = 0x1c0; op1 = 0xb40; break;
8523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
8533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         op2 = 0x1b0;
8543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         op1 = 0xb30;
8553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
8563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
8573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, op2, op1);
8583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NEG_(2e, 0);
8603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ABS_(9, 0);
8613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (!(code[0] & 0x1)) {
8623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         NEG_(8, 1);
8633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         ABS_(2f, 1);
8643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      } else {
8653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         modNegAbsF32_3b(i, 1);
8663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
8673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(32);
8683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // normal DST field is negated predicate result
8703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = (code[0] & ~0xfc) | ((code[0] << 3) & 0xe0);
8713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->defExists(1))
8723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         defId(i->def(1), 2);
8733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   else
8743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= 0x1c;
8753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
8763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->sType) {
8773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case TYPE_F32: op2 = 0x000; op1 = 0x820; break;
8783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case TYPE_F64: op2 = 0x080; op1 = 0x900; break;
8793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
8803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         op2 = 0x1a8;
8813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         op1 = 0xb28;
8823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
8833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
8843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, op2, op1);
8853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      NEG_(2e, 0);
8873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ABS_(39, 0);
8883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (!(code[0] & 0x1)) {
8893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         NEG_(38, 1);
8903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         ABS_(2f, 1);
8913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      } else {
8923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         modNegAbsF32_3b(i, 1);
8933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
8943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(3a);
8953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
8963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->sType == TYPE_S32)
8973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 19;
8983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
8993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->op != OP_SET) {
9003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->op) {
9013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case OP_SET_AND: code[1] |= 0x0 << 16; break;
9023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case OP_SET_OR:  code[1] |= 0x1 << 16; break;
9033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case OP_SET_XOR: code[1] |= 0x2 << 16; break;
9043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
9053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         assert(0);
9063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
9073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
9083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      srcId(i->src(2), 0x2a);
9093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
9103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0x7 << 10;
9113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
9123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitCondCode(i->setCond,
9133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller                isFloatType(i->sType) ? 0x33 : 0x34,
9143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller                isFloatType(i->sType) ? 0xf : 0x7);
9153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
9163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
9183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitSLCT(const CmpInstruction *i)
9193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
9203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   CondCode cc = i->setCond;
9213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(2).mod.neg())
9223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      cc = reverseCondCode(cc);
9233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->dType == TYPE_F32) {
9253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x1d0, 0xb50);
9263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      FTZ_(32);
9273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitCondCode(cc, 0x33, 0xf);
9283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
9293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_21(i, 0x1a4, 0xb20);
9303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitCondCode(cc, 0x34, 0x7);
9313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
9323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
9333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::emitSELP(const Instruction *i)
9353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
9363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitForm_21(i, 0x250, 0x050);
9373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if ((i->cc == CC_NOT_P) ^ (bool)(i->src(2).mod & Modifier(NV50_IR_MOD_NOT)))
9393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 1 << 13;
9403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
9413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::emitTEXBAR(const Instruction *i)
9433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
9443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = 0x00000002 | (i->subOp << 23);
9453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] = 0x77000000;
9463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
9483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
9493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid CodeEmitterGK110::emitTEXCSAA(const TexInstruction *i)
9513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
95208505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   code[0] = 0x00000002;
95308505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   code[1] = 0x76c00000;
95408505549ab938a6650024aab68f7713989c5c6feIlia Mirkin
95508505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   // code[1] |= i->tex.r << 9;
95608505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   // code[1] |= i->tex.s << (9 + 8);
95708505549ab938a6650024aab68f7713989c5c6feIlia Mirkin
95808505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   if (i->tex.liveOnly)
95908505549ab938a6650024aab68f7713989c5c6feIlia Mirkin      code[0] |= 0x80000000;
96008505549ab938a6650024aab68f7713989c5c6feIlia Mirkin
96108505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   defId(i->def(0), 2);
96208505549ab938a6650024aab68f7713989c5c6feIlia Mirkin   srcId(i->src(0), 10);
9633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
9643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerstatic inline bool
9663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerisNextIndependentTex(const TexInstruction *i)
9673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
9683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (!i->next || !isTextureOp(i->next->op))
9693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
9703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->getDef(0)->interfers(i->next->getSrc(0)))
9713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
9723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   return !i->next->srcExists(1) || !i->getDef(0)->interfers(i->next->getSrc(1));
9733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
9743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
9763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitTEX(const TexInstruction *i)
9773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
9783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const bool ind = i->tex.rIndirectSrc >= 0;
9793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
9803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (ind) {
9813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x00000002;
9823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->op) {
9833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case OP_TXD:
9843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] = 0x7e000000;
9853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
986cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin      case OP_TXF:
987cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin         code[1] = 0x78000000;
988cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin         break;
9893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
9903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] = 0x7d800000;
9913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
9923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
9933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
9943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (i->op) {
9953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case OP_TXD:
9963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[0] = 0x00000002;
9973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] = 0x76000000;
9983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
999cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin      case OP_TXF:
1000cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin         code[0] = 0x00000002;
1001cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin         code[1] = 0x70000000;
1002cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin         break;
10033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
10043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[0] = 0x00000001;
10053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] = 0x60000000;
10063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
10073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
10083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= i->tex.r << 15;
10093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
10103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= isNextIndependentTex(i) ? 0x1 : 0x2; // t : p mode
10123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1013cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin   if (i->tex.liveOnly)
1014cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin      code[0] |= 0x80000000;
10153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->op) {
10173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TEX: break;
10183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXB: code[1] |= 0x2000; break;
10193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXL: code[1] |= 0x3000; break;
1020cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin   case OP_TXF: break;
10213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXG: break; // XXX
10223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXD: break;
10233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
10243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid texture op");
10253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
10263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
1027cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin
10283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->op == OP_TXF) {
10293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (!i->tex.levelZero)
1030cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin         code[1] |= 0x1000;
1031cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin   } else
10323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->tex.levelZero) {
10333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0x1000;
10343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
10353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // if (i->op != OP_TXD && i->tex.derivAll)
10373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   //   code[1] |= 1 << 13;
10383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
10403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= i->tex.mask << 2;
10423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const int src1 = (i->predSrc == 1) ? 2 : 1; // if predSrc == 1, !srcExists(2)
10443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
10463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   srcId(i->src(0), 10);
10473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   srcId(i, src1, 23);
10483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // if (i->op == OP_TXG) code[0] |= i->tex.gatherComp << 5;
10503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // texture target:
10523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= (i->tex.target.isCube() ? 3 : (i->tex.target.getDim() - 1)) << 7;
10533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->tex.target.isArray())
10543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= 0x40;
1055cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin   if (i->tex.target.isShadow())
1056cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin      code[1] |= 0x400;
1057cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin   if (i->tex.target == TEX_TARGET_2D_MS ||
1058cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin       i->tex.target == TEX_TARGET_2D_MS_ARRAY)
1059cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin      code[1] |= 0x800;
10603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->srcExists(src1) && i->src(src1).getFile() == FILE_IMMEDIATE) {
10623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // ?
10633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
10643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1065cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin   if (i->tex.useOffsets)
1066cb3dcb14300613a7628941ff4ba1ad4c52e9772bIlia Mirkin      code[1] |= 0x200;
10673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
10683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
10693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
10703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitTXQ(const TexInstruction *i)
10713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
107276554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   code[0] = 0x00000002;
107376554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   code[1] = 0x75400001;
107476554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin
107576554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   switch (i->tex.query) {
107676554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   case TXQ_DIMS:            code[0] |= 0x01 << 25; break;
107776554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   case TXQ_TYPE:            code[0] |= 0x02 << 25; break;
107876554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   case TXQ_SAMPLE_POSITION: code[0] |= 0x05 << 25; break;
107976554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   case TXQ_FILTER:          code[0] |= 0x10 << 25; break;
108076554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   case TXQ_LOD:             code[0] |= 0x12 << 25; break;
108176554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   case TXQ_BORDER_COLOUR:   code[0] |= 0x16 << 25; break;
108276554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   default:
108376554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin      assert(!"invalid texture query");
108476554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin      break;
108576554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   }
108676554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin
108776554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   // TODO:
108876554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   // code[1] |= i->tex.mask << 14;
108976554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   //
109076554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   // code[1] |= i->tex.r << 9;
109176554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   // code[1] |= i->tex.s << 2;
109276554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   // if (i->tex.sIndirectSrc >= 0 || i->tex.rIndirectSrc >= 0)
109376554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   //   ?
109476554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin
109576554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   defId(i->def(0), 2);
109676554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   srcId(i->src(0), 10);
109776554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin
109876554d2d1f3e017370a7ef1b3ea511f83cd83573Ilia Mirkin   emitPredicate(i);
10993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
11003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
11023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitQUADOP(const Instruction *i, uint8_t qOp, uint8_t laneMask)
11033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
11043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitNOP(i); // TODO
11053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
11063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
11083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitFlow(const Instruction *i)
11093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
11103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const FlowInstruction *f = i->asFlow();
11113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   unsigned mask; // bit 0: predicate, bit 1: target
11133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] = 0x00000000;
11153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->op) {
11173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_BRA:
1118ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin      code[1] = f->absolute ? 0x10800000 : 0x12000000;
1119ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin      if (i->srcExists(0) && i->src(0).getFile() == FILE_MEMORY_CONST)
1120ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin         code[0] |= 0x80;
11213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      mask = 3;
11223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
11233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CALL:
1124ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin      code[1] = f->absolute ? 0x11000000 : 0x13000000;
1125ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin      if (i->srcExists(0) && i->src(0).getFile() == FILE_MEMORY_CONST)
1126ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin         code[0] |= 0x80;
11273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      mask = 2;
11283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
11293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_EXIT:    code[1] = 0x18000000; mask = 1; break;
11313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_RET:     code[1] = 0x19000000; mask = 1; break;
1132ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_DISCARD: code[1] = 0x19800000; mask = 1; break;
1133ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_BREAK:   code[1] = 0x1a000000; mask = 1; break;
1134ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_CONT:    code[1] = 0x1a800000; mask = 1; break;
11353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_JOINAT:   code[1] = 0x14800000; mask = 2; break;
1137ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_PREBREAK: code[1] = 0x15000000; mask = 2; break;
1138ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_PRECONT:  code[1] = 0x15800000; mask = 2; break;
1139ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_PRERET:   code[1] = 0x13800000; mask = 2; break;
11403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
1141ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_QUADON:  code[1] = 0x1b000000; mask = 0; break;
1142ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_QUADPOP: code[1] = 0x1c000000; mask = 0; break;
1143ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin   case OP_BRKPT:   code[1] = 0x00000000; mask = 0; break;
11443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
11453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid flow operation");
11463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return;
11473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
11483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (mask & 1) {
11503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPredicate(i);
11513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->flagsSrc < 0)
11523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[0] |= 0x3c;
11533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
11543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (!f)
11563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return;
11573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (f->allWarp)
1159ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin      code[0] |= 1 << 9;
11603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (f->limit)
1161ce75a3e8d36e85214e98194ca212504282df47f9Ilia Mirkin      code[0] |= 1 << 8;
11623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (f->op == OP_CALL) {
11643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (f->builtin) {
11653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         assert(f->absolute);
11663741b7d844f7357fac984e8c565dedb248947487Christoph Bumiller         uint32_t pcAbs = targNVC0->getBuiltinOffset(f->target.builtin);
11673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         addReloc(RelocEntry::TYPE_BUILTIN, 0, pcAbs, 0xff800000, 23);
11683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         addReloc(RelocEntry::TYPE_BUILTIN, 1, pcAbs, 0x007fffff, -9);
11693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      } else {
11703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         assert(!f->absolute);
11713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         int32_t pcRel = f->target.fn->binPos - (codeSize + 8);
11723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[0] |= (pcRel & 0x1ff) << 23;
11733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] |= (pcRel >> 9) & 0x7fff;
11743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
11753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
11763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (mask & 2) {
11773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      int32_t pcRel = f->target.bb->binPos - (codeSize + 8);
11783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // currently we don't want absolute branches
11793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!f->absolute);
11803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= (pcRel & 0x1ff) << 23;
11813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= (pcRel >> 9) & 0x7fff;
11823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
11833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
11843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
11863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitPFETCH(const Instruction *i)
11873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1188c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin   uint32_t prim = i->src(0).get()->reg.data.u32;
1189c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin
1190c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin   code[0] = 0x00000002 | ((prim & 0xff) << 23);
1191c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin   code[1] = 0x7f800000;
1192c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin
1193c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin   emitPredicate(i);
1194c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin
1195c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin   defId(i->def(0), 2);
1196c17f7247ec5b7acf44e462accf5b5124fb713772Ilia Mirkin   srcId(i->src(1), 10);
11973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
11983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
11993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
12003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitVFETCH(const Instruction *i)
12013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1202c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   uint32_t offset = i->src(0).get()->reg.data.offset;
1203c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1204c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[0] = 0x00000002 | (offset << 23);
1205c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[1] = 0x7ec00000 | (offset >> 9);
1206c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1207c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs#if 0
1208c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   if (i->perPatch)
1209c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      code[0] |= 0x100;
1210c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   if (i->getSrc(0)->reg.file == FILE_SHADER_OUTPUT)
1211c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      code[0] |= 0x200; // yes, TCPs can read from *outputs* of other threads
1212c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs#endif
1213c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1214c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   emitPredicate(i);
1215c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1216c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   defId(i->def(0), 2);
1217c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   srcId(i->src(0).getIndirect(0), 10);
1218c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   srcId(i->src(0).getIndirect(1), 32 + 10); // vertex address
12193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
12203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
12213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
12223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitEXPORT(const Instruction *i)
12233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1224c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   uint32_t offset = i->src(0).get()->reg.data.offset;
1225c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1226c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[0] = 0x00000002 | (offset << 23);
1227c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[1] = 0x7f000000 | (offset >> 9);
1228c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1229c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs#if 0
1230c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   if (i->perPatch)
1231c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      code[0] |= 0x100;
1232c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs#endif
1233c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1234c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   emitPredicate(i);
1235c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1236c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   assert(i->src(1).getFile() == FILE_GPR);
1237c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1238c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   srcId(i->src(0).getIndirect(0), 10);
1239c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   srcId(i->src(0).getIndirect(1), 32 + 10); // vertex base address
1240c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   srcId(i->src(1), 2);
12413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
12423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
12433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
12443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitOUT(const Instruction *i)
12453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
124615b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin   assert(i->src(0).getFile() == FILE_GPR);
124715b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin
124815b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin   emitForm_21(i, 0x1f0, 0xb70);
124915b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin
125015b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin   if (i->op == OP_EMIT)
125115b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin      code[1] |= 1 << 10;
125215b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin   if (i->op == OP_RESTART || i->subOp == NV50_IR_SUBOP_EMIT_RESTART)
125315b1f420d04e2fbff8e1ed4a863239e8ddf602deIlia Mirkin      code[1] |= 1 << 11;
12543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
12553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
12563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
12573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitInterpMode(const Instruction *i)
12583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1259c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[1] |= i->ipa << 21; // TODO: INTERP_SAMPLEID
12603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
12613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
12623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
12633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitINTERP(const Instruction *i)
12643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
1265c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   const uint32_t base = i->getSrc(0)->reg.data.offset;
1266c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1267c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[0] = 0x00000002 | (base << 31);
1268c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   code[1] = 0x74800000 | (base >> 1);
1269c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1270c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   if (i->saturate)
1271c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      code[1] |= 1 << 18;
1272c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1273c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   if (i->op == OP_PINTERP)
1274c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      srcId(i->src(1), 23);
1275c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   else
1276c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      code[0] |= 0xff << 23;
1277c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1278c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   srcId(i->src(0).getIndirect(0), 10);
1279c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   emitInterpMode(i);
1280c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1281c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   emitPredicate(i);
1282c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   defId(i->def(0), 2);
1283c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs
1284c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   if (i->getSampleMode() == NV50_IR_INTERP_OFFSET)
1285c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      srcId(i->src(i->op == OP_PINTERP ? 2 : 1), 32 + 10);
1286c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs   else
1287c29c6b2b2e65f73c75c70daae1d2d32e53964120Ben Skeggs      code[1] |= 0xff << 10;
12883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
12893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
12903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
12913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitLoadStoreType(DataType ty, const int pos)
12923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
12933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t n;
12943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
12953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (ty) {
12963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_U8:
12973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
12983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
12993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_S8:
13003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 1;
13013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_U16:
13033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 2;
13043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_S16:
13063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 3;
13073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_F32:
13093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_U32:
13103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_S32:
13113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 4;
13123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_F64:
13143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_U64:
13153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_S64:
13163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 5;
13173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case TYPE_B128:
13193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 6;
13203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
13223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
13233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid ld/st type");
13243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
13263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= n << (pos % 32);
13273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
13283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
13303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitCachingMode(CacheMode c, const int pos)
13313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
13323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   uint8_t n;
13333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (c) {
13353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CACHE_CA:
13363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller// case CACHE_WB:
13373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
13383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CACHE_CG:
13403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 1;
13413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CACHE_CS:
13433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 2;
13443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case CACHE_CV:
13463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller// case CACHE_WT:
13473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 3;
13483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
13503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      n = 0;
13513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid caching mode");
13523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
13543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[pos / 32] |= n << (pos % 32);
13553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
13563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
13583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitSTORE(const Instruction *i)
13593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
13603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   int32_t offset = SDATA(i->src(0)).offset;
13613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->src(0).getFile()) {
13633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_GLOBAL: code[1] = 0xe0000000; code[0] = 0x00000000; break;
13643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_LOCAL:  code[1] = 0x7a800000; code[0] = 0x00000002; break;
13653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_SHARED: code[1] = 0x7ac00000; code[0] = 0x00000002; break;
13663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
13673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid memory file");
13683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
13693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
13703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(0).getFile() != FILE_MEMORY_GLOBAL)
13723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      offset &= 0xffffff;
13733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (code[0] & 0x2) {
13753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLoadStoreType(i->dType, 0x33);
13763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->src(0).getFile() == FILE_MEMORY_LOCAL)
13773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitCachingMode(i->cache, 0x2f);
13783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
13793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLoadStoreType(i->dType, 0x38);
13803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitCachingMode(i->cache, 0x3b);
13813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
13823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] |= offset << 23;
13833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= offset >> 9;
13843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
13863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   srcId(i->src(1), 2);
13883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   srcId(i->src(0).getIndirect(0), 10);
13893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
13903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
13923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitLOAD(const Instruction *i)
13933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
13943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   int32_t offset = SDATA(i->src(0)).offset;
13953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
13963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (i->src(0).getFile()) {
13973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_GLOBAL: code[1] = 0xc0000000; code[0] = 0x00000000; break;
13983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_LOCAL:  code[1] = 0x7a000000; code[0] = 0x00000002; break;
13993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_SHARED: code[1] = 0x7ac00000; code[0] = 0x00000002; break;
14003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case FILE_MEMORY_CONST:
14013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (!i->src(0).isIndirect(0) && typeSizeof(i->dType) == 4) {
14023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitMOV(i);
14033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         return;
14043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
14053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      offset &= 0xffff;
14063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x00000002;
14073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] = 0x7c800000 | (i->src(0).get()->reg.fileIndex << 7);
14083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
14093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
14103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"invalid memory file");
14113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
14123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
14133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (code[0] & 0x2) {
14153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      offset &= 0xffffff;
14163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLoadStoreType(i->dType, 0x33);
14173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (i->src(0).getFile() == FILE_MEMORY_LOCAL)
14183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitCachingMode(i->cache, 0x2f);
14193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
14203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLoadStoreType(i->dType, 0x38);
14213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitCachingMode(i->cache, 0x3b);
14223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
14233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[0] |= offset << 23;
14243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code[1] |= offset >> 9;
14253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emitPredicate(i);
14273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   defId(i->def(0), 2);
14293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   srcId(i->src(0).getIndirect(0), 10);
14303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
14313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumilleruint8_t
14333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::getSRegEncoding(const ValueRef& ref)
14343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
14353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (SDATA(ref).sv.sv) {
14363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_LANEID:        return 0x00;
14373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_PHYSID:        return 0x03;
14383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_VERTEX_COUNT:  return 0x10;
14393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_INVOCATION_ID: return 0x11;
14403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_YDIR:          return 0x12;
14413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_TID:           return 0x21 + SDATA(ref).sv.index;
14423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_CTAID:         return 0x25 + SDATA(ref).sv.index;
14433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_NTID:          return 0x29 + SDATA(ref).sv.index;
14443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_GRIDID:        return 0x2c;
14453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_NCTAID:        return 0x2d + SDATA(ref).sv.index;
14463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_LBASE:         return 0x34;
14473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_SBASE:         return 0x30;
14483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case SV_CLOCK:         return 0x50 + SDATA(ref).sv.index;
14493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
14503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(!"no sreg for system value");
14513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return 0;
14523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
14533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
14543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
14563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitMOV(const Instruction *i)
14573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
14583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(0).getFile() == FILE_SYSTEM_VALUE) {
14593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x00000002 | (getSRegEncoding(i->src(0)) << 23);
14603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] = 0x86400000;
14613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPredicate(i);
14623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      defId(i->def(0), 2);
14633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
14643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(0).getFile() == FILE_IMMEDIATE) {
14653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] = 0x00000002 | (i->lanes << 14);
14663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] = 0x74000000;
14673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPredicate(i);
14683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      defId(i->def(0), 2);
14693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      setImmediate32(i, 0, Modifier(0));
14703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
14713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (i->src(0).getFile() == FILE_PREDICATE) {
14723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      // TODO
14733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else {
14743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitForm_C(i, 0x24c, 2);
14753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[1] |= i->lanes << 10;
14763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
14773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
14783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillerbool
14803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::emitInstruction(Instruction *insn)
14813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
14823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const unsigned int size = (writeIssueDelays && !(codeSize & 0x3f)) ? 16 : 8;
14833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (insn->encSize != 8) {
14853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ERROR("skipping unencodable instruction: ");
14863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      insn->print();
14873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
14883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   } else
14893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (codeSize + size > codeSizeLimit) {
14903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ERROR("code emitter output buffer too small\n");
14913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
14923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
14933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
14943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (writeIssueDelays) {
14953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      int id = (codeSize & 0x3f) / 8 - 1;
14963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (id < 0) {
14973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         id += 1;
14983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[0] = 0x00000000; // cf issue delay "instruction"
14993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code[1] = 0x08000000;
15003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         code += 2;
15013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         codeSize += 8;
15023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
15033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      uint32_t *data = code - (id * 2 + 2);
15043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
15053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      switch (id) {
15063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case 0: data[0] |= insn->sched << 2; break;
15073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case 1: data[0] |= insn->sched << 10; break;
15083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case 2: data[0] |= insn->sched << 18; break;
15093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case 3: data[0] |= insn->sched << 26; data[1] |= insn->sched >> 6; break;
15101b68009466dd2ac6a8d8827ef47ba9bdf0c58501Ilia Mirkin      case 4: data[1] |= insn->sched << 2; break;
15113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case 5: data[1] |= insn->sched << 10; break;
15123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      case 6: data[1] |= insn->sched << 18; break;
15133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      default:
15143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         assert(0);
15153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         break;
15163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      }
15173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
15183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
15193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // assert that instructions with multiple defs don't corrupt registers
15203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   for (int d = 0; insn->defExists(d); ++d)
15213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      assert(insn->asTex() || insn->def(d).rep()->reg.data.id >= 0);
15223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
15233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   switch (insn->op) {
15243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_MOV:
15253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_RDSV:
15263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitMOV(insn);
15273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_NOP:
15293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_LOAD:
15313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLOAD(insn);
15323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_STORE:
15343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSTORE(insn);
15353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_LINTERP:
15373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PINTERP:
15383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitINTERP(insn);
15393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_VFETCH:
15413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitVFETCH(insn);
15423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_EXPORT:
15443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitEXPORT(insn);
15453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PFETCH:
15473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPFETCH(insn);
15483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_EMIT:
15503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_RESTART:
15513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitOUT(insn);
15523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_ADD:
15543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SUB:
15553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (isFloatType(insn->dType))
15563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitFADD(insn);
15573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      else
15583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitUADD(insn);
15593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_MUL:
15613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (isFloatType(insn->dType))
15623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitFMUL(insn);
15633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      else
15643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitIMUL(insn);
15653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_MAD:
15673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_FMA:
15683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      if (isFloatType(insn->dType))
15693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitFMAD(insn);
15703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      else
15713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller         emitIMAD(insn);
15723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SAD:
15743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitISAD(insn);
15753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_NOT:
15773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitNOT(insn);
15783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_AND:
15803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLogicOp(insn, 0);
15813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_OR:
15833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLogicOp(insn, 1);
15843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_XOR:
15863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitLogicOp(insn, 2);
15873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SHL:
15893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SHR:
15903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitShift(insn);
15913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SET:
15933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SET_AND:
15943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SET_OR:
15953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SET_XOR:
15963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSET(insn->asCmp());
15973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
15983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SELP:
15993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSELP(insn);
16003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SLCT:
16023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSLCT(insn->asCmp());
16033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_MIN:
16053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_MAX:
16063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitMINMAX(insn);
16073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_ABS:
16093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_NEG:
16103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CEIL:
16113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_FLOOR:
16123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TRUNC:
16133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CVT:
16143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SAT:
16153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitCVT(insn);
16163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_RSQ:
16183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSFnOp(insn, 5);
16193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_RCP:
16213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSFnOp(insn, 4);
16223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_LG2:
16243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSFnOp(insn, 3);
16253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_EX2:
16273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSFnOp(insn, 2);
16283433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SIN:
16303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSFnOp(insn, 1);
16313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_COS:
16333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitSFnOp(insn, 0);
16343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PRESIN:
16363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PREEX2:
16373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPreOp(insn);
16383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TEX:
16403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXB:
16413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXL:
16423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXD:
16433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXF:
16443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitTEX(insn->asTex());
16453433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16463433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TXQ:
16473433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitTXQ(insn->asTex());
16483433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16493433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_TEXBAR:
16503433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitTEXBAR(insn);
16513433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16523433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_BRA:
16533433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CALL:
16543433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PRERET:
16553433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_RET:
16563433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_DISCARD:
16573433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_EXIT:
16583433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PRECONT:
16593433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CONT:
16603433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PREBREAK:
16613433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_BREAK:
16623433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_JOINAT:
16633433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_BRKPT:
16643433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_QUADON:
16653433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_QUADPOP:
16663433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitFlow(insn);
16673433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16683433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_QUADOP:
16693433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitQUADOP(insn, insn->subOp, insn->lanes);
16703433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16713433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_DFDX:
16723433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitQUADOP(insn, insn->src(0).mod.neg() ? 0x66 : 0x99, 0x4);
16733433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16743433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_DFDY:
16753433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitQUADOP(insn, insn->src(0).mod.neg() ? 0x5a : 0xa5, 0x5);
16763433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16773433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_POPCNT:
16783433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitPOPC(insn);
16793433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16803433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_JOIN:
16813433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      emitNOP(insn);
16823433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      insn->join = 1;
16833433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      break;
16843433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_PHI:
16853433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_UNION:
16863433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_CONSTRAINT:
16873433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ERROR("operation should have been eliminated");
16883433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
16893433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_EXP:
16903433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_LOG:
16913433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_SQRT:
16923433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   case OP_POW:
16933433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ERROR("operation should have been lowered\n");
16943433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
16953433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   default:
16963433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      ERROR("unknow op\n");
16973433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      return false;
16983433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   }
16993433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17003433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (insn->join)
17013433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      code[0] |= 1 << 22;
17023433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17033433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code += 2;
17043433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   codeSize += 8;
17053433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   return true;
17063433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
17073433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17083433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumilleruint32_t
17093433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::getMinEncodingSize(const Instruction *i) const
17103433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
17113433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   // No more short instruction encodings.
17123433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   return 8;
17133433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
17143433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17153433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumillervoid
17163433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::prepareEmission(Function *func)
17173433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
17183433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   const Target *targ = func->getProgram()->getTarget();
17193433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17203433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   CodeEmitter::prepareEmission(func);
17213433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17223433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   if (targ->hasSWSched)
17233433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller      calculateSchedDataNVC0(targ, func);
17243433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
17253433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17263433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitterGK110::CodeEmitterGK110(const TargetNVC0 *target)
17273433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   : CodeEmitter(target),
17283741b7d844f7357fac984e8c565dedb248947487Christoph Bumiller     targNVC0(target),
17293433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller     writeIssueDelays(target->hasSWSched)
17303433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
17313433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   code = NULL;
17323433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   codeSize = codeSizeLimit = 0;
17333433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   relocInfo = NULL;
17343433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
17353433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17363433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerCodeEmitter *
17373433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph BumillerTargetNVC0::createCodeEmitterGK110(Program::Type type)
17383433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller{
17393433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   CodeEmitterGK110 *emit = new CodeEmitterGK110(this);
17403433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   emit->setProgramType(type);
17413433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller   return emit;
17423433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller}
17433433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller
17443433471e8b46dd9dd042a00f88ef9ad011a94aacChristoph Bumiller} // namespace nv50_ir
1745