r300/compiler: Move some helper functions to radeon_compiler_util.c
[mesa.git] / src / gallium / drivers / r300 / compiler / radeon_compiler_util.c
1 /*
2 * Copyright 2010 Tom Stellard <tstellar@gmail.com>
3 *
4 * All Rights Reserved.
5 *
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:
13 *
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.
17 *
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.
25 *
26 */
27
28 /**
29 * \file
30 */
31
32 #include "radeon_compiler_util.h"
33
34 #include "radeon_compiler.h"
35 #include "radeon_dataflow.h"
36 /**
37 */
38 unsigned int rc_swizzle_to_writemask(unsigned int swz)
39 {
40 unsigned int mask = 0;
41 unsigned int i;
42
43 for(i = 0; i < 4; i++) {
44 mask |= 1 << GET_SWZ(swz, i);
45 }
46 mask &= RC_MASK_XYZW;
47
48 return mask;
49 }
50
51 rc_swizzle get_swz(unsigned int swz, rc_swizzle idx)
52 {
53 if (idx & 0x4)
54 return idx;
55 return GET_SWZ(swz, idx);
56 }
57
58 /**
59 * The purpose of this function is to standardize the number channels used by
60 * swizzles. All swizzles regardless of what instruction they are a part of
61 * should have 4 channels initialized with values.
62 * @param channels The number of channels in initial_value that have a
63 * meaningful value.
64 * @return An initialized swizzle that has all of the unused channels set to
65 * RC_SWIZZLE_UNUSED.
66 */
67 unsigned int rc_init_swizzle(unsigned int initial_value, unsigned int channels)
68 {
69 unsigned int i;
70 for (i = channels; i < 4; i++) {
71 SET_SWZ(initial_value, i, RC_SWIZZLE_UNUSED);
72 }
73 return initial_value;
74 }
75
76 unsigned int combine_swizzles4(unsigned int src,
77 rc_swizzle swz_x, rc_swizzle swz_y, rc_swizzle swz_z, rc_swizzle swz_w)
78 {
79 unsigned int ret = 0;
80
81 ret |= get_swz(src, swz_x);
82 ret |= get_swz(src, swz_y) << 3;
83 ret |= get_swz(src, swz_z) << 6;
84 ret |= get_swz(src, swz_w) << 9;
85
86 return ret;
87 }
88
89 unsigned int combine_swizzles(unsigned int src, unsigned int swz)
90 {
91 unsigned int ret = 0;
92
93 ret |= get_swz(src, GET_SWZ(swz, RC_SWIZZLE_X));
94 ret |= get_swz(src, GET_SWZ(swz, RC_SWIZZLE_Y)) << 3;
95 ret |= get_swz(src, GET_SWZ(swz, RC_SWIZZLE_Z)) << 6;
96 ret |= get_swz(src, GET_SWZ(swz, RC_SWIZZLE_W)) << 9;
97
98 return ret;
99 }
100
101 /**
102 * @param mask Must be either RC_MASK_X, RC_MASK_Y, RC_MASK_Z, or RC_MASK_W
103 */
104 rc_swizzle rc_mask_to_swizzle(unsigned int mask)
105 {
106 switch (mask) {
107 case RC_MASK_X: return RC_SWIZZLE_X;
108 case RC_MASK_Y: return RC_SWIZZLE_Y;
109 case RC_MASK_Z: return RC_SWIZZLE_Z;
110 case RC_MASK_W: return RC_SWIZZLE_W;
111 }
112 return RC_SWIZZLE_UNUSED;
113 }
114
115 /* Reorder mask bits according to swizzle. */
116 unsigned swizzle_mask(unsigned swizzle, unsigned mask)
117 {
118 unsigned ret = 0;
119 for (unsigned chan = 0; chan < 4; ++chan) {
120 unsigned swz = GET_SWZ(swizzle, chan);
121 if (swz < 4)
122 ret |= GET_BIT(mask, swz) << chan;
123 }
124 return ret;
125 }
126
127 static unsigned int srcs_need_rewrite(const struct rc_opcode_info * info)
128 {
129 if (info->HasTexture) {
130 return 0;
131 }
132 switch (info->Opcode) {
133 case RC_OPCODE_DP2:
134 case RC_OPCODE_DP3:
135 case RC_OPCODE_DP4:
136 case RC_OPCODE_DDX:
137 case RC_OPCODE_DDY:
138 return 0;
139 default:
140 return 1;
141 }
142 }
143
144 /**
145 * @return A swizzle the results from converting old_swizzle using
146 * conversion_swizzle
147 */
148 unsigned int rc_adjust_channels(
149 unsigned int old_swizzle,
150 unsigned int conversion_swizzle)
151 {
152 unsigned int i;
153 unsigned int new_swizzle = rc_init_swizzle(RC_SWIZZLE_UNUSED, 0);
154 for (i = 0; i < 4; i++) {
155 unsigned int new_chan = get_swz(conversion_swizzle, i);
156 if (new_chan == RC_SWIZZLE_UNUSED) {
157 continue;
158 }
159 SET_SWZ(new_swizzle, new_chan, GET_SWZ(old_swizzle, i));
160 }
161 return new_swizzle;
162 }
163
164 static unsigned int rewrite_writemask(
165 unsigned int old_mask,
166 unsigned int conversion_swizzle)
167 {
168 unsigned int new_mask = 0;
169 unsigned int i;
170
171 for (i = 0; i < 4; i++) {
172 if (!GET_BIT(old_mask, i)
173 || GET_SWZ(conversion_swizzle, i) == RC_SWIZZLE_UNUSED) {
174 continue;
175 }
176 new_mask |= (1 << GET_SWZ(conversion_swizzle, i));
177 }
178
179 return new_mask;
180 }
181
182 /**
183 * This function rewrites the writemask of sub and adjusts the swizzles
184 * of all its source registers based on the conversion_swizzle.
185 * conversion_swizzle represents a mapping of the old writemask to the
186 * new writemask. For a detailed description of how conversion swizzles
187 * work see rc_rewrite_swizzle().
188 */
189 void rc_pair_rewrite_writemask(
190 struct rc_pair_sub_instruction * sub,
191 unsigned int conversion_swizzle)
192 {
193 const struct rc_opcode_info * info = rc_get_opcode_info(sub->Opcode);
194 unsigned int i;
195
196 sub->WriteMask = rewrite_writemask(sub->WriteMask, conversion_swizzle);
197
198 if (!srcs_need_rewrite(info)) {
199 return ;
200 }
201
202 for (i = 0; i < info->NumSrcRegs; i++) {
203 sub->Arg[i].Swizzle =
204 rc_adjust_channels(sub->Arg[i].Swizzle,
205 conversion_swizzle);
206 }
207 }
208
209 static void normal_rewrite_writemask_cb(
210 void * userdata,
211 struct rc_instruction * inst,
212 struct rc_src_register * src)
213 {
214 unsigned int * new_mask = (unsigned int *)userdata;
215 src->Swizzle = rc_adjust_channels(src->Swizzle, *new_mask);
216 }
217
218 /**
219 * This function is the same as rc_pair_rewrite_writemask() except it
220 * operates on normal instructions.
221 */
222 void rc_normal_rewrite_writemask(
223 struct rc_instruction * inst,
224 unsigned int conversion_swizzle)
225 {
226 unsigned int new_mask;
227 struct rc_sub_instruction * sub = &inst->U.I;
228 const struct rc_opcode_info * info = rc_get_opcode_info(sub->Opcode);
229 sub->DstReg.WriteMask =
230 rewrite_writemask(sub->DstReg.WriteMask, conversion_swizzle);
231
232 if (info->HasTexture) {
233 unsigned int i;
234 assert(sub->TexSwizzle == RC_SWIZZLE_XYZW);
235 for (i = 0; i < 4; i++) {
236 unsigned int swz = GET_SWZ(conversion_swizzle, i);
237 if (swz > 3)
238 continue;
239 SET_SWZ(sub->TexSwizzle, swz, i);
240 }
241 }
242
243 if (!srcs_need_rewrite(info)) {
244 return;
245 }
246
247 new_mask = sub->DstReg.WriteMask;
248 rc_for_all_reads_src(inst, normal_rewrite_writemask_cb, &new_mask);
249 }
250
251 /**
252 * This function replaces each value 'swz' in swizzle with the value of
253 * GET_SWZ(conversion_swizzle, swz). So, if you want to change all the X's
254 * in swizzle to Y, then conversion_swizzle should be Y___ (0xff9). If you want
255 * to change all the Y's in swizzle to X, then conversion_swizzle should be
256 * _X__ (0xfc7). If you want to change the Y's to X and the X's to Y, then
257 * conversion swizzle should be YX__ (0xfc1).
258 * @param swizzle The swizzle to change
259 * @param conversion_swizzle Describes the conversion to perform on the swizzle
260 * @return A converted swizzle
261 */
262 unsigned int rc_rewrite_swizzle(
263 unsigned int swizzle,
264 unsigned int conversion_swizzle)
265 {
266 unsigned int chan;
267 unsigned int out_swizzle = swizzle;
268
269 for (chan = 0; chan < 4; chan++) {
270 unsigned int swz = GET_SWZ(swizzle, chan);
271 unsigned int new_swz;
272 if (swz > 3) {
273 SET_SWZ(out_swizzle, chan, swz);
274 } else {
275 new_swz = GET_SWZ(conversion_swizzle, swz);
276 if (new_swz != RC_SWIZZLE_UNUSED) {
277 SET_SWZ(out_swizzle, chan, new_swz);
278 } else {
279 SET_SWZ(out_swizzle, chan, swz);
280 }
281 }
282 }
283 return out_swizzle;
284 }
285
286 /**
287 * Left multiplication of a register with a swizzle
288 */
289 struct rc_src_register lmul_swizzle(unsigned int swizzle, struct rc_src_register srcreg)
290 {
291 struct rc_src_register tmp = srcreg;
292 int i;
293 tmp.Swizzle = 0;
294 tmp.Negate = 0;
295 for(i = 0; i < 4; ++i) {
296 rc_swizzle swz = GET_SWZ(swizzle, i);
297 if (swz < 4) {
298 tmp.Swizzle |= GET_SWZ(srcreg.Swizzle, swz) << (i*3);
299 tmp.Negate |= GET_BIT(srcreg.Negate, swz) << i;
300 } else {
301 tmp.Swizzle |= swz << (i*3);
302 }
303 }
304 return tmp;
305 }
306
307 void reset_srcreg(struct rc_src_register* reg)
308 {
309 memset(reg, 0, sizeof(struct rc_src_register));
310 reg->Swizzle = RC_SWIZZLE_XYZW;
311 }
312
313 unsigned int rc_src_reads_dst_mask(
314 rc_register_file src_file,
315 unsigned int src_idx,
316 unsigned int src_swz,
317 rc_register_file dst_file,
318 unsigned int dst_idx,
319 unsigned int dst_mask)
320 {
321 if (src_file != dst_file || src_idx != dst_idx) {
322 return RC_MASK_NONE;
323 }
324 return dst_mask & rc_swizzle_to_writemask(src_swz);
325 }
326
327 /**
328 * @return A bit mask specifying whether this swizzle will select from an RGB
329 * source, an Alpha source, or both.
330 */
331 unsigned int rc_source_type_swz(unsigned int swizzle)
332 {
333 unsigned int chan;
334 unsigned int swz = RC_SWIZZLE_UNUSED;
335 unsigned int ret = RC_SOURCE_NONE;
336
337 for(chan = 0; chan < 4; chan++) {
338 swz = GET_SWZ(swizzle, chan);
339 if (swz == RC_SWIZZLE_W) {
340 ret |= RC_SOURCE_ALPHA;
341 } else if (swz == RC_SWIZZLE_X || swz == RC_SWIZZLE_Y
342 || swz == RC_SWIZZLE_Z) {
343 ret |= RC_SOURCE_RGB;
344 }
345 }
346 return ret;
347 }
348
349 unsigned int rc_source_type_mask(unsigned int mask)
350 {
351 unsigned int ret = RC_SOURCE_NONE;
352
353 if (mask & RC_MASK_XYZ)
354 ret |= RC_SOURCE_RGB;
355
356 if (mask & RC_MASK_W)
357 ret |= RC_SOURCE_ALPHA;
358
359 return ret;
360 }
361
362 struct src_select {
363 rc_register_file File;
364 int Index;
365 unsigned int SrcType;
366 };
367
368 struct can_use_presub_data {
369 struct src_select Selects[5];
370 unsigned int SelectCount;
371 const struct rc_src_register * ReplaceReg;
372 unsigned int ReplaceRemoved;
373 };
374
375 static void can_use_presub_data_add_select(
376 struct can_use_presub_data * data,
377 rc_register_file file,
378 unsigned int index,
379 unsigned int src_type)
380 {
381 struct src_select * select;
382
383 select = &data->Selects[data->SelectCount++];
384 select->File = file;
385 select->Index = index;
386 select->SrcType = src_type;
387 }
388
389 /**
390 * This callback function counts the number of sources in inst that are
391 * different from the sources in can_use_presub_data->RemoveSrcs.
392 */
393 static void can_use_presub_read_cb(
394 void * userdata,
395 struct rc_instruction * inst,
396 struct rc_src_register * src)
397 {
398 struct can_use_presub_data * d = userdata;
399
400 if (!d->ReplaceRemoved && src == d->ReplaceReg) {
401 d->ReplaceRemoved = 1;
402 return;
403 }
404
405 if (src->File == RC_FILE_NONE)
406 return;
407
408 can_use_presub_data_add_select(d, src->File, src->Index,
409 rc_source_type_swz(src->Swizzle));
410 }
411
412 unsigned int rc_inst_can_use_presub(
413 struct rc_instruction * inst,
414 rc_presubtract_op presub_op,
415 unsigned int presub_writemask,
416 const struct rc_src_register * replace_reg,
417 const struct rc_src_register * presub_src0,
418 const struct rc_src_register * presub_src1)
419 {
420 struct can_use_presub_data d;
421 unsigned int num_presub_srcs;
422 unsigned int i;
423 const struct rc_opcode_info * info =
424 rc_get_opcode_info(inst->U.I.Opcode);
425 int rgb_count = 0, alpha_count = 0;
426 unsigned int src_type0, src_type1;
427
428 if (presub_op == RC_PRESUB_NONE) {
429 return 1;
430 }
431
432 if (info->HasTexture) {
433 return 0;
434 }
435
436 /* We can't use more than one presubtract value in an
437 * instruction, unless the two prsubtract operations
438 * are the same and read from the same registers.
439 * XXX For now we will limit instructions to only one presubtract
440 * value.*/
441 if (inst->U.I.PreSub.Opcode != RC_PRESUB_NONE) {
442 return 0;
443 }
444
445 memset(&d, 0, sizeof(d));
446 d.ReplaceReg = replace_reg;
447
448 rc_for_all_reads_src(inst, can_use_presub_read_cb, &d);
449
450 num_presub_srcs = rc_presubtract_src_reg_count(presub_op);
451
452 src_type0 = rc_source_type_swz(presub_src0->Swizzle);
453 can_use_presub_data_add_select(&d,
454 presub_src0->File,
455 presub_src0->Index,
456 src_type0);
457
458 if (num_presub_srcs > 1) {
459 src_type1 = rc_source_type_swz(presub_src1->Swizzle);
460 can_use_presub_data_add_select(&d,
461 presub_src1->File,
462 presub_src1->Index,
463 src_type1);
464
465 /* Even if both of the presub sources read from the same
466 * register, we still need to use 2 different source selects
467 * for them, so we need to increment the count to compensate.
468 */
469 if (presub_src0->File == presub_src1->File
470 && presub_src0->Index == presub_src1->Index) {
471 if (src_type0 & src_type1 & RC_SOURCE_RGB) {
472 rgb_count++;
473 }
474 if (src_type0 & src_type1 & RC_SOURCE_ALPHA) {
475 alpha_count++;
476 }
477 }
478 }
479
480 /* Count the number of source selects for Alpha and RGB. If we
481 * encounter two of the same source selects then we can ignore the
482 * first one. */
483 for (i = 0; i < d.SelectCount; i++) {
484 unsigned int j;
485 unsigned int src_type = d.Selects[i].SrcType;
486 for (j = i + 1; j < d.SelectCount; j++) {
487 if (d.Selects[i].File == d.Selects[j].File
488 && d.Selects[i].Index == d.Selects[j].Index) {
489 src_type &= ~d.Selects[j].SrcType;
490 }
491 }
492 if (src_type & RC_SOURCE_RGB) {
493 rgb_count++;
494 }
495
496 if (src_type & RC_SOURCE_ALPHA) {
497 alpha_count++;
498 }
499 }
500
501 if (rgb_count > 3 || alpha_count > 3) {
502 return 0;
503 }
504
505 return 1;
506 }
507
508 struct max_data {
509 unsigned int Max;
510 unsigned int HasFileType;
511 rc_register_file File;
512 };
513
514 static void max_callback(
515 void * userdata,
516 struct rc_instruction * inst,
517 rc_register_file file,
518 unsigned int index,
519 unsigned int mask)
520 {
521 struct max_data * d = (struct max_data*)userdata;
522 if (file == d->File && (!d->HasFileType || index > d->Max)) {
523 d->Max = index;
524 d->HasFileType = 1;
525 }
526 }
527
528 /**
529 * @return The maximum index of the specified register file used by the
530 * program.
531 */
532 int rc_get_max_index(
533 struct radeon_compiler * c,
534 rc_register_file file)
535 {
536 struct max_data data;
537 struct rc_instruction * inst;
538 data.Max = 0;
539 data.HasFileType = 0;
540 data.File = file;
541 for (inst = c->Program.Instructions.Next;
542 inst != &c->Program.Instructions;
543 inst = inst->Next) {
544 rc_for_all_reads_mask(inst, max_callback, &data);
545 rc_for_all_writes_mask(inst, max_callback, &data);
546 }
547 if (!data.HasFileType) {
548 return -1;
549 } else {
550 return data.Max;
551 }
552 }
553
554 static unsigned int get_source_readmask(
555 struct rc_pair_sub_instruction * sub,
556 unsigned int source,
557 unsigned int src_type)
558 {
559 unsigned int i;
560 unsigned int readmask = 0;
561 const struct rc_opcode_info * info = rc_get_opcode_info(sub->Opcode);
562
563 for (i = 0; i < info->NumSrcRegs; i++) {
564 if (sub->Arg[i].Source != source
565 || src_type != rc_source_type_swz(sub->Arg[i].Swizzle)) {
566 continue;
567 }
568 readmask |= rc_swizzle_to_writemask(sub->Arg[i].Swizzle);
569 }
570 return readmask;
571 }
572
573 /**
574 * This function attempts to remove a source from a pair instructions.
575 * @param inst
576 * @param src_type RC_SOURCE_RGB, RC_SOURCE_ALPHA, or both bitwise or'd
577 * @param source The index of the source to remove
578 * @param new_readmask A mask representing the components that are read by
579 * the source that is intended to replace the one you are removing. If you
580 * want to remove a source only and not replace it, this parameter should be
581 * zero.
582 * @return 1 if the source was successfully removed, 0 if it was not
583 */
584 unsigned int rc_pair_remove_src(
585 struct rc_instruction * inst,
586 unsigned int src_type,
587 unsigned int source,
588 unsigned int new_readmask)
589 {
590 unsigned int readmask = 0;
591
592 readmask |= get_source_readmask(&inst->U.P.RGB, source, src_type);
593 readmask |= get_source_readmask(&inst->U.P.Alpha, source, src_type);
594
595 if ((new_readmask & readmask) != readmask)
596 return 0;
597
598 if (src_type & RC_SOURCE_RGB) {
599 memset(&inst->U.P.RGB.Src[source], 0,
600 sizeof(struct rc_pair_instruction_source));
601 }
602
603 if (src_type & RC_SOURCE_ALPHA) {
604 memset(&inst->U.P.Alpha.Src[source], 0,
605 sizeof(struct rc_pair_instruction_source));
606 }
607
608 return 1;
609 }
610
611 /**
612 * @return RC_OPCODE_NOOP if inst is not a flow control instruction.
613 * @return The opcode of inst if it is a flow control instruction.
614 */
615 rc_opcode rc_get_flow_control_inst(struct rc_instruction * inst)
616 {
617 const struct rc_opcode_info * info;
618 if (inst->Type == RC_INSTRUCTION_NORMAL) {
619 info = rc_get_opcode_info(inst->U.I.Opcode);
620 } else {
621 info = rc_get_opcode_info(inst->U.P.RGB.Opcode);
622 /*A flow control instruction shouldn't have an alpha
623 * instruction.*/
624 assert(!info->IsFlowControl ||
625 inst->U.P.Alpha.Opcode == RC_OPCODE_NOP);
626 }
627
628 if (info->IsFlowControl)
629 return info->Opcode;
630 else
631 return RC_OPCODE_NOP;
632
633 }
634
635 /**
636 * @return The BGNLOOP instruction that starts the loop ended by endloop.
637 */
638 struct rc_instruction * rc_match_endloop(struct rc_instruction * endloop)
639 {
640 unsigned int endloop_count = 0;
641 struct rc_instruction * inst;
642 for (inst = endloop->Prev; inst != endloop; inst = inst->Prev) {
643 rc_opcode op = rc_get_flow_control_inst(inst);
644 if (op == RC_OPCODE_ENDLOOP) {
645 endloop_count++;
646 } else if (op == RC_OPCODE_BGNLOOP) {
647 if (endloop_count == 0) {
648 return inst;
649 } else {
650 endloop_count--;
651 }
652 }
653 }
654 return NULL;
655 }
656
657 /**
658 * @return The ENDLOOP instruction that ends the loop started by bgnloop.
659 */
660 struct rc_instruction * rc_match_bgnloop(struct rc_instruction * bgnloop)
661 {
662 unsigned int bgnloop_count = 0;
663 struct rc_instruction * inst;
664 for (inst = bgnloop->Next; inst!=bgnloop; inst = inst->Next) {
665 rc_opcode op = rc_get_flow_control_inst(inst);
666 if (op == RC_OPCODE_BGNLOOP) {
667 bgnloop_count++;
668 } else if (op == RC_OPCODE_ENDLOOP) {
669 if (bgnloop_count == 0) {
670 return inst;
671 } else {
672 bgnloop_count--;
673 }
674 }
675 }
676 return NULL;
677 }
678
679 /**
680 * @return A conversion swizzle for converting from old_mask->new_mask
681 */
682 unsigned int rc_make_conversion_swizzle(
683 unsigned int old_mask,
684 unsigned int new_mask)
685 {
686 unsigned int conversion_swizzle = rc_init_swizzle(RC_SWIZZLE_UNUSED, 0);
687 unsigned int old_idx;
688 unsigned int new_idx = 0;
689 for (old_idx = 0; old_idx < 4; old_idx++) {
690 if (!GET_BIT(old_mask, old_idx))
691 continue;
692 for ( ; new_idx < 4; new_idx++) {
693 if (GET_BIT(new_mask, new_idx)) {
694 SET_SWZ(conversion_swizzle, old_idx, new_idx);
695 new_idx++;
696 break;
697 }
698 }
699 }
700 return conversion_swizzle;
701 }
702
703 /**
704 * @return 1 if the register contains an immediate value, 0 otherwise.
705 */
706 unsigned int rc_src_reg_is_immediate(
707 struct radeon_compiler * c,
708 unsigned int file,
709 unsigned int index)
710 {
711 return file == RC_FILE_CONSTANT &&
712 c->Program.Constants.Constants[index].Type == RC_CONSTANT_IMMEDIATE;
713 }
714
715 /**
716 * @return The immediate value in the specified register.
717 */
718 float rc_get_constant_value(
719 struct radeon_compiler * c,
720 unsigned int index,
721 unsigned int swizzle,
722 unsigned int negate,
723 unsigned int chan)
724 {
725 float base = 1.0f;
726 int swz = GET_SWZ(swizzle, chan);
727 if(swz >= 4 || index >= c->Program.Constants.Count ){
728 rc_error(c, "get_constant_value: Can't find a value.\n");
729 return 0.0f;
730 }
731 if(GET_BIT(negate, chan)){
732 base = -1.0f;
733 }
734 return base *
735 c->Program.Constants.Constants[index].u.Immediate[swz];
736 }