1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2009 Nicolai Haehnle. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 7bf215546Sopenharmony_ci * a copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 16bf215546Sopenharmony_ci * portions of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 22bf215546Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23bf215546Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24bf215546Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef RADEON_OPCODES_H 29bf215546Sopenharmony_ci#define RADEON_OPCODES_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include <assert.h> 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci/** 34bf215546Sopenharmony_ci * Opcodes understood by the Radeon compiler. 35bf215546Sopenharmony_ci */ 36bf215546Sopenharmony_citypedef enum { 37bf215546Sopenharmony_ci RC_OPCODE_NOP = 0, 38bf215546Sopenharmony_ci RC_OPCODE_ILLEGAL_OPCODE, 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c + src1.c; */ 41bf215546Sopenharmony_ci RC_OPCODE_ADD, 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci /** special instruction: load address register 44bf215546Sopenharmony_ci * dst.x = floor(src.x), where dst must be an address register */ 45bf215546Sopenharmony_ci RC_OPCODE_ARL, 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci /** special instruction: load address register with round 48bf215546Sopenharmony_ci * dst.x = round(src.x), where dst must be an address register */ 49bf215546Sopenharmony_ci RC_OPCODE_ARR, 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci /** vec4 instruction: dst.c = ceil(src0.c) */ 52bf215546Sopenharmony_ci RC_OPCODE_CEIL, 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c < 0.0 ? src1.c : src2.c */ 55bf215546Sopenharmony_ci RC_OPCODE_CMP, 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src2.c > 0.5 ? src0.c : src1.c */ 58bf215546Sopenharmony_ci RC_OPCODE_CND, 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci /** scalar instruction: dst = cos(src0.x) */ 61bf215546Sopenharmony_ci RC_OPCODE_COS, 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /** special instruction: take vec4 partial derivative in X direction 64bf215546Sopenharmony_ci * dst.c = d src0.c / dx */ 65bf215546Sopenharmony_ci RC_OPCODE_DDX, 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci /** special instruction: take vec4 partial derivative in Y direction 68bf215546Sopenharmony_ci * dst.c = d src0.c / dy */ 69bf215546Sopenharmony_ci RC_OPCODE_DDY, 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci /** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y */ 72bf215546Sopenharmony_ci RC_OPCODE_DP2, 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci /** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y + src0.z*src1.z */ 75bf215546Sopenharmony_ci RC_OPCODE_DP3, 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci /** scalar instruction: dst = src0.x*src1.x + src0.y*src1.y + src0.z*src1.z + src0.w*src1.w */ 78bf215546Sopenharmony_ci RC_OPCODE_DP4, 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci /** special instruction, see ARB_fragment_program */ 81bf215546Sopenharmony_ci RC_OPCODE_DST, 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci /** scalar instruction: dst = 2**src0.x */ 84bf215546Sopenharmony_ci RC_OPCODE_EX2, 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci /** special instruction, see ARB_vertex_program */ 87bf215546Sopenharmony_ci RC_OPCODE_EXP, 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci /** vec4 instruction: dst.c = floor(src0.c) */ 90bf215546Sopenharmony_ci RC_OPCODE_FLR, 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c - floor(src0.c) */ 93bf215546Sopenharmony_ci RC_OPCODE_FRC, 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci /** special instruction: stop execution if any component of src0 is negative */ 96bf215546Sopenharmony_ci RC_OPCODE_KIL, 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci /** scalar instruction: dst = log_2(src0.x) */ 99bf215546Sopenharmony_ci RC_OPCODE_LG2, 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci /** special instruction, see ARB_vertex_program */ 102bf215546Sopenharmony_ci RC_OPCODE_LIT, 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci /** special instruction, see ARB_vertex_program */ 105bf215546Sopenharmony_ci RC_OPCODE_LOG, 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c*src1.c + (1 - src0.c)*src2.c */ 108bf215546Sopenharmony_ci RC_OPCODE_LRP, 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c*src1.c + src2.c */ 111bf215546Sopenharmony_ci RC_OPCODE_MAD, 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ci /** vec4 instruction: dst.c = max(src0.c, src1.c) */ 114bf215546Sopenharmony_ci RC_OPCODE_MAX, 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci /** vec4 instruction: dst.c = min(src0.c, src1.c) */ 117bf215546Sopenharmony_ci RC_OPCODE_MIN, 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c */ 120bf215546Sopenharmony_ci RC_OPCODE_MOV, 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c*src1.c */ 123bf215546Sopenharmony_ci RC_OPCODE_MUL, 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci /** scalar instruction: dst = src0.x ** src1.x */ 126bf215546Sopenharmony_ci RC_OPCODE_POW, 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci /** scalar instruction: dst = 1 / src0.x */ 129bf215546Sopenharmony_ci RC_OPCODE_RCP, 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci /** vec4 instruction: dst.c = floor(src0.c + 0.5) */ 132bf215546Sopenharmony_ci RC_OPCODE_ROUND, 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci /** scalar instruction: dst = 1 / sqrt(src0.x) */ 135bf215546Sopenharmony_ci RC_OPCODE_RSQ, 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c == src1.c) ? 1.0 : 0.0 */ 138bf215546Sopenharmony_ci RC_OPCODE_SEQ, 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c >= src1.c) ? 1.0 : 0.0 */ 141bf215546Sopenharmony_ci RC_OPCODE_SGE, 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c > src1.c) ? 1.0 : 0.0 */ 144bf215546Sopenharmony_ci RC_OPCODE_SGT, 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci /** scalar instruction: dst = sin(src0.x) */ 147bf215546Sopenharmony_ci RC_OPCODE_SIN, 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c <= src1.c) ? 1.0 : 0.0 */ 150bf215546Sopenharmony_ci RC_OPCODE_SLE, 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c < src1.c) ? 1.0 : 0.0 */ 153bf215546Sopenharmony_ci RC_OPCODE_SLT, 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c != src1.c) ? 1.0 : 0.0 */ 156bf215546Sopenharmony_ci RC_OPCODE_SNE, 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (src0.c < 0 ?) -1 : ((src0.c > 0) : 1 : 0) */ 159bf215546Sopenharmony_ci RC_OPCODE_SSG, 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci /** vec4 instruction: dst.c = src0.c - src1.c */ 162bf215546Sopenharmony_ci RC_OPCODE_SUB, 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci /** vec4 instruction: dst.c = (abs(src0.c) - fract(abs(src0.c))) * sgn(src0.c) */ 165bf215546Sopenharmony_ci RC_OPCODE_TRUNC, 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci RC_OPCODE_TEX, 168bf215546Sopenharmony_ci RC_OPCODE_TXB, 169bf215546Sopenharmony_ci RC_OPCODE_TXD, 170bf215546Sopenharmony_ci RC_OPCODE_TXL, 171bf215546Sopenharmony_ci RC_OPCODE_TXP, 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci /** branch instruction: 174bf215546Sopenharmony_ci * If src0.x != 0.0, continue with the next instruction; 175bf215546Sopenharmony_ci * otherwise, jump to matching RC_OPCODE_ELSE or RC_OPCODE_ENDIF. 176bf215546Sopenharmony_ci */ 177bf215546Sopenharmony_ci RC_OPCODE_IF, 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ci /** branch instruction: jump to matching RC_OPCODE_ENDIF */ 180bf215546Sopenharmony_ci RC_OPCODE_ELSE, 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci /** branch instruction: has no effect */ 183bf215546Sopenharmony_ci RC_OPCODE_ENDIF, 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_ci RC_OPCODE_BGNLOOP, 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci RC_OPCODE_BRK, 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci RC_OPCODE_ENDLOOP, 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci RC_OPCODE_CONT, 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci /** special instruction, used in R300-R500 fragment program pair instructions 194bf215546Sopenharmony_ci * indicates that the result of the alpha operation shall be replicated 195bf215546Sopenharmony_ci * across all other channels */ 196bf215546Sopenharmony_ci RC_OPCODE_REPL_ALPHA, 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci /** special instruction, used in R300-R500 fragment programs 199bf215546Sopenharmony_ci * to indicate the start of a block of texture instructions that 200bf215546Sopenharmony_ci * can run simultaneously. */ 201bf215546Sopenharmony_ci RC_OPCODE_BEGIN_TEX, 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci /** Stop execution of the shader (GLSL discard) */ 204bf215546Sopenharmony_ci RC_OPCODE_KILP, 205bf215546Sopenharmony_ci 206bf215546Sopenharmony_ci /* Vertex shader CF Instructions */ 207bf215546Sopenharmony_ci RC_ME_PRED_SEQ, 208bf215546Sopenharmony_ci RC_ME_PRED_SGT, 209bf215546Sopenharmony_ci RC_ME_PRED_SGE, 210bf215546Sopenharmony_ci RC_ME_PRED_SNEQ, 211bf215546Sopenharmony_ci RC_ME_PRED_SET_CLR, 212bf215546Sopenharmony_ci RC_ME_PRED_SET_INV, 213bf215546Sopenharmony_ci RC_ME_PRED_SET_POP, 214bf215546Sopenharmony_ci RC_ME_PRED_SET_RESTORE, 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci RC_VE_PRED_SEQ_PUSH, 217bf215546Sopenharmony_ci RC_VE_PRED_SGT_PUSH, 218bf215546Sopenharmony_ci RC_VE_PRED_SGE_PUSH, 219bf215546Sopenharmony_ci RC_VE_PRED_SNEQ_PUSH, 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_ci MAX_RC_OPCODE 222bf215546Sopenharmony_ci} rc_opcode; 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_cistruct rc_opcode_info { 226bf215546Sopenharmony_ci rc_opcode Opcode; 227bf215546Sopenharmony_ci const char * Name; 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci /** true if the instruction reads from a texture. 230bf215546Sopenharmony_ci * 231bf215546Sopenharmony_ci * \note This is false for the KIL instruction, even though KIL is 232bf215546Sopenharmony_ci * a texture instruction from a hardware point of view. */ 233bf215546Sopenharmony_ci unsigned int HasTexture:1; 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci unsigned int NumSrcRegs:2; 236bf215546Sopenharmony_ci unsigned int HasDstReg:1; 237bf215546Sopenharmony_ci 238bf215546Sopenharmony_ci /** true if this instruction affects control flow */ 239bf215546Sopenharmony_ci unsigned int IsFlowControl:1; 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci /** true if this is a vector instruction that operates on components in parallel 242bf215546Sopenharmony_ci * without any cross-component interaction */ 243bf215546Sopenharmony_ci unsigned int IsComponentwise:1; 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci /** true if this instruction sources only its operands X components 246bf215546Sopenharmony_ci * to compute one result which is smeared across all output channels */ 247bf215546Sopenharmony_ci unsigned int IsStandardScalar:1; 248bf215546Sopenharmony_ci}; 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ciextern const struct rc_opcode_info rc_opcodes[MAX_RC_OPCODE]; 251bf215546Sopenharmony_ci 252bf215546Sopenharmony_cistatic inline const struct rc_opcode_info * rc_get_opcode_info(rc_opcode opcode) 253bf215546Sopenharmony_ci{ 254bf215546Sopenharmony_ci assert((unsigned int)opcode < MAX_RC_OPCODE); 255bf215546Sopenharmony_ci assert(rc_opcodes[opcode].Opcode == opcode); 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci return &rc_opcodes[opcode]; 258bf215546Sopenharmony_ci} 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_cistruct rc_instruction; 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_civoid rc_compute_sources_for_writemask( 263bf215546Sopenharmony_ci const struct rc_instruction *inst, 264bf215546Sopenharmony_ci unsigned int writemask, 265bf215546Sopenharmony_ci unsigned int *srcmasks); 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci#endif /* RADEON_OPCODES_H */ 268