Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ArbInst.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef ARBINST_HPP
00021 #define ARBINST_HPP
00022 
00023 #include "ShVariable.hpp"
00024 
00025 namespace shgl {
00026 
00029 enum ArbOp {
00030   // VERTEX AND FRAGMENT
00031   
00032   // Vector
00033   SH_ARB_ABS,
00034   SH_ARB_FLR,
00035   SH_ARB_FRC,
00036   SH_ARB_LIT,
00037   SH_ARB_MOV,
00038 
00039   // Scalar
00040   SH_ARB_EX2,
00041   SH_ARB_LG2,
00042   SH_ARB_RCP,
00043   SH_ARB_RSQ,
00044 
00045   // Binary scalar
00046   SH_ARB_POW,
00047 
00048   // Binary vector
00049   SH_ARB_ADD,
00050   SH_ARB_DP3,
00051   SH_ARB_DP4,
00052   SH_ARB_DPH,
00053   SH_ARB_DST,
00054   SH_ARB_MAX,
00055   SH_ARB_MIN,
00056   SH_ARB_MUL,
00057   SH_ARB_SGE,
00058   SH_ARB_SLT,
00059   SH_ARB_SUB,
00060   SH_ARB_XPD,
00061 
00062   // Trinary
00063   SH_ARB_MAD,
00064 
00065   // Swizzling
00066   SH_ARB_SWZ,
00067 
00068   // VERTEX ONLY
00069   // Scalar
00070   SH_ARB_EXP,
00071   SH_ARB_LOG,
00072   
00073   // Weird,
00074   SH_ARB_ARL,
00075   SH_ARB_ARRAYMOV, // Kind of hacky but works.
00076   
00077   // FRAGMENT ONLY
00078   // Scalar
00079   SH_ARB_COS,
00080   SH_ARB_SIN,
00081   SH_ARB_SCS,
00082 
00083   // Trinary
00084   SH_ARB_CMP,
00085   SH_ARB_LRP,
00086 
00087   // Sampling
00088   SH_ARB_TEX,
00089   SH_ARB_TXP,
00090   SH_ARB_TXB,
00091 
00092   // KIL
00093   SH_ARB_KIL,
00094 
00095   // NV_vertex_program2/NV_fragment_program
00096   SH_ARB_SEQ,
00097   SH_ARB_SGT,
00098   SH_ARB_SLE,
00099   SH_ARB_SNE,
00100   SH_ARB_SFL,
00101   SH_ARB_STR,
00102 
00103   // NV_fragment_program
00104   SH_ARB_DDX,
00105   SH_ARB_DDY,
00106   SH_ARB_RFL,
00107   SH_ARB_TXD,
00108 
00109   // NV_vertex_program2
00110   SH_ARB_SSG,
00111   SH_ARB_BRA,
00112   SH_ARB_LABEL, // Special label "instruction"
00113   
00114   // NV_fragment_program2
00115   SH_ARB_DIV,
00116   SH_ARB_DP2,
00117   SH_ARB_NRM,
00118   SH_ARB_IF,
00119   SH_ARB_ELSE,
00120   SH_ARB_ENDIF,
00121   SH_ARB_REP,
00122   SH_ARB_ENDREP,
00123   SH_ARB_BRK,
00124   SH_ARB_RET,
00125   
00126   // Special "operations" for emit
00127   SH_ARB_FUN,
00128 
00129   // Just comments
00130   SH_ARB_COMMENT,
00131 };
00132 
00135 struct ArbOpInfo {
00136   char* name;
00137   int arity;
00138   bool collectingOp;
00139 };
00140 
00141 extern ArbOpInfo arbOpInfo[];
00142 
00145 struct ArbInst {
00146   static const int max_num_sources = 4;
00147   
00148   explicit ArbInst(ArbOp op)
00149     : op(op), invert(false), update_cc(false), ccode(NOCC)
00150   {
00151   }
00152 
00153   ArbInst(ArbOp op, int label)
00154     : op(op), label(label), invert(false),
00155       update_cc(false), ccode(NOCC)
00156   {
00157   }
00158 
00159   ArbInst(ArbOp op, const std::string& comment)
00160     : op(op), invert(false), update_cc(false), ccode(NOCC),
00161     comment(comment)
00162   {
00163   }
00164 
00165   ArbInst(ArbOp op, int label, const SH::ShVariable& condition)
00166     : op(op), label(label), invert(false),
00167       update_cc(false), ccode(NOCC)
00168   {
00169     src[0] = condition;
00170   }
00171   
00172   ArbInst(ArbOp op, const SH::ShVariable& dest)
00173     : op(op), dest(dest), invert(false),
00174       update_cc(false), ccode(NOCC)
00175   {
00176   }
00177 
00178   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0)
00179     : op(op), dest(dest), invert(false),
00180       update_cc(false), ccode(NOCC)
00181   {
00182     src[0] = src0;
00183   }
00184 
00185   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0,
00186           const SH::ShVariable& src1)
00187     : op(op), dest(dest), invert(false),
00188       update_cc(false), ccode(NOCC)
00189   {
00190     src[0] = src0;
00191     src[1] = src1;
00192   }
00193   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0,
00194           const SH::ShVariable& src1, const SH::ShVariable& src2)
00195     : op(op), dest(dest), invert(false),
00196       update_cc(false), ccode(NOCC)
00197   {
00198     src[0] = src0;
00199     src[1] = src1;
00200     src[2] = src2;
00201   }
00202   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0,
00203           const SH::ShVariable& src1, const SH::ShVariable& src2,
00204           const SH::ShVariable& src3)
00205     : op(op), dest(dest), invert(false),
00206       update_cc(false), ccode(NOCC)
00207   {
00208     src[0] = src0;
00209     src[1] = src1;
00210     src[2] = src2;
00211     src[3] = src3;
00212   }
00213   
00214   ArbOp op;
00215   SH::ShVariable dest;
00216 
00217   SH::ShVariable src[max_num_sources];
00218 
00219   int label; // For branching instructions and labels
00220   bool invert; // Invert the sense of a break condition.
00221 
00222   // NV specific stuff for condition codes
00223   bool update_cc; 
00224   
00225   enum CCode {
00226     NOCC,
00227     EQ,
00228     GE,
00229     GT,
00230     LE,
00231     LT,
00232     NE,
00233     TR,
00234     FL
00235   } ccode; 
00236 
00237   SH::ShSwizzle ccswiz;
00238   
00239   // Only used for COMMENTs
00240   std::string comment;
00241 };
00242 
00243 extern char* arbCCnames[];
00244 
00245 }
00246 
00247 #endif

Generated on Thu Jul 28 17:33:00 2005 for Sh by  doxygen 1.4.3-20050530