void rv_emit(SymbolTable *table, Node *ptr) { int stIndex; if (ptr->token.tokenNumber == NUMBER) { emit1("ldc", atoi(ptr->token.tokenValue)); } else { SymbolRow* foundRow; stIndex = lookup(table, ptr->token.tokenValue); if (stIndex != -1) { foundRow = &table->rows[stIndex]; } if (stIndex == -1) { stIndex = lookup(rootTable, ptr->token.tokenValue); if (stIndex != -1) { foundRow = &(rootTable->rows[stIndex]); } else { return; } } if (foundRow->qual == QUAL_CONST) { emit1("ldc", foundRow->init); } else if (foundRow->width > 1) { emit2("lda", foundRow->base, foundRow->offset); } else { emit2("lod", foundRow->base, foundRow->offset); } } }
static void r300_transform_SIN_COS_SCS(struct radeon_compiler *c, struct rc_instruction *inst, unsigned srctmp) { if (inst->U.I.Opcode == RC_OPCODE_COS) { emit1(c, inst->Prev, RC_OPCODE_COS, inst->U.I.SaturateMode, inst->U.I.DstReg, srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW)); } else if (inst->U.I.Opcode == RC_OPCODE_SIN) { emit1(c, inst->Prev, RC_OPCODE_SIN, inst->U.I.SaturateMode, inst->U.I.DstReg, srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW)); } else if (inst->U.I.Opcode == RC_OPCODE_SCS) { struct rc_dst_register moddst = inst->U.I.DstReg; if (inst->U.I.DstReg.WriteMask & RC_MASK_X) { moddst.WriteMask = RC_MASK_X; emit1(c, inst->Prev, RC_OPCODE_COS, inst->U.I.SaturateMode, moddst, srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW)); } if (inst->U.I.DstReg.WriteMask & RC_MASK_Y) { moddst.WriteMask = RC_MASK_Y; emit1(c, inst->Prev, RC_OPCODE_SIN, inst->U.I.SaturateMode, moddst, srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW)); } } rc_remove_instruction(inst); }
static void transform_POW(struct radeon_compiler* c, struct rc_instruction* inst) { struct rc_dst_register tempdst = try_to_reuse_dst(c, inst); struct rc_src_register tempsrc = srcreg(RC_FILE_TEMPORARY, tempdst.Index); tempdst.WriteMask = RC_MASK_W; tempsrc.Swizzle = RC_SWIZZLE_WWWW; emit1(c, inst->Prev, RC_OPCODE_LG2, 0, tempdst, swizzle_xxxx(inst->U.I.SrcReg[0])); emit2(c, inst->Prev, RC_OPCODE_MUL, 0, tempdst, tempsrc, swizzle_xxxx(inst->U.I.SrcReg[1])); emit1(c, inst->Prev, RC_OPCODE_EX2, inst->U.I.SaturateMode, inst->U.I.DstReg, tempsrc); rc_remove_instruction(inst); }
/** * Transform the trigonometric functions COS, SIN, and SCS * so that the input to COS and SIN is always in the range [-PI, PI]. * SCS is replaced by one COS and one SIN instruction. */ int r300_transform_trig_scale_vertex(struct radeon_compiler *c, struct rc_instruction *inst, void *unused) { static const float cons[4] = {0.15915494309189535, 0.5, 6.28318530717959, -3.14159265358979}; unsigned int temp; unsigned int constant; if (inst->U.I.Opcode != RC_OPCODE_COS && inst->U.I.Opcode != RC_OPCODE_SIN && inst->U.I.Opcode != RC_OPCODE_SCS) return 0; /* Repeat x in the range [-PI, PI]: * * repeat(x) = frac(x / 2PI + 0.5) * 2PI - PI */ temp = rc_find_free_temporary(c); constant = rc_constants_add_immediate_vec4(&c->Program.Constants, cons); emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(temp, RC_MASK_W), swizzle_xxxx(inst->U.I.SrcReg[0]), srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_XXXX), srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_YYYY)); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(temp, RC_MASK_W), srcreg(RC_FILE_TEMPORARY, temp)); emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(temp, RC_MASK_W), srcreg(RC_FILE_TEMPORARY, temp), srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_ZZZZ), srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_WWWW)); r300_transform_SIN_COS_SCS(c, inst, temp); return 1; }
/* dst = ROUND(src) : * add = src + .5 * frac = FRC(add) * dst = add - frac * * According to the GLSL spec, the implementor can decide which way to round * when the fraction is .5. We round down for .5. * */ static void transform_ROUND(struct radeon_compiler* c, struct rc_instruction* inst) { unsigned int mask = inst->U.I.DstReg.WriteMask; unsigned int frac_index, add_index; struct rc_dst_register frac_dst, add_dst; struct rc_src_register frac_src, add_src; /* add = src + .5 */ add_index = rc_find_free_temporary(c); add_dst = dstregtmpmask(add_index, mask); emit2(c, inst->Prev, RC_OPCODE_ADD, 0, add_dst, inst->U.I.SrcReg[0], builtin_half); add_src = srcreg(RC_FILE_TEMPORARY, add_dst.Index); /* frac = FRC(add) */ frac_index = rc_find_free_temporary(c); frac_dst = dstregtmpmask(frac_index, mask); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, frac_dst, add_src); frac_src = srcreg(RC_FILE_TEMPORARY, frac_dst.Index); /* dst = add - frac */ emit2(c, inst->Prev, RC_OPCODE_ADD, 0, inst->U.I.DstReg, add_src, negate(frac_src)); rc_remove_instruction(inst); }
/** * Transform the trigonometric functions COS, SIN, and SCS * to include pre-scaling by 1/(2*PI) and taking the fractional * part, so that the input to COS and SIN is always in the range [0,1). * SCS is replaced by one COS and one SIN instruction. * * @warning This transformation implicitly changes the semantics of SIN and COS! */ int radeonTransformTrigScale(struct radeon_compiler* c, struct rc_instruction* inst, void* unused) { static const float RCP_2PI = 0.15915494309189535; unsigned int temp; unsigned int constant; unsigned int constant_swizzle; if (inst->U.I.Opcode != RC_OPCODE_COS && inst->U.I.Opcode != RC_OPCODE_SIN && inst->U.I.Opcode != RC_OPCODE_SCS) return 0; temp = rc_find_free_temporary(c); constant = rc_constants_add_immediate_scalar(&c->Program.Constants, RCP_2PI, &constant_swizzle); emit2(c, inst->Prev, RC_OPCODE_MUL, 0, dstregtmpmask(temp, RC_MASK_W), swizzle_xxxx(inst->U.I.SrcReg[0]), srcregswz(RC_FILE_CONSTANT, constant, constant_swizzle)); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(temp, RC_MASK_W), srcreg(RC_FILE_TEMPORARY, temp)); r300_transform_SIN_COS_SCS(c, inst, temp); return 1; }
void VirtualMachine::emit4(int v) { emit1(v & 255); emit1((v >> 8) & 255); emit1((v >> 16) & 255); emit1((v >> 24) & 255); }
static void transform_FLR(struct radeon_compiler* c, struct rc_instruction* inst) { struct rc_dst_register dst = try_to_reuse_dst(c, inst); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dst, inst->U.I.SrcReg[0]); emit2(c, inst->Prev, RC_OPCODE_ADD, inst->U.I.SaturateMode, inst->U.I.DstReg, inst->U.I.SrcReg[0], negate(srcreg(RC_FILE_TEMPORARY, dst.Index))); rc_remove_instruction(inst); }
static void transform_ABS(struct radeon_compiler* c, struct rc_instruction* inst) { struct rc_src_register src = inst->U.I.SrcReg[0]; src.Abs = 1; src.Negate = RC_MASK_NONE; emit1(c, inst->Prev, RC_OPCODE_MOV, inst->U.I.SaturateMode, inst->U.I.DstReg, src); rc_remove_instruction(inst); }
static void transform_TRUNC(struct radeon_compiler* c, struct rc_instruction* inst) { /* Definition of trunc: * trunc(x) = (abs(x) - fract(abs(x))) * sgn(x) * * The multiplication by sgn(x) can be simplified using CMP: * y * sgn(x) = (x < 0 ? -y : y) */ struct rc_dst_register dst = try_to_reuse_dst(c, inst); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dst, absolute(inst->U.I.SrcReg[0])); emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, absolute(inst->U.I.SrcReg[0]), negate(srcreg(RC_FILE_TEMPORARY, dst.Index))); emit3(c, inst->Prev, RC_OPCODE_CMP, &inst->U.I, inst->U.I.DstReg, inst->U.I.SrcReg[0], negate(srcreg(RC_FILE_TEMPORARY, dst.Index)), srcreg(RC_FILE_TEMPORARY, dst.Index)); rc_remove_instruction(inst); }
static void transform_CEIL(struct radeon_compiler* c, struct rc_instruction* inst) { /* Assuming: * ceil(x) = -floor(-x) * * After inlining floor: * ceil(x) = -(-x-frac(-x)) * * After simplification: * ceil(x) = x+frac(-x) */ struct rc_dst_register dst = try_to_reuse_dst(c, inst); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dst, negate(inst->U.I.SrcReg[0])); emit2(c, inst->Prev, RC_OPCODE_ADD, inst->U.I.SaturateMode, inst->U.I.DstReg, inst->U.I.SrcReg[0], srcreg(RC_FILE_TEMPORARY, dst.Index)); rc_remove_instruction(inst); }
void VirtualMachine::emitInstruction(const char *string) { int c1, c2; int v; while (true) { c1 = string[0]; c2 = string[1]; v = (hex( c1 ) << 4) | hex(c2); emit1( v ); if (!string[2]) { break; } string += 3; } }
void codeGen(Node *root, FILE *ucoFile) { Node *p; // pointer for Node int globalSize; // the size of global variables file = ucoFile; // rootTable = initSymbolTable(); // step 1: process the declaration part for (p = root->son; p; p = p->next) { if (p->token.tokenNumber == DCL) { processDeclaration(rootTable, p->son); } else if (p->token.tokenNumber == FUNC_DEF) { processFuncHeader(rootTable, p->son); } else { icg_error(3); } } globalSize = rootTable->offset - 1; // step 2: process the function part for (p = root->son; p; p = p->next) { if (p->token.tokenNumber == FUNC_DEF) { processFunction(rootTable, p); } } display(rootTable, 0); // step 3: generate codes for starting routine // bgn globalSize // ldp // call main // end emit1("bgn", globalSize); emit0("ldp"); emitJump("call", "main"); emit0("end"); }
static void transform_r300_vertex_fix_LIT(struct radeon_compiler* c, struct rc_instruction* inst) { struct rc_dst_register dst = try_to_reuse_dst(c, inst); unsigned constant_swizzle; int constant = rc_constants_add_immediate_scalar(&c->Program.Constants, 0.0000000000000000001, &constant_swizzle); /* MOV dst, src */ dst.WriteMask = RC_MASK_XYZW; emit1(c, inst->Prev, RC_OPCODE_MOV, 0, dst, inst->U.I.SrcReg[0]); /* MAX dst.y, src, 0.00...001 */ emit2(c, inst->Prev, RC_OPCODE_MAX, 0, dstregtmpmask(dst.Index, RC_MASK_Y), srcreg(RC_FILE_TEMPORARY, dst.Index), srcregswz(RC_FILE_CONSTANT, constant, constant_swizzle)); inst->U.I.SrcReg[0] = srcreg(RC_FILE_TEMPORARY, dst.Index); }
void dch(u32 x) { emit1(x); }
void fillb(u32 size, u32 value) { int i; for(i=0; i<size; i+=2) emit1(value|(value<<8)); }
void emit5(u32 x, u32 y, u32 z, u32 a, u32 b) { emit1(x); emit1(y); emit1(z); emit1(a); emit1(b); }
void emit3(u32 x, u32 y, u32 z) { emit1(x); emit1(y); emit1(z); }
void emit2(u32 x, u32 y) { emit1(x); emit1(y); }
static int compile_operator(compiletime c) { int operand_count = 0; const char *op = pop_operator(c, &operand_count); if (!strcmp(op, "*")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, multiply_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "**")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, power_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "/")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, divide_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "%")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, modulo_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "=")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, assign_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, ";")) { } else if (!strcmp(op, "if")) { const char *val1 = pop_operand(c); emit2(c, if_tc, val1); DEBUG printf("emit '%s' %s\n", val1, op); c->level++; } else if (!strcmp(op, "else")) { c->level--; emit1(c, else_tc); c->level++; DEBUG printf("emit %s\n", op); } else if (!strcmp(op, "fi")) { c->level--; emit1(c, fi_tc); DEBUG printf("emit %s\n", op); } else if (!strcmp(op, "!")) { const char *val1 = pop_operand(c); emit2(c, not_tc, val1); DEBUG printf("emit '%s' %s\n", val1, op); } else if (!strcmp(op, "+")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, add_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "-")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, subtract_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, ">")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, gt_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, ">=")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, geq_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "<=")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, leq_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "<")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, lt_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "&&")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, and_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "||")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, or_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "^^")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, xor_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "&")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, bit_and_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "|")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, bit_or_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "^")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, bit_xor_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "~")) { const char *val1 = pop_operand(c); emit2(c, bit_negate_tc, val1); DEBUG printf("emit %s %s\n", val1, op); } else if (!strcmp(op, "<<")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, shift_left_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, ">>")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, shift_right_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, ">>>")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, logical_shift_right_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "==")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, eq_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "!=")) { const char *val2 = pop_operand(c); const char *val1 = pop_operand(c); emit3(c, neq_tc, val1, val2); DEBUG printf("emit %s %s %s\n", val1, op, val2); } else if (!strcmp(op, "fold-case")) { const char *val1 = pop_operand(c); emit2(c, func_fold_case_tc, val1); DEBUG printf("emit %s %s\n", op, val1); } else if (!strcmp(op, "size")) { const char *val1 = pop_operand(c); emit2(c, func_size_tc, val1); DEBUG printf("emit %s %s\n", op, val1); } else if (!strcmp(op, "print")) { const char *val1 = pop_operand(c); emit2(c, func_print_tc, val1); DEBUG printf("emit %s %s\n", op, val1); } else if (!strcmp(op, "jday")) { const char *val1 = pop_operand(c); emit2(c, func_jday_tc, val1); DEBUG printf("emit %s %s\n", op, val1); } else if (!strcmp(op, "dow")) { const char *val1 = pop_operand(c); emit2(c, func_dow_tc, val1); DEBUG printf("emit %s %s\n", op, val1); } else if (!strcmp(op, "equals")) { emit_code(c, func_eq_tc, operand_count); while (operand_count--) { const char *val1 = pop_operand(c); emit_value(c, val1); DEBUG printf("emit %s '%s'\n", op, val1); } } else if (!strcmp(op, "contains")) { emit_code(c, func_contains_tc, operand_count); while (operand_count--) { const char *val1 = pop_operand(c); emit_value(c, val1); DEBUG printf("emit %s '%s'\n", op, val1); } } else if (!strcmp(op, "begins-with")) { emit_code(c, func_begins_with_tc, operand_count); while (operand_count--) { const char *val1 = pop_operand(c); emit_value(c, val1); DEBUG printf("emit %s '%s'\n", op, val1); } } else if (!strcmp(op, "ends-with")) { emit_code(c, func_ends_with_tc, operand_count); while (operand_count--) { const char *val1 = pop_operand(c); emit_value(c, val1); DEBUG printf("emit %s '%s'\n", op, val1); } } else if (!strcmp(op, "int")) { const char *val1 = pop_operand(c); emit2(c, func_is_int_tc, val1); DEBUG printf("emit %s '%s'\n", op, val1); } else if (!strcmp(op, "real")) { const char *val1 = pop_operand(c); emit2(c, func_is_real_tc, val1); DEBUG printf("emit %s '%s'\n", op, val1); } else if (!strcmp(op, "nan")) { const char *val1 = pop_operand(c); emit2(c, func_is_nan_tc, val1); DEBUG printf("emit %s '%s'\n", op, val1); } else if (!strcmp(op, "string")) { const char *val1 = pop_operand(c); emit2(c, func_is_string_tc, val1); DEBUG printf("emit %s '%s'\n", op, val1); } else if (!strcmp(op, "(")) { return 1; } else if (!strcmp(op, ")")) { return 1; } else { DEBUG printf("bad operator '%s'\n", op); return 0; } push_operand(c, "_STACK"); return 1; }
/** * Translate the trigonometric functions COS, SIN, and SCS * using only the basic instructions * MOV, ADD, MUL, MAD, FRC */ int r300_transform_trig_simple(struct radeon_compiler* c, struct rc_instruction* inst, void* unused) { unsigned int constants[2]; unsigned int tempreg; if (inst->U.I.Opcode != RC_OPCODE_COS && inst->U.I.Opcode != RC_OPCODE_SIN && inst->U.I.Opcode != RC_OPCODE_SCS) return 0; tempreg = rc_find_free_temporary(c); sincos_constants(c, constants); if (inst->U.I.Opcode == RC_OPCODE_COS) { /* MAD tmp.x, src, 1/(2*PI), 0.75 */ /* FRC tmp.x, tmp.x */ /* MAD tmp.z, tmp.x, 2*PI, -PI */ emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W), swizzle_xxxx(inst->U.I.SrcReg[0]), swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[1])), swizzle_xxxx(srcreg(RC_FILE_CONSTANT, constants[1]))); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(tempreg, RC_MASK_W), swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg))); emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W), swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)), swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[1])), negate(swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[0])))); sin_approx(c, inst, inst->U.I.DstReg, swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)), constants); } else if (inst->U.I.Opcode == RC_OPCODE_SIN) { emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W), swizzle_xxxx(inst->U.I.SrcReg[0]), swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[1])), swizzle_yyyy(srcreg(RC_FILE_CONSTANT, constants[1]))); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(tempreg, RC_MASK_W), swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg))); emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W), swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)), swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[1])), negate(swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[0])))); sin_approx(c, inst, inst->U.I.DstReg, swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)), constants); } else { struct rc_dst_register dst; emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_XY), swizzle_xxxx(inst->U.I.SrcReg[0]), swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[1])), swizzle(srcreg(RC_FILE_CONSTANT, constants[1]), RC_SWIZZLE_X, RC_SWIZZLE_Y, RC_SWIZZLE_Z, RC_SWIZZLE_W)); emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(tempreg, RC_MASK_XY), srcreg(RC_FILE_TEMPORARY, tempreg)); emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_XY), srcreg(RC_FILE_TEMPORARY, tempreg), swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[1])), negate(swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[0])))); dst = inst->U.I.DstReg; dst.WriteMask = inst->U.I.DstReg.WriteMask & RC_MASK_X; sin_approx(c, inst, dst, swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg)), constants); dst.WriteMask = inst->U.I.DstReg.WriteMask & RC_MASK_Y; sin_approx(c, inst, dst, swizzle_yyyy(srcreg(RC_FILE_TEMPORARY, tempreg)), constants); } rc_remove_instruction(inst); return 1; }
static void transform_SFL(struct radeon_compiler* c, struct rc_instruction* inst) { emit1(c, inst->Prev, RC_OPCODE_MOV, inst->U.I.SaturateMode, inst->U.I.DstReg, builtin_zero); rc_remove_instruction(inst); }
/** * Definition of LIT (from ARB_fragment_program): * * tmp = VectorLoad(op0); * if (tmp.x < 0) tmp.x = 0; * if (tmp.y < 0) tmp.y = 0; * if (tmp.w < -(128.0-epsilon)) tmp.w = -(128.0-epsilon); * else if (tmp.w > 128-epsilon) tmp.w = 128-epsilon; * result.x = 1.0; * result.y = tmp.x; * result.z = (tmp.x > 0) ? RoughApproxPower(tmp.y, tmp.w) : 0.0; * result.w = 1.0; * * The longest path of computation is the one leading to result.z, * consisting of 5 operations. This implementation of LIT takes * 5 slots, if the subsequent optimization passes are clever enough * to pair instructions correctly. */ static void transform_LIT(struct radeon_compiler* c, struct rc_instruction* inst) { unsigned int constant; unsigned int constant_swizzle; unsigned int temp; struct rc_src_register srctemp; constant = rc_constants_add_immediate_scalar(&c->Program.Constants, -127.999999, &constant_swizzle); if (inst->U.I.DstReg.WriteMask != RC_MASK_XYZW || inst->U.I.DstReg.File != RC_FILE_TEMPORARY) { struct rc_instruction * inst_mov; inst_mov = emit1(c, inst, RC_OPCODE_MOV, 0, inst->U.I.DstReg, srcreg(RC_FILE_TEMPORARY, rc_find_free_temporary(c))); inst->U.I.DstReg.File = RC_FILE_TEMPORARY; inst->U.I.DstReg.Index = inst_mov->U.I.SrcReg[0].Index; inst->U.I.DstReg.WriteMask = RC_MASK_XYZW; } temp = inst->U.I.DstReg.Index; srctemp = srcreg(RC_FILE_TEMPORARY, temp); /* tmp.x = max(0.0, Src.x); */ /* tmp.y = max(0.0, Src.y); */ /* tmp.w = clamp(Src.z, -128+eps, 128-eps); */ emit2(c, inst->Prev, RC_OPCODE_MAX, 0, dstregtmpmask(temp, RC_MASK_XYW), inst->U.I.SrcReg[0], swizzle(srcreg(RC_FILE_CONSTANT, constant), RC_SWIZZLE_ZERO, RC_SWIZZLE_ZERO, RC_SWIZZLE_ZERO, constant_swizzle&3)); emit2(c, inst->Prev, RC_OPCODE_MIN, 0, dstregtmpmask(temp, RC_MASK_Z), swizzle_wwww(srctemp), negate(srcregswz(RC_FILE_CONSTANT, constant, constant_swizzle))); /* tmp.w = Pow(tmp.y, tmp.w) */ emit1(c, inst->Prev, RC_OPCODE_LG2, 0, dstregtmpmask(temp, RC_MASK_W), swizzle_yyyy(srctemp)); emit2(c, inst->Prev, RC_OPCODE_MUL, 0, dstregtmpmask(temp, RC_MASK_W), swizzle_wwww(srctemp), swizzle_zzzz(srctemp)); emit1(c, inst->Prev, RC_OPCODE_EX2, 0, dstregtmpmask(temp, RC_MASK_W), swizzle_wwww(srctemp)); /* tmp.z = (tmp.x > 0) ? tmp.w : 0.0 */ emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, dstregtmpmask(temp, RC_MASK_Z), negate(swizzle_xxxx(srctemp)), swizzle_wwww(srctemp), builtin_zero); /* tmp.x, tmp.y, tmp.w = 1.0, tmp.x, 1.0 */ emit1(c, inst->Prev, RC_OPCODE_MOV, inst->U.I.SaturateMode, dstregtmpmask(temp, RC_MASK_XYW), swizzle(srctemp, RC_SWIZZLE_ONE, RC_SWIZZLE_X, RC_SWIZZLE_ONE, RC_SWIZZLE_ONE)); rc_remove_instruction(inst); }