From af7a7ab7d71780fd171a22948dda56bc3caae4bc Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 13 Nov 2016 08:57:29 +0100 Subject: [PATCH] Remove use of the llvm.round intrinsic as it apparently doesn't work in some environments --- .../fixedfunction/drawtrianglecodegen.cpp | 19 +++++++++++++------ .../fixedfunction/drawtrianglecodegen.h | 1 + src/r_compiler/ssa/ssa_float.cpp | 3 +++ src/r_compiler/ssa/ssa_float.h | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp index 4819a28cf..013969bbb 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp @@ -39,18 +39,25 @@ void DrawTriangleCodegen::Generate(TriDrawVariant variant, bool truecolor, SSAVa LoopBlockY(variant, truecolor); } +SSAInt DrawTriangleCodegen::FloatTo28_4(SSAFloat v) +{ + // SSAInt(SSAFloat::round(16.0f * v), false); + SSAInt a = SSAInt(v * 32.0f, false); + return (a + (a.ashr(31) | SSAInt(1))).ashr(1); +} + void DrawTriangleCodegen::Setup(TriDrawVariant variant, bool truecolor) { int pixelsize = truecolor ? 4 : 1; // 28.4 fixed-point coordinates - Y1 = SSAInt(SSAFloat::round(16.0f * v1.y), false); - Y2 = SSAInt(SSAFloat::round(16.0f * v2.y), false); - Y3 = SSAInt(SSAFloat::round(16.0f * v3.y), false); + Y1 = FloatTo28_4(v1.y); + Y2 = FloatTo28_4(v2.y); + Y3 = FloatTo28_4(v3.y); - X1 = SSAInt(SSAFloat::round(16.0f * v1.x), false); - X2 = SSAInt(SSAFloat::round(16.0f * v2.x), false); - X3 = SSAInt(SSAFloat::round(16.0f * v3.x), false); + X1 = FloatTo28_4(v1.x); + X2 = FloatTo28_4(v2.x); + X3 = FloatTo28_4(v3.x); // Deltas DX12 = X1 - X2; diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.h b/src/r_compiler/fixedfunction/drawtrianglecodegen.h index 6f9a6c32a..eba1caf4f 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.h +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.h @@ -40,6 +40,7 @@ private: SSATriVertex LoadTriVertex(SSAValue v); void LoadUniforms(SSAValue uniforms); void Setup(TriDrawVariant variant, bool truecolor); + SSAInt FloatTo28_4(SSAFloat v); void LoopBlockY(TriDrawVariant variant, bool truecolor); void LoopBlockX(TriDrawVariant variant, bool truecolor); void LoopFullBlock(TriDrawVariant variant, bool truecolor); diff --git a/src/r_compiler/ssa/ssa_float.cpp b/src/r_compiler/ssa/ssa_float.cpp index 77cef29ff..a45bee613 100644 --- a/src/r_compiler/ssa/ssa_float.cpp +++ b/src/r_compiler/ssa/ssa_float.cpp @@ -112,12 +112,15 @@ SSAFloat SSAFloat::fma(SSAFloat a, SSAFloat b, SSAFloat c) return SSAFloat::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::fma, params), args, SSAScope::hint())); } +/* This intrinsic isn't always available.. SSAFloat SSAFloat::round(SSAFloat val) { + std::vector params; params.push_back(SSAFloat::llvm_type()); return SSAFloat::from_llvm(SSAScope::builder().CreateCall(SSAScope::intrinsic(llvm::Intrinsic::round, params), val.v, SSAScope::hint())); } +*/ SSAFloat SSAFloat::floor(SSAFloat val) { diff --git a/src/r_compiler/ssa/ssa_float.h b/src/r_compiler/ssa/ssa_float.h index 9386db017..69fb81a75 100644 --- a/src/r_compiler/ssa/ssa_float.h +++ b/src/r_compiler/ssa/ssa_float.h @@ -43,7 +43,7 @@ public: static SSAFloat exp(SSAFloat val); static SSAFloat log(SSAFloat val); static SSAFloat fma(SSAFloat a, SSAFloat b, SSAFloat c); - static SSAFloat round(SSAFloat val); + //static SSAFloat round(SSAFloat val); static SSAFloat floor(SSAFloat val); static SSAFloat MIN(SSAFloat a, SSAFloat b); static SSAFloat MAX(SSAFloat a, SSAFloat b);