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 software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef ARBINST_HPP
00025 #define ARBINST_HPP
00026 
00027 #include "ShVariable.hpp"
00028 
00029 namespace shgl {
00030 
00033 enum ArbOp {
00034   // VERTEX AND FRAGMENT
00035   
00036   // Vector
00037   SH_ARB_ABS,
00038   SH_ARB_FLR,
00039   SH_ARB_FRC,
00040   SH_ARB_LIT,
00041   SH_ARB_MOV,
00042 
00043   // Scalar
00044   SH_ARB_EX2,
00045   SH_ARB_LG2,
00046   SH_ARB_RCP,
00047   SH_ARB_RSQ,
00048 
00049   // Binary scalar
00050   SH_ARB_POW,
00051 
00052   // Binary vector
00053   SH_ARB_ADD,
00054   SH_ARB_DP3,
00055   SH_ARB_DP4,
00056   SH_ARB_DPH,
00057   SH_ARB_DST,
00058   SH_ARB_MAX,
00059   SH_ARB_MIN,
00060   SH_ARB_MUL,
00061   SH_ARB_SGE,
00062   SH_ARB_SLT,
00063   SH_ARB_SUB,
00064   SH_ARB_XPD,
00065 
00066   // Trinary
00067   SH_ARB_MAD,
00068 
00069   // Swizzling
00070   SH_ARB_SWZ,
00071 
00072   // VERTEX ONLY
00073   // Scalar
00074   SH_ARB_EXP,
00075   SH_ARB_LOG,
00076   
00077   // Weird,
00078   SH_ARB_ARL,
00079   SH_ARB_ARRAYMOV, // Kind of hacky but works.
00080   
00081   // FRAGMENT ONLY
00082   // Scalar
00083   SH_ARB_COS,
00084   SH_ARB_SIN,
00085   SH_ARB_SCS,
00086 
00087   // Trinary
00088   SH_ARB_CMP,
00089   SH_ARB_LRP,
00090 
00091   // Sampling
00092   SH_ARB_TEX,
00093   SH_ARB_TXP,
00094   SH_ARB_TXB,
00095 
00096   // KIL
00097   SH_ARB_KIL,
00098 
00099   // NV_vertex_program2/NV_fragment_program
00100   SH_ARB_SEQ,
00101   SH_ARB_SGT,
00102   SH_ARB_SLE,
00103   SH_ARB_SNE,
00104   SH_ARB_SFL,
00105   SH_ARB_STR,
00106 
00107   // NV_fragment_program
00108   SH_ARB_DDX,
00109   SH_ARB_DDY,
00110   SH_ARB_RFL,
00111   SH_ARB_TXD,
00112 
00113   // NV_vertex_program2
00114   SH_ARB_SSG,
00115   SH_ARB_BRA,
00116   SH_ARB_LABEL, // Special label "instruction"
00117   
00118   // NV_fragment_program2
00119   SH_ARB_DIV,
00120   SH_ARB_DP2,
00121   SH_ARB_NRM,
00122   SH_ARB_IF,
00123   SH_ARB_ELSE,
00124   SH_ARB_ENDIF,
00125   SH_ARB_REP,
00126   SH_ARB_ENDREP,
00127   SH_ARB_BRK,
00128   SH_ARB_RET,
00129   
00130   // Special "operations" for emit
00131   SH_ARB_FUN
00132 };
00133 
00136 struct ArbOpInfo {
00137   char* name;
00138   int arity;
00139   bool collectingOp;
00140 };
00141 
00142 extern ArbOpInfo arbOpInfo[];
00143 
00146 struct ArbInst {
00147   static const int max_num_sources = 4;
00148   
00149   explicit ArbInst(ArbOp op)
00150     : op(op), invert(false), update_cc(false), ccode(NOCC)
00151   {
00152   }
00153 
00154   ArbInst(ArbOp op, int label)
00155     : op(op), label(label), invert(false),
00156       update_cc(false), ccode(NOCC)
00157   {
00158   }
00159 
00160   ArbInst(ArbOp op, int label, const SH::ShVariable& condition)
00161     : op(op), label(label), invert(false),
00162       update_cc(false), ccode(NOCC)
00163   {
00164     src[0] = condition;
00165   }
00166   
00167   ArbInst(ArbOp op, const SH::ShVariable& dest)
00168     : op(op), dest(dest), invert(false),
00169       update_cc(false), ccode(NOCC)
00170   {
00171   }
00172 
00173   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0)
00174     : op(op), dest(dest), invert(false),
00175       update_cc(false), ccode(NOCC)
00176   {
00177     src[0] = src0;
00178   }
00179 
00180   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0,
00181           const SH::ShVariable& src1)
00182     : op(op), dest(dest), invert(false),
00183       update_cc(false), ccode(NOCC)
00184   {
00185     src[0] = src0;
00186     src[1] = src1;
00187   }
00188   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0,
00189           const SH::ShVariable& src1, const SH::ShVariable& src2)
00190     : op(op), dest(dest), invert(false),
00191       update_cc(false), ccode(NOCC)
00192   {
00193     src[0] = src0;
00194     src[1] = src1;
00195     src[2] = src2;
00196   }
00197   ArbInst(ArbOp op, const SH::ShVariable& dest, const SH::ShVariable& src0,
00198           const SH::ShVariable& src1, const SH::ShVariable& src2,
00199           const SH::ShVariable& src3)
00200     : op(op), dest(dest), invert(false),
00201       update_cc(false), ccode(NOCC)
00202   {
00203     src[0] = src0;
00204     src[1] = src1;
00205     src[2] = src2;
00206     src[3] = src3;
00207   }
00208   
00209   ArbOp op;
00210   SH::ShVariable dest;
00211 
00212   SH::ShVariable src[max_num_sources];
00213 
00214   int label; // For branching instructions and labels
00215   bool invert; // Invert the sense of a break condition.
00216 
00217   // NV specific stuff for condition codes
00218   bool update_cc; 
00219   
00220   enum CCode {
00221     NOCC,
00222     EQ,
00223     GE,
00224     GT,
00225     LE,
00226     LT,
00227     NE,
00228     TR,
00229     FL
00230   } ccode; 
00231 
00232   SH::ShSwizzle ccswiz;
00233   
00234 };
00235 
00236 extern char* arbCCnames[];
00237 
00238 }
00239 
00240 #endif

Generated on Wed Jun 15 18:12:37 2005 for Sh by  doxygen 1.4.3-20050530