summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorRoland Scheidegger <[email protected]>2013-11-11 15:11:59 +0000
committerRoland Scheidegger <[email protected]>2013-11-12 19:08:58 +0000
commit50f19e3a668b1b589bf00613d33c7c7c4e6a4954 (patch)
tree935ead207e3501e91c31c1590f40a0d751de2dea /src/gallium/drivers
parent2d77e4f922a8c34541d8b187e171738006bd6f4d (diff)
draw,llvmpipe: use exponent manipulation instead of exp2 for polygon offset
Since we explicitly require a integer input we should avoid using exp2 math (even if we were using optimized versions), which turns the exp2 into a int sub (plus some casts). v2: fix bogus uint (needs to be int) math spotted by Matthew, fix comments Reviewed-by: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_setup.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_state_setup.c b/src/gallium/drivers/llvmpipe/lp_state_setup.c
index ccc9fb902f3..1685ddce5ab 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_setup.c
@@ -31,6 +31,7 @@
#include "util/u_simple_list.h"
#include "os/os_time.h"
#include "gallivm/lp_bld_arit.h"
+#include "gallivm/lp_bld_bitarit.h"
#include "gallivm/lp_bld_const.h"
#include "gallivm/lp_bld_debug.h"
#include "gallivm/lp_bld_init.h"
@@ -268,8 +269,6 @@ lp_do_offset_tri(struct gallivm_state *gallivm,
LLVMValueRef zeroi = lp_build_const_int32(gallivm, 0);
LLVMValueRef twoi = lp_build_const_int32(gallivm, 2);
LLVMValueRef threei = lp_build_const_int32(gallivm, 3);
- LLVMValueRef mantissa_bits, exp, bias;
- LLVMValueRef maxz_value, maxz0z1_value;
/* (res12) = cross(e,f).xy */
shuffles[0] = twoi;
@@ -319,9 +318,13 @@ lp_do_offset_tri(struct gallivm_state *gallivm,
*
* NOTE: Assumes IEEE float32.
*/
+ LLVMValueRef c23_shifted, exp_mask, bias, exp;
+ LLVMValueRef maxz_value, maxz0z1_value;
+
lp_build_context_init(&int_scalar_bld, gallivm, lp_type_int_vec(32, 32));
- mantissa_bits = lp_build_const_int32(gallivm, 23);
+ c23_shifted = lp_build_const_int32(gallivm, 23 << 23);
+ exp_mask = lp_build_const_int32(gallivm, 0xff << 23);
maxz0z1_value = lp_build_max(&flt_scalar_bld,
LLVMBuildExtractElement(b, attribv[0], twoi, ""),
@@ -331,15 +334,16 @@ lp_do_offset_tri(struct gallivm_state *gallivm,
LLVMBuildExtractElement(b, attribv[2], twoi, ""),
maxz0z1_value);
- /**
- * XXX: TODO optimize this to quickly resolve a pow2 number through
- * an exponent only operation.
- */
- exp = lp_build_extract_exponent(&flt_scalar_bld, maxz_value, 0);
- exp = lp_build_sub(&int_scalar_bld, exp, mantissa_bits);
- exp = lp_build_int_to_float(&flt_scalar_bld, exp);
+ exp = LLVMBuildBitCast(b, maxz_value, int_scalar_bld.vec_type, "");
+ exp = lp_build_and(&int_scalar_bld, exp, exp_mask);
+ exp = lp_build_sub(&int_scalar_bld, exp, c23_shifted);
+ /* Clamping to zero means mrd will be zero for very small numbers,
+ * but specs do not indicate this should be prevented by clamping
+ * mrd to smallest normal number instead. */
+ exp = lp_build_max(&int_scalar_bld, exp, int_scalar_bld.zero);
+ exp = LLVMBuildBitCast(b, exp, flt_scalar_bld.vec_type, "");
- bias = LLVMBuildFMul(b, lp_build_exp2(&flt_scalar_bld, exp),
+ bias = LLVMBuildFMul(b, exp,
lp_build_const_float(gallivm, key->pgon_offset_units),
"bias");