[Mesa-dev] [PATCH] glsl: ensure that frexp returns a 0 exponent for zero values
Ilia Mirkin
imirkin at alum.mit.edu
Fri Jul 18 09:19:24 PDT 2014
The current code appears to work in simple tests, however this will
guarantee that the returned exponent is 0 for a 0 value.
Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
I couldn't make a simple test-case that would cause the current logic to
fail. However when I did the same thing with doubles, I ran into trouble. It
seems safer to move the csel outside of the add in case the value actually has
a non-0 exponent despite a 0 significand.
src/glsl/builtin_functions.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index e01742c..5755de9 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -4229,8 +4229,8 @@ builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
* to unsigned integers to ensure that 1 bits aren't shifted in.
*/
body.emit(assign(exponent, rshift(bitcast_f2i(abs(x)), exponent_shift)));
- body.emit(assign(exponent, add(exponent, csel(is_not_zero, exponent_bias,
- imm(0, vec_elem)))));
+ body.emit(assign(exponent, csel(is_not_zero, add(exponent, exponent_bias),
+ imm(0, vec_elem))));
ir_variable *bits = body.make_temp(uvec, "bits");
body.emit(assign(bits, bitcast_f2u(x)));
--
1.8.5.5
More information about the mesa-dev
mailing list