summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/gallivm
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/gallivm')
-rw-r--r--src/gallium/auxiliary/gallivm/gallivm.cpp6
-rw-r--r--src/gallium/auxiliary/gallivm/instructionssoa.cpp35
-rw-r--r--src/gallium/auxiliary/gallivm/instructionssoa.h3
-rw-r--r--src/gallium/auxiliary/gallivm/soabuiltins.c38
-rw-r--r--src/gallium/auxiliary/gallivm/tgsitollvm.cpp2
5 files changed, 67 insertions, 17 deletions
diff --git a/src/gallium/auxiliary/gallivm/gallivm.cpp b/src/gallium/auxiliary/gallivm/gallivm.cpp
index 48a3b18cdc..77900e342b 100644
--- a/src/gallium/auxiliary/gallivm/gallivm.cpp
+++ b/src/gallium/auxiliary/gallivm/gallivm.cpp
@@ -303,11 +303,11 @@ struct gallivm_prog * gallivm_ir_compile(struct gallivm_ir *ir)
{
struct gallivm_prog *prog =
(struct gallivm_prog *)calloc(1, sizeof(struct gallivm_prog));
-
+
std::cout << "Before optimizations:"<<std::endl;
ir->module->dump();
std::cout<<"-------------------------------"<<std::endl;
-
+
PassManager veri;
veri.add(createVerifierPass());
veri.run(*ir->module);
@@ -315,7 +315,7 @@ struct gallivm_prog * gallivm_ir_compile(struct gallivm_ir *ir)
prog->num_consts = ir->num_consts;
memcpy(prog->interpolators, ir->interpolators, sizeof(prog->interpolators));
prog->num_interp = ir->num_interp;
-
+
/* Run optimization passes over it */
PassManager passes;
passes.add(new TargetData(mod));
diff --git a/src/gallium/auxiliary/gallivm/instructionssoa.cpp b/src/gallium/auxiliary/gallivm/instructionssoa.cpp
index 17e876e32d..4520559ba2 100644
--- a/src/gallium/auxiliary/gallivm/instructionssoa.cpp
+++ b/src/gallium/auxiliary/gallivm/instructionssoa.cpp
@@ -173,6 +173,7 @@ std::vector<llvm::Value*> InstructionsSoa::extractVector(llvm::Value *vector)
void InstructionsSoa::createFunctionMap()
{
+ m_functionsMap[TGSI_OPCODE_ABS] = "abs";
m_functionsMap[TGSI_OPCODE_DP3] = "dp3";
m_functionsMap[TGSI_OPCODE_DP4] = "dp4";
m_functionsMap[TGSI_OPCODE_POWER] = "pow";
@@ -180,9 +181,16 @@ void InstructionsSoa::createFunctionMap()
void InstructionsSoa::createDependencies()
{
- std::vector<std::string> powDeps(1);
- powDeps[0] = "powf";
- m_builtinDependencies["pow"] = powDeps;
+ {
+ std::vector<std::string> powDeps(1);
+ powDeps[0] = "powf";
+ m_builtinDependencies["pow"] = powDeps;
+ }
+ {
+ std::vector<std::string> absDeps(1);
+ absDeps[0] = "fabsf";
+ m_builtinDependencies["abs"] = absDeps;
+ }
}
llvm::Function * InstructionsSoa::function(int op)
@@ -226,6 +234,13 @@ void InstructionsSoa::createBuiltins()
createDependencies();
}
+
+std::vector<llvm::Value*> InstructionsSoa::abs(const std::vector<llvm::Value*> in1)
+{
+ llvm::Function *func = function(TGSI_OPCODE_ABS);
+ return callBuiltin(func, in1);
+}
+
std::vector<llvm::Value*> InstructionsSoa::dp3(const std::vector<llvm::Value*> in1,
const std::vector<llvm::Value*> in2)
{
@@ -418,3 +433,17 @@ void InstructionsSoa::injectFunction(llvm::Function *originalFunc, int op)
m_functions[op] = func;
}
}
+
+std::vector<llvm::Value*> InstructionsSoa::sub(const std::vector<llvm::Value*> in1,
+ const std::vector<llvm::Value*> in2)
+{
+ std::vector<llvm::Value*> res(4);
+
+ res[0] = m_builder.CreateSub(in1[0], in2[0], name("subx"));
+ res[1] = m_builder.CreateSub(in1[1], in2[1], name("suby"));
+ res[2] = m_builder.CreateSub(in1[2], in2[2], name("subz"));
+ res[3] = m_builder.CreateSub(in1[3], in2[3], name("subw"));
+
+ return res;
+}
+
diff --git a/src/gallium/auxiliary/gallivm/instructionssoa.h b/src/gallium/auxiliary/gallivm/instructionssoa.h
index 060ee72f2e..02e5fab51f 100644
--- a/src/gallium/auxiliary/gallivm/instructionssoa.h
+++ b/src/gallium/auxiliary/gallivm/instructionssoa.h
@@ -48,6 +48,7 @@ public:
InstructionsSoa(llvm::Module *mod, llvm::Function *func,
llvm::BasicBlock *block, StorageSoa *storage);
+ std::vector<llvm::Value*> abs(const std::vector<llvm::Value*> in1);
std::vector<llvm::Value*> arl(const std::vector<llvm::Value*> in);
std::vector<llvm::Value*> add(const std::vector<llvm::Value*> in1,
const std::vector<llvm::Value*> in2);
@@ -62,6 +63,8 @@ public:
const std::vector<llvm::Value*> in2);
std::vector<llvm::Value*> pow(const std::vector<llvm::Value*> in1,
const std::vector<llvm::Value*> in2);
+ std::vector<llvm::Value*> sub(const std::vector<llvm::Value*> in1,
+ const std::vector<llvm::Value*> in2);
void end();
std::vector<llvm::Value*> extractVector(llvm::Value *vector);
diff --git a/src/gallium/auxiliary/gallivm/soabuiltins.c b/src/gallium/auxiliary/gallivm/soabuiltins.c
index 40addebd8c..f04e4c974d 100644
--- a/src/gallium/auxiliary/gallivm/soabuiltins.c
+++ b/src/gallium/auxiliary/gallivm/soabuiltins.c
@@ -33,6 +33,33 @@
*/
typedef __attribute__(( ext_vector_type(4) )) float float4;
+
+extern float fabsf(float val);
+
+void abs(float4 *res,
+ float4 tmp0x, float4 tmp0y, float4 tmp0z, float4 tmp0w)
+{
+ res[0].x = fabsf(tmp0x.x);
+ res[0].y = fabsf(tmp0x.y);
+ res[0].z = fabsf(tmp0x.z);
+ res[0].w = fabsf(tmp0x.w);
+
+ res[1].x = fabsf(tmp0y.x);
+ res[1].y = fabsf(tmp0y.y);
+ res[1].z = fabsf(tmp0y.z);
+ res[1].w = fabsf(tmp0y.w);
+
+ res[2].x = fabsf(tmp0z.x);
+ res[2].y = fabsf(tmp0z.y);
+ res[2].z = fabsf(tmp0z.z);
+ res[2].w = fabsf(tmp0z.w);
+
+ res[3].x = fabsf(tmp0w.x);
+ res[3].y = fabsf(tmp0w.y);
+ res[3].z = fabsf(tmp0w.z);
+ res[3].w = fabsf(tmp0w.w);
+}
+
void dp3(float4 *res,
float4 tmp0x, float4 tmp0y, float4 tmp0z, float4 tmp0w,
float4 tmp1x, float4 tmp1y, float4 tmp1z, float4 tmp1w)
@@ -77,14 +104,3 @@ void pow(float4 *res,
res[2] = p;
res[3] = p;
}
-
-#if 0
-void yo(float4 *out, float4 *in)
-{
- float4 res[4];
-
- dp3(res, in[0], in[1], in[2], in[3],
- in[4], in[5], in[6], in[7]);
- out[1] = res[1];
-}
-#endif
diff --git a/src/gallium/auxiliary/gallivm/tgsitollvm.cpp b/src/gallium/auxiliary/gallivm/tgsitollvm.cpp
index ab8c851f14..5465d3a95e 100644
--- a/src/gallium/auxiliary/gallivm/tgsitollvm.cpp
+++ b/src/gallium/auxiliary/gallivm/tgsitollvm.cpp
@@ -740,6 +740,7 @@ translate_instructionir(llvm::Module *module,
}
break;
case TGSI_OPCODE_SUB: {
+ out = instr->sub(inputs[0], inputs[1]);
}
break;
case TGSI_OPCODE_LERP: {
@@ -781,6 +782,7 @@ translate_instructionir(llvm::Module *module,
case TGSI_OPCODE_MULTIPLYMATRIX:
break;
case TGSI_OPCODE_ABS: {
+ out = instr->abs(inputs[0]);
}
break;
case TGSI_OPCODE_RCC: