summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r300/compiler
diff options
context:
space:
mode:
authorTom Stellard <[email protected]>2011-06-15 08:00:13 -0700
committerTom Stellard <[email protected]>2011-09-16 17:19:56 -0700
commit1e5aaaa138d87a3e3bc53f6e4c18b1842b752dea (patch)
tree306a48b89719c85ca5eb97465e4e8c0ceccf3a1f /src/gallium/drivers/r300/compiler
parent96620d2275894d1e021d403c0e40007c61269563 (diff)
r300/compiler: Move some helper functions to radeon_compiler_util.c
Diffstat (limited to 'src/gallium/drivers/r300/compiler')
-rw-r--r--src/gallium/drivers/r300/compiler/radeon_compiler_util.c35
-rw-r--r--src/gallium/drivers/r300/compiler/radeon_compiler_util.h13
-rw-r--r--src/gallium/drivers/r300/compiler/radeon_emulate_loops.c53
3 files changed, 68 insertions, 33 deletions
diff --git a/src/gallium/drivers/r300/compiler/radeon_compiler_util.c b/src/gallium/drivers/r300/compiler/radeon_compiler_util.c
index 2742721f800..33dbe0e86e9 100644
--- a/src/gallium/drivers/r300/compiler/radeon_compiler_util.c
+++ b/src/gallium/drivers/r300/compiler/radeon_compiler_util.c
@@ -699,3 +699,38 @@ unsigned int rc_make_conversion_swizzle(
}
return conversion_swizzle;
}
+
+/**
+ * @return 1 if the register contains an immediate value, 0 otherwise.
+ */
+unsigned int rc_src_reg_is_immediate(
+ struct radeon_compiler * c,
+ unsigned int file,
+ unsigned int index)
+{
+ return file == RC_FILE_CONSTANT &&
+ c->Program.Constants.Constants[index].Type == RC_CONSTANT_IMMEDIATE;
+}
+
+/**
+ * @return The immediate value in the specified register.
+ */
+float rc_get_constant_value(
+ struct radeon_compiler * c,
+ unsigned int index,
+ unsigned int swizzle,
+ unsigned int negate,
+ unsigned int chan)
+{
+ float base = 1.0f;
+ int swz = GET_SWZ(swizzle, chan);
+ if(swz >= 4 || index >= c->Program.Constants.Count ){
+ rc_error(c, "get_constant_value: Can't find a value.\n");
+ return 0.0f;
+ }
+ if(GET_BIT(negate, chan)){
+ base = -1.0f;
+ }
+ return base *
+ c->Program.Constants.Constants[index].u.Immediate[swz];
+}
diff --git a/src/gallium/drivers/r300/compiler/radeon_compiler_util.h b/src/gallium/drivers/r300/compiler/radeon_compiler_util.h
index 3730aa888c0..58bdb3c684b 100644
--- a/src/gallium/drivers/r300/compiler/radeon_compiler_util.h
+++ b/src/gallium/drivers/r300/compiler/radeon_compiler_util.h
@@ -86,4 +86,17 @@ unsigned int rc_make_conversion_swizzle(
unsigned int old_mask,
unsigned int new_mask);
+unsigned int rc_src_reg_is_immediate(
+ struct radeon_compiler * c,
+ unsigned int file,
+ unsigned int index);
+
+float rc_get_constant_value(
+ struct radeon_compiler * c,
+ unsigned int index,
+ unsigned int swizzle,
+ unsigned int negate,
+ unsigned int chan);
+
+
#endif /* RADEON_PROGRAM_UTIL_H */
diff --git a/src/gallium/drivers/r300/compiler/radeon_emulate_loops.c b/src/gallium/drivers/r300/compiler/radeon_emulate_loops.c
index 8c46db08093..91ed9d2615d 100644
--- a/src/gallium/drivers/r300/compiler/radeon_emulate_loops.c
+++ b/src/gallium/drivers/r300/compiler/radeon_emulate_loops.c
@@ -32,6 +32,7 @@
#include "radeon_emulate_loops.h"
#include "radeon_compiler.h"
+#include "radeon_compiler_util.h"
#include "radeon_dataflow.h"
#define VERBOSE 0
@@ -54,30 +55,6 @@ struct count_inst {
unsigned BranchDepth;
};
-static float get_constant_value(struct radeon_compiler * c,
- struct rc_src_register * src,
- int chan)
-{
- float base = 1.0f;
- int swz = GET_SWZ(src->Swizzle, chan);
- if(swz >= 4 || src->Index >= c->Program.Constants.Count ){
- rc_error(c, "get_constant_value: Can't find a value.\n");
- return 0.0f;
- }
- if(GET_BIT(src->Negate, chan)){
- base = -1.0f;
- }
- return base *
- c->Program.Constants.Constants[src->Index].u.Immediate[swz];
-}
-
-static int src_reg_is_immediate(struct rc_src_register * src,
- struct radeon_compiler * c)
-{
- return src->File == RC_FILE_CONSTANT &&
- c->Program.Constants.Constants[src->Index].Type==RC_CONSTANT_IMMEDIATE;
-}
-
static unsigned int loop_max_possible_iterations(struct radeon_compiler *c,
struct loop_info * loop)
{
@@ -119,12 +96,16 @@ static void update_const_value(void * data, struct rc_instruction * inst,
}
switch(inst->U.I.Opcode){
case RC_OPCODE_MOV:
- if(!src_reg_is_immediate(&inst->U.I.SrcReg[0], value->C)){
+ if(!rc_src_reg_is_immediate(value->C, inst->U.I.SrcReg[0].File,
+ inst->U.I.SrcReg[0].Index)){
return;
}
value->HasValue = 1;
value->Value =
- get_constant_value(value->C, &inst->U.I.SrcReg[0], 0);
+ rc_get_constant_value(value->C,
+ inst->U.I.SrcReg[0].Index,
+ inst->U.I.SrcReg[0].Swizzle,
+ inst->U.I.SrcReg[0].Negate, 0);
break;
}
}
@@ -169,10 +150,13 @@ static void get_incr_amount(void * data, struct rc_instruction * inst,
count_inst->Unknown = 1;
return;
}
- if(src_reg_is_immediate(&inst->U.I.SrcReg[amnt_src_index],
- count_inst->C)){
- amount = get_constant_value(count_inst->C,
- &inst->U.I.SrcReg[amnt_src_index], 0);
+ if(rc_src_reg_is_immediate(count_inst->C,
+ inst->U.I.SrcReg[amnt_src_index].File,
+ inst->U.I.SrcReg[amnt_src_index].Index)){
+ amount = rc_get_constant_value(count_inst->C,
+ inst->U.I.SrcReg[amnt_src_index].Index,
+ inst->U.I.SrcReg[amnt_src_index].Swizzle,
+ inst->U.I.SrcReg[amnt_src_index].Negate, 0);
}
else{
count_inst->Unknown = 1 ;
@@ -212,11 +196,13 @@ static int try_unroll_loop(struct radeon_compiler * c, struct loop_info * loop)
/* Find the counter and the upper limit */
- if(src_reg_is_immediate(&loop->Cond->U.I.SrcReg[0], c)){
+ if(rc_src_reg_is_immediate(c, loop->Cond->U.I.SrcReg[0].File,
+ loop->Cond->U.I.SrcReg[0].Index)){
limit = &loop->Cond->U.I.SrcReg[0];
counter = &loop->Cond->U.I.SrcReg[1];
}
- else if(src_reg_is_immediate(&loop->Cond->U.I.SrcReg[1], c)){
+ else if(rc_src_reg_is_immediate(c, loop->Cond->U.I.SrcReg[1].File,
+ loop->Cond->U.I.SrcReg[1].Index)){
limit = &loop->Cond->U.I.SrcReg[1];
counter = &loop->Cond->U.I.SrcReg[0];
}
@@ -290,7 +276,8 @@ static int try_unroll_loop(struct radeon_compiler * c, struct loop_info * loop)
/* Calculate the number of iterations of this loop. Keeping this
* simple, since we only support increment and decrement loops.
*/
- limit_value = get_constant_value(c, limit, 0);
+ limit_value = rc_get_constant_value(c, limit->Index, limit->Swizzle,
+ limit->Negate, 0);
DBG("Limit is %f.\n", limit_value);
/* The iteration calculations are opposite of what you would expect.
* In a normal loop, if the condition is met, then loop continues, but