{
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);
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));
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";
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)
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)
{
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;
+}
+
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);
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);
*/
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)
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
}
break;
case TGSI_OPCODE_SUB: {
+ out = instr->sub(inputs[0], inputs[1]);
}
break;
case TGSI_OPCODE_LERP: {
case TGSI_OPCODE_MULTIPLYMATRIX:
break;
case TGSI_OPCODE_ABS: {
+ out = instr->abs(inputs[0]);
}
break;
case TGSI_OPCODE_RCC: