2 * Copyright (C) 2008 Nicolai Haehnle.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 * Shareable transformations that transform "special" ALU instructions
32 * into ALU instructions that are supported by hardware.
36 #include "radeon_program_alu.h"
38 #include "radeon_compiler.h"
39 #include "radeon_compiler_util.h"
42 static struct rc_instruction *emit1(
43 struct radeon_compiler * c, struct rc_instruction * after,
44 rc_opcode Opcode, rc_saturate_mode Saturate, struct rc_dst_register DstReg,
45 struct rc_src_register SrcReg)
47 struct rc_instruction *fpi = rc_insert_new_instruction(c, after);
49 fpi->U.I.Opcode = Opcode;
50 fpi->U.I.SaturateMode = Saturate;
51 fpi->U.I.DstReg = DstReg;
52 fpi->U.I.SrcReg[0] = SrcReg;
56 static struct rc_instruction *emit2(
57 struct radeon_compiler * c, struct rc_instruction * after,
58 rc_opcode Opcode, rc_saturate_mode Saturate, struct rc_dst_register DstReg,
59 struct rc_src_register SrcReg0, struct rc_src_register SrcReg1)
61 struct rc_instruction *fpi = rc_insert_new_instruction(c, after);
63 fpi->U.I.Opcode = Opcode;
64 fpi->U.I.SaturateMode = Saturate;
65 fpi->U.I.DstReg = DstReg;
66 fpi->U.I.SrcReg[0] = SrcReg0;
67 fpi->U.I.SrcReg[1] = SrcReg1;
71 static struct rc_instruction *emit3(
72 struct radeon_compiler * c, struct rc_instruction * after,
73 rc_opcode Opcode, rc_saturate_mode Saturate, struct rc_dst_register DstReg,
74 struct rc_src_register SrcReg0, struct rc_src_register SrcReg1,
75 struct rc_src_register SrcReg2)
77 struct rc_instruction *fpi = rc_insert_new_instruction(c, after);
79 fpi->U.I.Opcode = Opcode;
80 fpi->U.I.SaturateMode = Saturate;
81 fpi->U.I.DstReg = DstReg;
82 fpi->U.I.SrcReg[0] = SrcReg0;
83 fpi->U.I.SrcReg[1] = SrcReg1;
84 fpi->U.I.SrcReg[2] = SrcReg2;
88 static struct rc_dst_register dstregtmpmask(int index, int mask)
90 struct rc_dst_register dst = {0};
91 dst.File = RC_FILE_TEMPORARY;
97 static const struct rc_src_register builtin_zero = {
100 .Swizzle = RC_SWIZZLE_0000
102 static const struct rc_src_register builtin_one = {
103 .File = RC_FILE_NONE,
105 .Swizzle = RC_SWIZZLE_1111
107 static const struct rc_src_register srcreg_undefined = {
108 .File = RC_FILE_NONE,
110 .Swizzle = RC_SWIZZLE_XYZW
113 static struct rc_src_register srcreg(int file, int index)
115 struct rc_src_register src = srcreg_undefined;
121 static struct rc_src_register srcregswz(int file, int index, int swz)
123 struct rc_src_register src = srcreg_undefined;
130 static struct rc_src_register absolute(struct rc_src_register reg)
132 struct rc_src_register newreg = reg;
134 newreg.Negate = RC_MASK_NONE;
138 static struct rc_src_register negate(struct rc_src_register reg)
140 struct rc_src_register newreg = reg;
141 newreg.Negate = newreg.Negate ^ RC_MASK_XYZW;
145 static struct rc_src_register swizzle(struct rc_src_register reg,
146 rc_swizzle x, rc_swizzle y, rc_swizzle z, rc_swizzle w)
148 struct rc_src_register swizzled = reg;
149 swizzled.Swizzle = combine_swizzles4(reg.Swizzle, x, y, z, w);
153 static struct rc_src_register swizzle_smear(struct rc_src_register reg,
156 return swizzle(reg, x, x, x, x);
159 static struct rc_src_register swizzle_xxxx(struct rc_src_register reg)
161 return swizzle_smear(reg, RC_SWIZZLE_X);
164 static struct rc_src_register swizzle_yyyy(struct rc_src_register reg)
166 return swizzle_smear(reg, RC_SWIZZLE_Y);
169 static struct rc_src_register swizzle_zzzz(struct rc_src_register reg)
171 return swizzle_smear(reg, RC_SWIZZLE_Z);
174 static struct rc_src_register swizzle_wwww(struct rc_src_register reg)
176 return swizzle_smear(reg, RC_SWIZZLE_W);
179 static int is_dst_safe_to_reuse(struct rc_instruction *inst)
181 const struct rc_opcode_info *info = rc_get_opcode_info(inst->U.I.Opcode);
184 assert(info->HasDstReg);
186 if (inst->U.I.DstReg.File != RC_FILE_TEMPORARY)
189 for (i = 0; i < info->NumSrcRegs; i++) {
190 if (inst->U.I.SrcReg[i].File == RC_FILE_TEMPORARY &&
191 inst->U.I.SrcReg[i].Index == inst->U.I.DstReg.Index)
198 static struct rc_dst_register try_to_reuse_dst(struct radeon_compiler *c,
199 struct rc_instruction *inst)
203 if (is_dst_safe_to_reuse(inst))
204 tmp = inst->U.I.DstReg.Index;
206 tmp = rc_find_free_temporary(c);
208 return dstregtmpmask(tmp, inst->U.I.DstReg.WriteMask);
211 static void transform_ABS(struct radeon_compiler* c,
212 struct rc_instruction* inst)
214 struct rc_src_register src = inst->U.I.SrcReg[0];
216 src.Negate = RC_MASK_NONE;
217 emit1(c, inst->Prev, RC_OPCODE_MOV, inst->U.I.SaturateMode, inst->U.I.DstReg, src);
218 rc_remove_instruction(inst);
221 static void transform_CEIL(struct radeon_compiler* c,
222 struct rc_instruction* inst)
225 * ceil(x) = -floor(-x)
227 * After inlining floor:
228 * ceil(x) = -(-x-frac(-x))
230 * After simplification:
231 * ceil(x) = x+frac(-x)
234 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
235 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dst, negate(inst->U.I.SrcReg[0]));
236 emit2(c, inst->Prev, RC_OPCODE_ADD, inst->U.I.SaturateMode, inst->U.I.DstReg,
237 inst->U.I.SrcReg[0], srcreg(RC_FILE_TEMPORARY, dst.Index));
238 rc_remove_instruction(inst);
241 static void transform_CLAMP(struct radeon_compiler *c,
242 struct rc_instruction *inst)
244 /* CLAMP dst, src, min, max
249 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
250 emit2(c, inst->Prev, RC_OPCODE_MIN, 0, dst,
251 inst->U.I.SrcReg[0], inst->U.I.SrcReg[2]);
252 emit2(c, inst->Prev, RC_OPCODE_MAX, inst->U.I.SaturateMode, inst->U.I.DstReg,
253 srcreg(RC_FILE_TEMPORARY, dst.Index), inst->U.I.SrcReg[1]);
254 rc_remove_instruction(inst);
257 static void transform_DP2(struct radeon_compiler* c,
258 struct rc_instruction* inst)
260 struct rc_src_register src0 = inst->U.I.SrcReg[0];
261 struct rc_src_register src1 = inst->U.I.SrcReg[1];
262 src0.Negate &= ~(RC_MASK_Z | RC_MASK_W);
263 src0.Swizzle &= ~(63 << (3 * 2));
264 src0.Swizzle |= (RC_SWIZZLE_ZERO << (3 * 2)) | (RC_SWIZZLE_ZERO << (3 * 3));
265 src1.Negate &= ~(RC_MASK_Z | RC_MASK_W);
266 src1.Swizzle &= ~(63 << (3 * 2));
267 src1.Swizzle |= (RC_SWIZZLE_ZERO << (3 * 2)) | (RC_SWIZZLE_ZERO << (3 * 3));
268 emit2(c, inst->Prev, RC_OPCODE_DP3, inst->U.I.SaturateMode, inst->U.I.DstReg, src0, src1);
269 rc_remove_instruction(inst);
272 static void transform_DPH(struct radeon_compiler* c,
273 struct rc_instruction* inst)
275 struct rc_src_register src0 = inst->U.I.SrcReg[0];
276 src0.Negate &= ~RC_MASK_W;
277 src0.Swizzle &= ~(7 << (3 * 3));
278 src0.Swizzle |= RC_SWIZZLE_ONE << (3 * 3);
279 emit2(c, inst->Prev, RC_OPCODE_DP4, inst->U.I.SaturateMode, inst->U.I.DstReg, src0, inst->U.I.SrcReg[1]);
280 rc_remove_instruction(inst);
284 * [1, src0.y*src1.y, src0.z, src1.w]
285 * So basically MUL with lotsa swizzling.
287 static void transform_DST(struct radeon_compiler* c,
288 struct rc_instruction* inst)
290 emit2(c, inst->Prev, RC_OPCODE_MUL, inst->U.I.SaturateMode, inst->U.I.DstReg,
291 swizzle(inst->U.I.SrcReg[0], RC_SWIZZLE_ONE, RC_SWIZZLE_Y, RC_SWIZZLE_Z, RC_SWIZZLE_ONE),
292 swizzle(inst->U.I.SrcReg[1], RC_SWIZZLE_ONE, RC_SWIZZLE_Y, RC_SWIZZLE_ONE, RC_SWIZZLE_W));
293 rc_remove_instruction(inst);
296 static void transform_FLR(struct radeon_compiler* c,
297 struct rc_instruction* inst)
299 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
300 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dst, inst->U.I.SrcReg[0]);
301 emit2(c, inst->Prev, RC_OPCODE_ADD, inst->U.I.SaturateMode, inst->U.I.DstReg,
302 inst->U.I.SrcReg[0], negate(srcreg(RC_FILE_TEMPORARY, dst.Index)));
303 rc_remove_instruction(inst);
307 * Definition of LIT (from ARB_fragment_program):
309 * tmp = VectorLoad(op0);
310 * if (tmp.x < 0) tmp.x = 0;
311 * if (tmp.y < 0) tmp.y = 0;
312 * if (tmp.w < -(128.0-epsilon)) tmp.w = -(128.0-epsilon);
313 * else if (tmp.w > 128-epsilon) tmp.w = 128-epsilon;
316 * result.z = (tmp.x > 0) ? RoughApproxPower(tmp.y, tmp.w) : 0.0;
319 * The longest path of computation is the one leading to result.z,
320 * consisting of 5 operations. This implementation of LIT takes
321 * 5 slots, if the subsequent optimization passes are clever enough
322 * to pair instructions correctly.
324 static void transform_LIT(struct radeon_compiler* c,
325 struct rc_instruction* inst)
327 unsigned int constant;
328 unsigned int constant_swizzle;
330 struct rc_src_register srctemp;
332 constant = rc_constants_add_immediate_scalar(&c->Program.Constants, -127.999999, &constant_swizzle);
334 if (inst->U.I.DstReg.WriteMask != RC_MASK_XYZW || inst->U.I.DstReg.File != RC_FILE_TEMPORARY) {
335 struct rc_instruction * inst_mov;
337 inst_mov = emit1(c, inst,
338 RC_OPCODE_MOV, 0, inst->U.I.DstReg,
339 srcreg(RC_FILE_TEMPORARY, rc_find_free_temporary(c)));
341 inst->U.I.DstReg.File = RC_FILE_TEMPORARY;
342 inst->U.I.DstReg.Index = inst_mov->U.I.SrcReg[0].Index;
343 inst->U.I.DstReg.WriteMask = RC_MASK_XYZW;
346 temp = inst->U.I.DstReg.Index;
347 srctemp = srcreg(RC_FILE_TEMPORARY, temp);
349 /* tmp.x = max(0.0, Src.x); */
350 /* tmp.y = max(0.0, Src.y); */
351 /* tmp.w = clamp(Src.z, -128+eps, 128-eps); */
352 emit2(c, inst->Prev, RC_OPCODE_MAX, 0,
353 dstregtmpmask(temp, RC_MASK_XYW),
355 swizzle(srcreg(RC_FILE_CONSTANT, constant),
356 RC_SWIZZLE_ZERO, RC_SWIZZLE_ZERO, RC_SWIZZLE_ZERO, constant_swizzle&3));
357 emit2(c, inst->Prev, RC_OPCODE_MIN, 0,
358 dstregtmpmask(temp, RC_MASK_Z),
359 swizzle_wwww(srctemp),
360 negate(srcregswz(RC_FILE_CONSTANT, constant, constant_swizzle)));
362 /* tmp.w = Pow(tmp.y, tmp.w) */
363 emit1(c, inst->Prev, RC_OPCODE_LG2, 0,
364 dstregtmpmask(temp, RC_MASK_W),
365 swizzle_yyyy(srctemp));
366 emit2(c, inst->Prev, RC_OPCODE_MUL, 0,
367 dstregtmpmask(temp, RC_MASK_W),
368 swizzle_wwww(srctemp),
369 swizzle_zzzz(srctemp));
370 emit1(c, inst->Prev, RC_OPCODE_EX2, 0,
371 dstregtmpmask(temp, RC_MASK_W),
372 swizzle_wwww(srctemp));
374 /* tmp.z = (tmp.x > 0) ? tmp.w : 0.0 */
375 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode,
376 dstregtmpmask(temp, RC_MASK_Z),
377 negate(swizzle_xxxx(srctemp)),
378 swizzle_wwww(srctemp),
381 /* tmp.x, tmp.y, tmp.w = 1.0, tmp.x, 1.0 */
382 emit1(c, inst->Prev, RC_OPCODE_MOV, inst->U.I.SaturateMode,
383 dstregtmpmask(temp, RC_MASK_XYW),
384 swizzle(srctemp, RC_SWIZZLE_ONE, RC_SWIZZLE_X, RC_SWIZZLE_ONE, RC_SWIZZLE_ONE));
386 rc_remove_instruction(inst);
389 static void transform_LRP(struct radeon_compiler* c,
390 struct rc_instruction* inst)
392 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
394 emit2(c, inst->Prev, RC_OPCODE_ADD, 0,
396 inst->U.I.SrcReg[1], negate(inst->U.I.SrcReg[2]));
397 emit3(c, inst->Prev, RC_OPCODE_MAD, inst->U.I.SaturateMode,
399 inst->U.I.SrcReg[0], srcreg(RC_FILE_TEMPORARY, dst.Index), inst->U.I.SrcReg[2]);
401 rc_remove_instruction(inst);
404 static void transform_POW(struct radeon_compiler* c,
405 struct rc_instruction* inst)
407 struct rc_dst_register tempdst = try_to_reuse_dst(c, inst);
408 struct rc_src_register tempsrc = srcreg(RC_FILE_TEMPORARY, tempdst.Index);
409 tempdst.WriteMask = RC_MASK_W;
410 tempsrc.Swizzle = RC_SWIZZLE_WWWW;
412 emit1(c, inst->Prev, RC_OPCODE_LG2, 0, tempdst, swizzle_xxxx(inst->U.I.SrcReg[0]));
413 emit2(c, inst->Prev, RC_OPCODE_MUL, 0, tempdst, tempsrc, swizzle_xxxx(inst->U.I.SrcReg[1]));
414 emit1(c, inst->Prev, RC_OPCODE_EX2, inst->U.I.SaturateMode, inst->U.I.DstReg, tempsrc);
416 rc_remove_instruction(inst);
419 static void transform_RSQ(struct radeon_compiler* c,
420 struct rc_instruction* inst)
422 inst->U.I.SrcReg[0] = absolute(inst->U.I.SrcReg[0]);
425 static void transform_SEQ(struct radeon_compiler* c,
426 struct rc_instruction* inst)
428 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
430 emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, inst->U.I.SrcReg[0], negate(inst->U.I.SrcReg[1]));
431 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, inst->U.I.DstReg,
432 negate(absolute(srcreg(RC_FILE_TEMPORARY, dst.Index))), builtin_zero, builtin_one);
434 rc_remove_instruction(inst);
437 static void transform_SFL(struct radeon_compiler* c,
438 struct rc_instruction* inst)
440 emit1(c, inst->Prev, RC_OPCODE_MOV, inst->U.I.SaturateMode, inst->U.I.DstReg, builtin_zero);
441 rc_remove_instruction(inst);
444 static void transform_SGE(struct radeon_compiler* c,
445 struct rc_instruction* inst)
447 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
449 emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, inst->U.I.SrcReg[0], negate(inst->U.I.SrcReg[1]));
450 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, inst->U.I.DstReg,
451 srcreg(RC_FILE_TEMPORARY, dst.Index), builtin_zero, builtin_one);
453 rc_remove_instruction(inst);
456 static void transform_SGT(struct radeon_compiler* c,
457 struct rc_instruction* inst)
459 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
461 emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, negate(inst->U.I.SrcReg[0]), inst->U.I.SrcReg[1]);
462 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, inst->U.I.DstReg,
463 srcreg(RC_FILE_TEMPORARY, dst.Index), builtin_one, builtin_zero);
465 rc_remove_instruction(inst);
468 static void transform_SLE(struct radeon_compiler* c,
469 struct rc_instruction* inst)
471 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
473 emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, negate(inst->U.I.SrcReg[0]), inst->U.I.SrcReg[1]);
474 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, inst->U.I.DstReg,
475 srcreg(RC_FILE_TEMPORARY, dst.Index), builtin_zero, builtin_one);
477 rc_remove_instruction(inst);
480 static void transform_SLT(struct radeon_compiler* c,
481 struct rc_instruction* inst)
483 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
485 emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, inst->U.I.SrcReg[0], negate(inst->U.I.SrcReg[1]));
486 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, inst->U.I.DstReg,
487 srcreg(RC_FILE_TEMPORARY, dst.Index), builtin_one, builtin_zero);
489 rc_remove_instruction(inst);
492 static void transform_SNE(struct radeon_compiler* c,
493 struct rc_instruction* inst)
495 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
497 emit2(c, inst->Prev, RC_OPCODE_ADD, 0, dst, inst->U.I.SrcReg[0], negate(inst->U.I.SrcReg[1]));
498 emit3(c, inst->Prev, RC_OPCODE_CMP, inst->U.I.SaturateMode, inst->U.I.DstReg,
499 negate(absolute(srcreg(RC_FILE_TEMPORARY, dst.Index))), builtin_one, builtin_zero);
501 rc_remove_instruction(inst);
504 static void transform_SSG(struct radeon_compiler* c,
505 struct rc_instruction* inst)
511 * ADD result, tmp0, -tmp1;
513 struct rc_dst_register dst0;
517 dst0 = try_to_reuse_dst(c, inst);
518 emit3(c, inst->Prev, RC_OPCODE_CMP, 0,
520 negate(inst->U.I.SrcReg[0]),
525 tmp1 = rc_find_free_temporary(c);
526 emit3(c, inst->Prev, RC_OPCODE_CMP, 0,
527 dstregtmpmask(tmp1, inst->U.I.DstReg.WriteMask),
532 /* Either both are zero, or one of them is one and the other is zero. */
533 /* result = tmp0 - tmp1 */
534 emit2(c, inst->Prev, RC_OPCODE_ADD, 0,
536 srcreg(RC_FILE_TEMPORARY, dst0.Index),
537 negate(srcreg(RC_FILE_TEMPORARY, tmp1)));
539 rc_remove_instruction(inst);
542 static void transform_SUB(struct radeon_compiler* c,
543 struct rc_instruction* inst)
545 inst->U.I.Opcode = RC_OPCODE_ADD;
546 inst->U.I.SrcReg[1] = negate(inst->U.I.SrcReg[1]);
549 static void transform_SWZ(struct radeon_compiler* c,
550 struct rc_instruction* inst)
552 inst->U.I.Opcode = RC_OPCODE_MOV;
555 static void transform_XPD(struct radeon_compiler* c,
556 struct rc_instruction* inst)
558 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
560 emit2(c, inst->Prev, RC_OPCODE_MUL, 0, dst,
561 swizzle(inst->U.I.SrcReg[0], RC_SWIZZLE_Z, RC_SWIZZLE_X, RC_SWIZZLE_Y, RC_SWIZZLE_W),
562 swizzle(inst->U.I.SrcReg[1], RC_SWIZZLE_Y, RC_SWIZZLE_Z, RC_SWIZZLE_X, RC_SWIZZLE_W));
563 emit3(c, inst->Prev, RC_OPCODE_MAD, inst->U.I.SaturateMode, inst->U.I.DstReg,
564 swizzle(inst->U.I.SrcReg[0], RC_SWIZZLE_Y, RC_SWIZZLE_Z, RC_SWIZZLE_X, RC_SWIZZLE_W),
565 swizzle(inst->U.I.SrcReg[1], RC_SWIZZLE_Z, RC_SWIZZLE_X, RC_SWIZZLE_Y, RC_SWIZZLE_W),
566 negate(srcreg(RC_FILE_TEMPORARY, dst.Index)));
568 rc_remove_instruction(inst);
573 * Can be used as a transformation for @ref radeonClauseLocalTransform,
574 * no userData necessary.
576 * Eliminates the following ALU instructions:
577 * ABS, CEIL, DPH, DST, FLR, LIT, LRP, POW, SEQ, SFL, SGE, SGT, SLE, SLT, SNE, SUB, SWZ, XPD
579 * MOV, ADD, MUL, MAD, FRC, DP3, LG2, EX2, CMP
581 * Transforms RSQ to Radeon's native RSQ by explicitly setting
584 * @note should be applicable to R300 and R500 fragment programs.
586 int radeonTransformALU(
587 struct radeon_compiler * c,
588 struct rc_instruction* inst,
591 switch(inst->U.I.Opcode) {
592 case RC_OPCODE_ABS: transform_ABS(c, inst); return 1;
593 case RC_OPCODE_CEIL: transform_CEIL(c, inst); return 1;
594 case RC_OPCODE_CLAMP: transform_CLAMP(c, inst); return 1;
595 case RC_OPCODE_DP2: transform_DP2(c, inst); return 1;
596 case RC_OPCODE_DPH: transform_DPH(c, inst); return 1;
597 case RC_OPCODE_DST: transform_DST(c, inst); return 1;
598 case RC_OPCODE_FLR: transform_FLR(c, inst); return 1;
599 case RC_OPCODE_LIT: transform_LIT(c, inst); return 1;
600 case RC_OPCODE_LRP: transform_LRP(c, inst); return 1;
601 case RC_OPCODE_POW: transform_POW(c, inst); return 1;
602 case RC_OPCODE_RSQ: transform_RSQ(c, inst); return 1;
603 case RC_OPCODE_SEQ: transform_SEQ(c, inst); return 1;
604 case RC_OPCODE_SFL: transform_SFL(c, inst); return 1;
605 case RC_OPCODE_SGE: transform_SGE(c, inst); return 1;
606 case RC_OPCODE_SGT: transform_SGT(c, inst); return 1;
607 case RC_OPCODE_SLE: transform_SLE(c, inst); return 1;
608 case RC_OPCODE_SLT: transform_SLT(c, inst); return 1;
609 case RC_OPCODE_SNE: transform_SNE(c, inst); return 1;
610 case RC_OPCODE_SSG: transform_SSG(c, inst); return 1;
611 case RC_OPCODE_SUB: transform_SUB(c, inst); return 1;
612 case RC_OPCODE_SWZ: transform_SWZ(c, inst); return 1;
613 case RC_OPCODE_XPD: transform_XPD(c, inst); return 1;
620 static void transform_r300_vertex_ABS(struct radeon_compiler* c,
621 struct rc_instruction* inst)
623 /* Note: r500 can take absolute values, but r300 cannot. */
624 inst->U.I.Opcode = RC_OPCODE_MAX;
625 inst->U.I.SrcReg[1] = inst->U.I.SrcReg[0];
626 inst->U.I.SrcReg[1].Negate ^= RC_MASK_XYZW;
629 static void transform_r300_vertex_CMP(struct radeon_compiler* c,
630 struct rc_instruction* inst)
632 /* There is no decent CMP available, so let's rig one up.
633 * CMP is defined as dst = src0 < 0.0 ? src1 : src2
634 * The following sequence consumes zero to two temps and two extra slots
635 * (the second temp and the second slot is consumed by transform_LRP),
636 * but should be equivalent:
638 * SLT tmp0, src0, 0.0
639 * LRP dst, tmp0, src1, src2
641 * Yes, I know, I'm a mad scientist. ~ C. & M. */
642 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
644 /* SLT tmp0, src0, 0.0 */
645 emit2(c, inst->Prev, RC_OPCODE_SLT, 0,
647 inst->U.I.SrcReg[0], builtin_zero);
649 /* LRP dst, tmp0, src1, src2 */
651 emit3(c, inst->Prev, RC_OPCODE_LRP, 0,
653 srcreg(RC_FILE_TEMPORARY, dst.Index), inst->U.I.SrcReg[1], inst->U.I.SrcReg[2]));
655 rc_remove_instruction(inst);
658 static void transform_r300_vertex_DP2(struct radeon_compiler* c,
659 struct rc_instruction* inst)
661 struct rc_instruction *next_inst = inst->Next;
662 transform_DP2(c, inst);
663 next_inst->Prev->U.I.Opcode = RC_OPCODE_DP4;
666 static void transform_r300_vertex_DP3(struct radeon_compiler* c,
667 struct rc_instruction* inst)
669 struct rc_src_register src0 = inst->U.I.SrcReg[0];
670 struct rc_src_register src1 = inst->U.I.SrcReg[1];
671 src0.Negate &= ~RC_MASK_W;
672 src0.Swizzle &= ~(7 << (3 * 3));
673 src0.Swizzle |= RC_SWIZZLE_ZERO << (3 * 3);
674 src1.Negate &= ~RC_MASK_W;
675 src1.Swizzle &= ~(7 << (3 * 3));
676 src1.Swizzle |= RC_SWIZZLE_ZERO << (3 * 3);
677 emit2(c, inst->Prev, RC_OPCODE_DP4, inst->U.I.SaturateMode, inst->U.I.DstReg, src0, src1);
678 rc_remove_instruction(inst);
681 static void transform_r300_vertex_fix_LIT(struct radeon_compiler* c,
682 struct rc_instruction* inst)
684 struct rc_dst_register dst = try_to_reuse_dst(c, inst);
685 unsigned constant_swizzle;
686 int constant = rc_constants_add_immediate_scalar(&c->Program.Constants,
687 0.0000000000000000001,
691 dst.WriteMask = RC_MASK_XYZW;
692 emit1(c, inst->Prev, RC_OPCODE_MOV, 0,
694 inst->U.I.SrcReg[0]);
696 /* MAX dst.y, src, 0.00...001 */
697 emit2(c, inst->Prev, RC_OPCODE_MAX, 0,
698 dstregtmpmask(dst.Index, RC_MASK_Y),
699 srcreg(RC_FILE_TEMPORARY, dst.Index),
700 srcregswz(RC_FILE_CONSTANT, constant, constant_swizzle));
702 inst->U.I.SrcReg[0] = srcreg(RC_FILE_TEMPORARY, dst.Index);
705 static void transform_r300_vertex_SEQ(struct radeon_compiler *c,
706 struct rc_instruction *inst)
708 /* x = y <==> x >= y && y >= x */
709 int tmp = rc_find_free_temporary(c);
712 emit2(c, inst->Prev, RC_OPCODE_SGE, 0,
713 dstregtmpmask(tmp, inst->U.I.DstReg.WriteMask),
715 inst->U.I.SrcReg[1]);
718 emit2(c, inst->Prev, RC_OPCODE_SGE, 0,
721 inst->U.I.SrcReg[0]);
724 emit2(c, inst->Prev, RC_OPCODE_MUL, 0,
726 srcreg(RC_FILE_TEMPORARY, tmp),
727 srcreg(inst->U.I.DstReg.File, inst->U.I.DstReg.Index));
729 rc_remove_instruction(inst);
732 static void transform_r300_vertex_SNE(struct radeon_compiler *c,
733 struct rc_instruction *inst)
735 /* x != y <==> x < y || y < x */
736 int tmp = rc_find_free_temporary(c);
739 emit2(c, inst->Prev, RC_OPCODE_SLT, 0,
740 dstregtmpmask(tmp, inst->U.I.DstReg.WriteMask),
742 inst->U.I.SrcReg[1]);
745 emit2(c, inst->Prev, RC_OPCODE_SLT, 0,
748 inst->U.I.SrcReg[0]);
750 /* x || y = max(x, y) */
751 emit2(c, inst->Prev, RC_OPCODE_MAX, 0,
753 srcreg(RC_FILE_TEMPORARY, tmp),
754 srcreg(inst->U.I.DstReg.File, inst->U.I.DstReg.Index));
756 rc_remove_instruction(inst);
759 static void transform_r300_vertex_SGT(struct radeon_compiler* c,
760 struct rc_instruction* inst)
762 /* x > y <==> -x < -y */
763 inst->U.I.Opcode = RC_OPCODE_SLT;
764 inst->U.I.SrcReg[0].Negate ^= RC_MASK_XYZW;
765 inst->U.I.SrcReg[1].Negate ^= RC_MASK_XYZW;
768 static void transform_r300_vertex_SLE(struct radeon_compiler* c,
769 struct rc_instruction* inst)
771 /* x <= y <==> -x >= -y */
772 inst->U.I.Opcode = RC_OPCODE_SGE;
773 inst->U.I.SrcReg[0].Negate ^= RC_MASK_XYZW;
774 inst->U.I.SrcReg[1].Negate ^= RC_MASK_XYZW;
777 static void transform_r300_vertex_SSG(struct radeon_compiler* c,
778 struct rc_instruction* inst)
784 * ADD result, tmp0, -tmp1;
786 struct rc_dst_register dst0 = try_to_reuse_dst(c, inst);
790 dst0 = try_to_reuse_dst(c, inst);
791 emit2(c, inst->Prev, RC_OPCODE_SLT, 0,
794 inst->U.I.SrcReg[0]);
797 tmp1 = rc_find_free_temporary(c);
798 emit2(c, inst->Prev, RC_OPCODE_SLT, 0,
799 dstregtmpmask(tmp1, inst->U.I.DstReg.WriteMask),
803 /* Either both are zero, or one of them is one and the other is zero. */
804 /* result = tmp0 - tmp1 */
805 emit2(c, inst->Prev, RC_OPCODE_ADD, 0,
807 srcreg(RC_FILE_TEMPORARY, dst0.Index),
808 negate(srcreg(RC_FILE_TEMPORARY, tmp1)));
810 rc_remove_instruction(inst);
814 * For use with rc_local_transform, this transforms non-native ALU
815 * instructions of the r300 up to r500 vertex engine.
817 int r300_transform_vertex_alu(
818 struct radeon_compiler * c,
819 struct rc_instruction* inst,
822 switch(inst->U.I.Opcode) {
823 case RC_OPCODE_ABS: transform_r300_vertex_ABS(c, inst); return 1;
824 case RC_OPCODE_CEIL: transform_CEIL(c, inst); return 1;
825 case RC_OPCODE_CLAMP: transform_CLAMP(c, inst); return 1;
826 case RC_OPCODE_CMP: transform_r300_vertex_CMP(c, inst); return 1;
827 case RC_OPCODE_DP2: transform_r300_vertex_DP2(c, inst); return 1;
828 case RC_OPCODE_DP3: transform_r300_vertex_DP3(c, inst); return 1;
829 case RC_OPCODE_DPH: transform_DPH(c, inst); return 1;
830 case RC_OPCODE_FLR: transform_FLR(c, inst); return 1;
831 case RC_OPCODE_LIT: transform_r300_vertex_fix_LIT(c, inst); return 1;
832 case RC_OPCODE_LRP: transform_LRP(c, inst); return 1;
835 transform_r300_vertex_SEQ(c, inst);
839 case RC_OPCODE_SFL: transform_SFL(c, inst); return 1;
840 case RC_OPCODE_SGT: transform_r300_vertex_SGT(c, inst); return 1;
841 case RC_OPCODE_SLE: transform_r300_vertex_SLE(c, inst); return 1;
844 transform_r300_vertex_SNE(c, inst);
848 case RC_OPCODE_SSG: transform_r300_vertex_SSG(c, inst); return 1;
849 case RC_OPCODE_SUB: transform_SUB(c, inst); return 1;
850 case RC_OPCODE_SWZ: transform_SWZ(c, inst); return 1;
851 case RC_OPCODE_XPD: transform_XPD(c, inst); return 1;
857 static void sincos_constants(struct radeon_compiler* c, unsigned int *constants)
859 static const float SinCosConsts[2][4] = {
861 1.273239545, /* 4/PI */
862 -0.405284735, /* -4/(PI*PI) */
863 3.141592654, /* PI */
869 0.159154943, /* 1/(2*PI) */
870 6.283185307 /* 2*PI */
875 for(i = 0; i < 2; ++i)
876 constants[i] = rc_constants_add_immediate_vec4(&c->Program.Constants, SinCosConsts[i]);
880 * Approximate sin(x), where x is clamped to (-pi/2, pi/2).
882 * MUL tmp.xy, src, { 4/PI, -4/(PI^2) }
883 * MAD tmp.x, tmp.y, |src|, tmp.x
884 * MAD tmp.y, tmp.x, |tmp.x|, -tmp.x
885 * MAD dest, tmp.y, weight, tmp.x
887 static void sin_approx(
888 struct radeon_compiler* c, struct rc_instruction * inst,
889 struct rc_dst_register dst, struct rc_src_register src, const unsigned int* constants)
891 unsigned int tempreg = rc_find_free_temporary(c);
893 emit2(c, inst->Prev, RC_OPCODE_MUL, 0, dstregtmpmask(tempreg, RC_MASK_XY),
895 srcreg(RC_FILE_CONSTANT, constants[0]));
896 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_X),
897 swizzle_yyyy(srcreg(RC_FILE_TEMPORARY, tempreg)),
898 absolute(swizzle_xxxx(src)),
899 swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg)));
900 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_Y),
901 swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg)),
902 absolute(swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg))),
903 negate(swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg))));
904 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dst,
905 swizzle_yyyy(srcreg(RC_FILE_TEMPORARY, tempreg)),
906 swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[0])),
907 swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg)));
911 * Translate the trigonometric functions COS, SIN, and SCS
912 * using only the basic instructions
913 * MOV, ADD, MUL, MAD, FRC
915 int r300_transform_trig_simple(struct radeon_compiler* c,
916 struct rc_instruction* inst,
919 unsigned int constants[2];
920 unsigned int tempreg;
922 if (inst->U.I.Opcode != RC_OPCODE_COS &&
923 inst->U.I.Opcode != RC_OPCODE_SIN &&
924 inst->U.I.Opcode != RC_OPCODE_SCS)
927 tempreg = rc_find_free_temporary(c);
929 sincos_constants(c, constants);
931 if (inst->U.I.Opcode == RC_OPCODE_COS) {
932 /* MAD tmp.x, src, 1/(2*PI), 0.75 */
933 /* FRC tmp.x, tmp.x */
934 /* MAD tmp.z, tmp.x, 2*PI, -PI */
935 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W),
936 swizzle_xxxx(inst->U.I.SrcReg[0]),
937 swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[1])),
938 swizzle_xxxx(srcreg(RC_FILE_CONSTANT, constants[1])));
939 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(tempreg, RC_MASK_W),
940 swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)));
941 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W),
942 swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)),
943 swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[1])),
944 negate(swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[0]))));
946 sin_approx(c, inst, inst->U.I.DstReg,
947 swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)),
949 } else if (inst->U.I.Opcode == RC_OPCODE_SIN) {
950 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W),
951 swizzle_xxxx(inst->U.I.SrcReg[0]),
952 swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[1])),
953 swizzle_yyyy(srcreg(RC_FILE_CONSTANT, constants[1])));
954 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(tempreg, RC_MASK_W),
955 swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)));
956 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_W),
957 swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)),
958 swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[1])),
959 negate(swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[0]))));
961 sin_approx(c, inst, inst->U.I.DstReg,
962 swizzle_wwww(srcreg(RC_FILE_TEMPORARY, tempreg)),
965 struct rc_dst_register dst;
967 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_XY),
968 swizzle_xxxx(inst->U.I.SrcReg[0]),
969 swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[1])),
970 swizzle(srcreg(RC_FILE_CONSTANT, constants[1]), RC_SWIZZLE_X, RC_SWIZZLE_Y, RC_SWIZZLE_Z, RC_SWIZZLE_W));
971 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(tempreg, RC_MASK_XY),
972 srcreg(RC_FILE_TEMPORARY, tempreg));
973 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(tempreg, RC_MASK_XY),
974 srcreg(RC_FILE_TEMPORARY, tempreg),
975 swizzle_wwww(srcreg(RC_FILE_CONSTANT, constants[1])),
976 negate(swizzle_zzzz(srcreg(RC_FILE_CONSTANT, constants[0]))));
978 dst = inst->U.I.DstReg;
980 dst.WriteMask = inst->U.I.DstReg.WriteMask & RC_MASK_X;
981 sin_approx(c, inst, dst,
982 swizzle_xxxx(srcreg(RC_FILE_TEMPORARY, tempreg)),
985 dst.WriteMask = inst->U.I.DstReg.WriteMask & RC_MASK_Y;
986 sin_approx(c, inst, dst,
987 swizzle_yyyy(srcreg(RC_FILE_TEMPORARY, tempreg)),
991 rc_remove_instruction(inst);
996 static void r300_transform_SIN_COS_SCS(struct radeon_compiler *c,
997 struct rc_instruction *inst,
1000 if (inst->U.I.Opcode == RC_OPCODE_COS) {
1001 emit1(c, inst->Prev, RC_OPCODE_COS, inst->U.I.SaturateMode, inst->U.I.DstReg,
1002 srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW));
1003 } else if (inst->U.I.Opcode == RC_OPCODE_SIN) {
1004 emit1(c, inst->Prev, RC_OPCODE_SIN, inst->U.I.SaturateMode,
1005 inst->U.I.DstReg, srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW));
1006 } else if (inst->U.I.Opcode == RC_OPCODE_SCS) {
1007 struct rc_dst_register moddst = inst->U.I.DstReg;
1009 if (inst->U.I.DstReg.WriteMask & RC_MASK_X) {
1010 moddst.WriteMask = RC_MASK_X;
1011 emit1(c, inst->Prev, RC_OPCODE_COS, inst->U.I.SaturateMode, moddst,
1012 srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW));
1014 if (inst->U.I.DstReg.WriteMask & RC_MASK_Y) {
1015 moddst.WriteMask = RC_MASK_Y;
1016 emit1(c, inst->Prev, RC_OPCODE_SIN, inst->U.I.SaturateMode, moddst,
1017 srcregswz(RC_FILE_TEMPORARY, srctmp, RC_SWIZZLE_WWWW));
1021 rc_remove_instruction(inst);
1026 * Transform the trigonometric functions COS, SIN, and SCS
1027 * to include pre-scaling by 1/(2*PI) and taking the fractional
1028 * part, so that the input to COS and SIN is always in the range [0,1).
1029 * SCS is replaced by one COS and one SIN instruction.
1031 * @warning This transformation implicitly changes the semantics of SIN and COS!
1033 int radeonTransformTrigScale(struct radeon_compiler* c,
1034 struct rc_instruction* inst,
1037 static const float RCP_2PI = 0.15915494309189535;
1039 unsigned int constant;
1040 unsigned int constant_swizzle;
1042 if (inst->U.I.Opcode != RC_OPCODE_COS &&
1043 inst->U.I.Opcode != RC_OPCODE_SIN &&
1044 inst->U.I.Opcode != RC_OPCODE_SCS)
1047 temp = rc_find_free_temporary(c);
1048 constant = rc_constants_add_immediate_scalar(&c->Program.Constants, RCP_2PI, &constant_swizzle);
1050 emit2(c, inst->Prev, RC_OPCODE_MUL, 0, dstregtmpmask(temp, RC_MASK_W),
1051 swizzle_xxxx(inst->U.I.SrcReg[0]),
1052 srcregswz(RC_FILE_CONSTANT, constant, constant_swizzle));
1053 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(temp, RC_MASK_W),
1054 srcreg(RC_FILE_TEMPORARY, temp));
1056 r300_transform_SIN_COS_SCS(c, inst, temp);
1061 * Transform the trigonometric functions COS, SIN, and SCS
1062 * so that the input to COS and SIN is always in the range [-PI, PI].
1063 * SCS is replaced by one COS and one SIN instruction.
1065 int r300_transform_trig_scale_vertex(struct radeon_compiler *c,
1066 struct rc_instruction *inst,
1069 static const float cons[4] = {0.15915494309189535, 0.5, 6.28318530717959, -3.14159265358979};
1071 unsigned int constant;
1073 if (inst->U.I.Opcode != RC_OPCODE_COS &&
1074 inst->U.I.Opcode != RC_OPCODE_SIN &&
1075 inst->U.I.Opcode != RC_OPCODE_SCS)
1078 /* Repeat x in the range [-PI, PI]:
1080 * repeat(x) = frac(x / 2PI + 0.5) * 2PI - PI
1083 temp = rc_find_free_temporary(c);
1084 constant = rc_constants_add_immediate_vec4(&c->Program.Constants, cons);
1086 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(temp, RC_MASK_W),
1087 swizzle_xxxx(inst->U.I.SrcReg[0]),
1088 srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_XXXX),
1089 srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_YYYY));
1090 emit1(c, inst->Prev, RC_OPCODE_FRC, 0, dstregtmpmask(temp, RC_MASK_W),
1091 srcreg(RC_FILE_TEMPORARY, temp));
1092 emit3(c, inst->Prev, RC_OPCODE_MAD, 0, dstregtmpmask(temp, RC_MASK_W),
1093 srcreg(RC_FILE_TEMPORARY, temp),
1094 srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_ZZZZ),
1095 srcregswz(RC_FILE_CONSTANT, constant, RC_SWIZZLE_WWWW));
1097 r300_transform_SIN_COS_SCS(c, inst, temp);
1102 * Rewrite DDX/DDY instructions to properly work with r5xx shaders.
1103 * The r5xx MDH/MDV instruction provides per-quad partial derivatives.
1104 * It takes the form A*B+C. A and C are set by setting src0. B should be -1.
1106 * @warning This explicitly changes the form of DDX and DDY!
1109 int radeonTransformDeriv(struct radeon_compiler* c,
1110 struct rc_instruction* inst,
1113 if (inst->U.I.Opcode != RC_OPCODE_DDX && inst->U.I.Opcode != RC_OPCODE_DDY)
1116 inst->U.I.SrcReg[1].Swizzle = RC_SWIZZLE_1111;
1117 inst->U.I.SrcReg[1].Negate = RC_MASK_XYZW;
1124 * KILP - > KIL -abs(Temp[0].x)
1127 * This needs to be done in its own pass, because it modifies the instructions
1128 * before and after KILP.
1130 void rc_transform_KILP(struct radeon_compiler * c, void *user)
1132 struct rc_instruction * inst;
1133 for (inst = c->Program.Instructions.Next;
1134 inst != &c->Program.Instructions; inst = inst->Next) {
1136 if (inst->U.I.Opcode != RC_OPCODE_KILP)
1139 inst->U.I.Opcode = RC_OPCODE_KIL;
1141 if (inst->Prev->U.I.Opcode != RC_OPCODE_IF
1142 || inst->Next->U.I.Opcode != RC_OPCODE_ENDIF) {
1143 inst->U.I.SrcReg[0] = negate(builtin_one);
1146 inst->U.I.SrcReg[0] =
1147 negate(absolute(inst->Prev->U.I.SrcReg[0]));
1149 rc_remove_instruction(inst->Prev);
1151 rc_remove_instruction(inst->Next);