summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Turner <[email protected]>2013-08-04 14:01:30 -0700
committerMatt Turner <[email protected]>2013-08-29 12:07:28 -0700
commit1ecfdba98a346c8bb05ad9403e3a6412574215f4 (patch)
tree32f3b23a594338f9eff821002807c39bb586b572 /src
parent57cf5946ce7604aa42c78dbdc34c453f8b2a0b21 (diff)
glsl: Add heuristics to print floating-point numbers better.
v2: Fix *.expected files to match. Reviewed-by: Paul Berry <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/glsl/ir_print_visitor.cpp12
-rw-r--r--src/glsl/tests/lower_jumps/lower_breaks_2.opt_test.expected2
-rw-r--r--src/glsl/tests/lower_jumps/lower_breaks_3.opt_test.expected2
-rw-r--r--src/glsl/tests/lower_jumps/lower_breaks_4.opt_test.expected2
-rw-r--r--src/glsl/tests/lower_jumps/lower_breaks_5.opt_test.expected2
-rw-r--r--src/glsl/tests/lower_jumps/lower_breaks_6.opt_test.expected10
-rw-r--r--src/glsl/tests/lower_jumps/lower_guarded_conditional_break.opt_test.expected6
-rw-r--r--src/glsl/tests/lower_jumps/lower_pulled_out_jump.opt_test.expected8
-rw-r--r--src/glsl/tests/lower_jumps/lower_returns_3.opt_test.expected4
-rw-r--r--src/glsl/tests/lower_jumps/lower_returns_4.opt_test.expected2
-rw-r--r--src/glsl/tests/lower_jumps/lower_returns_main_false.opt_test.expected4
-rw-r--r--src/glsl/tests/lower_jumps/lower_returns_main_true.opt_test.expected4
-rw-r--r--src/glsl/tests/lower_jumps/lower_returns_sub_false.opt_test.expected4
-rw-r--r--src/glsl/tests/lower_jumps/lower_returns_sub_true.opt_test.expected4
-rw-r--r--src/glsl/tests/lower_jumps/lower_unified_returns.opt_test.expected8
15 files changed, 42 insertions, 32 deletions
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index 541231a33c1..b5183108d6b 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -406,7 +406,17 @@ void ir_print_visitor::visit(ir_constant *ir)
switch (ir->type->base_type) {
case GLSL_TYPE_UINT: printf("%u", ir->value.u[i]); break;
case GLSL_TYPE_INT: printf("%d", ir->value.i[i]); break;
- case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break;
+ case GLSL_TYPE_FLOAT:
+ if (ir->value.f[i] == 0.0f)
+ /* 0.0 == -0.0, so print with %f to get the proper sign. */
+ printf("%.1f", ir->value.f[i]);
+ else if (abs(ir->value.f[i]) < 0.000001f)
+ printf("%a", ir->value.f[i]);
+ else if (abs(ir->value.f[i]) > 1000000.0f)
+ printf("%e", ir->value.f[i]);
+ else
+ printf("%f", ir->value.f[i]);
+ break;
case GLSL_TYPE_BOOL: printf("%d", ir->value.b[i]); break;
default: assert(0);
}
diff --git a/src/glsl/tests/lower_jumps/lower_breaks_2.opt_test.expected b/src/glsl/tests/lower_jumps/lower_breaks_2.opt_test.expected
index a4cb2d6a125..3771efc7511 100644
--- a/src/glsl/tests/lower_jumps/lower_breaks_2.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_breaks_2.opt_test.expected
@@ -3,5 +3,5 @@
(signature void (parameters)
((loop () () () ()
((assign (x) (var_ref a) (constant float (1.000000)))
- (if (expression bool > (var_ref b) (constant float (0.000000))) (break)
+ (if (expression bool > (var_ref b) (constant float (0.0))) (break)
())))))))
diff --git a/src/glsl/tests/lower_jumps/lower_breaks_3.opt_test.expected b/src/glsl/tests/lower_jumps/lower_breaks_3.opt_test.expected
index 325f7b49a5d..afae5e7c77b 100644
--- a/src/glsl/tests/lower_jumps/lower_breaks_3.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_breaks_3.opt_test.expected
@@ -3,6 +3,6 @@
(signature void (parameters)
((loop () () () ()
((assign (x) (var_ref a) (constant float (1.000000)))
- (if (expression bool > (var_ref b) (constant float (0.000000)))
+ (if (expression bool > (var_ref b) (constant float (0.0)))
((assign (x) (var_ref c) (constant float (1.000000))) break)
())))))))
diff --git a/src/glsl/tests/lower_jumps/lower_breaks_4.opt_test.expected b/src/glsl/tests/lower_jumps/lower_breaks_4.opt_test.expected
index a7735457cb8..588a3f66a53 100644
--- a/src/glsl/tests/lower_jumps/lower_breaks_4.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_breaks_4.opt_test.expected
@@ -3,5 +3,5 @@
(signature void (parameters)
((loop () () () ()
((assign (x) (var_ref a) (constant float (1.000000)))
- (if (expression bool > (var_ref b) (constant float (0.000000))) ()
+ (if (expression bool > (var_ref b) (constant float (0.0))) ()
(break))))))))
diff --git a/src/glsl/tests/lower_jumps/lower_breaks_5.opt_test.expected b/src/glsl/tests/lower_jumps/lower_breaks_5.opt_test.expected
index 0dd4a529383..da2d1a2c820 100644
--- a/src/glsl/tests/lower_jumps/lower_breaks_5.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_breaks_5.opt_test.expected
@@ -3,5 +3,5 @@
(signature void (parameters)
((loop () () () ()
((assign (x) (var_ref a) (constant float (1.000000)))
- (if (expression bool > (var_ref b) (constant float (0.000000))) ()
+ (if (expression bool > (var_ref b) (constant float (0.0))) ()
((assign (x) (var_ref c) (constant float (1.000000))) break))))))))
diff --git a/src/glsl/tests/lower_jumps/lower_breaks_6.opt_test.expected b/src/glsl/tests/lower_jumps/lower_breaks_6.opt_test.expected
index 8222328e00c..9adf8655f23 100644
--- a/src/glsl/tests/lower_jumps/lower_breaks_6.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_breaks_6.opt_test.expected
@@ -8,15 +8,15 @@
(loop () () () ()
((declare (temporary) bool execute_flag)
(assign (x) (var_ref execute_flag) (constant bool (1)))
- (if (expression bool > (var_ref a) (constant float (0.000000)))
- ((if (expression bool > (var_ref ba) (constant float (0.000000)))
- ((if (expression bool > (var_ref bb) (constant float (0.000000)))
+ (if (expression bool > (var_ref a) (constant float (0.0)))
+ ((if (expression bool > (var_ref ba) (constant float (0.0)))
+ ((if (expression bool > (var_ref bb) (constant float (0.0)))
((assign (x) (var_ref execute_flag) (constant bool (0))))
()))
())
(if (var_ref execute_flag)
- ((if (expression bool > (var_ref ca) (constant float (0.000000)))
- ((if (expression bool > (var_ref cb) (constant float (0.000000)))
+ ((if (expression bool > (var_ref ca) (constant float (0.0)))
+ ((if (expression bool > (var_ref cb) (constant float (0.0)))
((assign (x) (var_ref break_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))
diff --git a/src/glsl/tests/lower_jumps/lower_guarded_conditional_break.opt_test.expected b/src/glsl/tests/lower_jumps/lower_guarded_conditional_break.opt_test.expected
index 7c6e73f77f8..a69e2b791a6 100644
--- a/src/glsl/tests/lower_jumps/lower_guarded_conditional_break.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_guarded_conditional_break.opt_test.expected
@@ -6,13 +6,13 @@
(loop () () () ()
((declare (temporary) bool execute_flag)
(assign (x) (var_ref execute_flag) (constant bool (1)))
- (if (expression bool > (var_ref aa) (constant float (0.000000)))
- ((if (expression bool > (var_ref ab) (constant float (0.000000)))
+ (if (expression bool > (var_ref aa) (constant float (0.0)))
+ ((if (expression bool > (var_ref ab) (constant float (0.0)))
((assign (x) (var_ref execute_flag) (constant bool (0))))
()))
())
(if (var_ref execute_flag)
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
((assign (x) (var_ref break_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))
diff --git a/src/glsl/tests/lower_jumps/lower_pulled_out_jump.opt_test.expected b/src/glsl/tests/lower_jumps/lower_pulled_out_jump.opt_test.expected
index bf45c2c93b6..b921d307ff6 100644
--- a/src/glsl/tests/lower_jumps/lower_pulled_out_jump.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_pulled_out_jump.opt_test.expected
@@ -7,16 +7,16 @@
(assign (x) (var_ref execute_flag) (constant bool (1)))
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (if (expression bool > (var_ref aa) (constant float (0.000000)))
- ((if (expression bool > (var_ref ab) (constant float (0.000000)))
+ (if (expression bool > (var_ref aa) (constant float (0.0)))
+ ((if (expression bool > (var_ref ab) (constant float (0.0)))
((assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))
())
(if (var_ref execute_flag)
((loop () () () ()
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
- ((if (expression bool > (var_ref c) (constant float (0.000000))) ()
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
+ ((if (expression bool > (var_ref c) (constant float (0.0))) ()
(continue)))
((assign (x) (var_ref return_flag) (constant bool (1)))))
break))
diff --git a/src/glsl/tests/lower_jumps/lower_returns_3.opt_test.expected b/src/glsl/tests/lower_jumps/lower_returns_3.opt_test.expected
index d4835e96b7c..5b62bbcde99 100644
--- a/src/glsl/tests/lower_jumps/lower_returns_3.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_returns_3.opt_test.expected
@@ -6,8 +6,8 @@
(declare (temporary) float return_value)
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (if (expression bool > (var_ref a) (constant float (0.000000)))
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
+ (if (expression bool > (var_ref a) (constant float (0.0)))
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
((assign (x) (var_ref return_value) (constant float (1.000000)))
(assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
diff --git a/src/glsl/tests/lower_jumps/lower_returns_4.opt_test.expected b/src/glsl/tests/lower_jumps/lower_returns_4.opt_test.expected
index b551a066f43..07c6842d20c 100644
--- a/src/glsl/tests/lower_jumps/lower_returns_4.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_returns_4.opt_test.expected
@@ -6,7 +6,7 @@
(declare (temporary) float return_value)
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (if (expression bool > (var_ref a) (constant float (0.000000)))
+ (if (expression bool > (var_ref a) (constant float (0.0)))
((assign (x) (var_ref return_value) (constant float (1.000000)))
(assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
diff --git a/src/glsl/tests/lower_jumps/lower_returns_main_false.opt_test.expected b/src/glsl/tests/lower_jumps/lower_returns_main_false.opt_test.expected
index e8b36f14478..7e3fe314f96 100644
--- a/src/glsl/tests/lower_jumps/lower_returns_main_false.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_returns_main_false.opt_test.expected
@@ -1,8 +1,8 @@
((declare (in) float a) (declare (in) float b)
(function main
(signature void (parameters)
- ((if (expression bool > (var_ref a) (constant float (0.000000)))
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
+ ((if (expression bool > (var_ref a) (constant float (0.0)))
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
((return))
()))
())))))
diff --git a/src/glsl/tests/lower_jumps/lower_returns_main_true.opt_test.expected b/src/glsl/tests/lower_jumps/lower_returns_main_true.opt_test.expected
index e15a97d1db2..b47f5a433de 100644
--- a/src/glsl/tests/lower_jumps/lower_returns_main_true.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_returns_main_true.opt_test.expected
@@ -5,8 +5,8 @@
(assign (x) (var_ref execute_flag) (constant bool (1)))
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (if (expression bool > (var_ref a) (constant float (0.000000)))
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
+ (if (expression bool > (var_ref a) (constant float (0.0)))
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
((assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))
diff --git a/src/glsl/tests/lower_jumps/lower_returns_sub_false.opt_test.expected b/src/glsl/tests/lower_jumps/lower_returns_sub_false.opt_test.expected
index 07db6e708f4..7424968b248 100644
--- a/src/glsl/tests/lower_jumps/lower_returns_sub_false.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_returns_sub_false.opt_test.expected
@@ -1,8 +1,8 @@
((declare (in) float a) (declare (in) float b)
(function sub
(signature void (parameters)
- ((if (expression bool > (var_ref a) (constant float (0.000000)))
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
+ ((if (expression bool > (var_ref a) (constant float (0.0)))
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
((return))
()))
())))))
diff --git a/src/glsl/tests/lower_jumps/lower_returns_sub_true.opt_test.expected b/src/glsl/tests/lower_jumps/lower_returns_sub_true.opt_test.expected
index 31109802351..1a3eae5da76 100644
--- a/src/glsl/tests/lower_jumps/lower_returns_sub_true.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_returns_sub_true.opt_test.expected
@@ -5,8 +5,8 @@
(assign (x) (var_ref execute_flag) (constant bool (1)))
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (if (expression bool > (var_ref a) (constant float (0.000000)))
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
+ (if (expression bool > (var_ref a) (constant float (0.0)))
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
((assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))
diff --git a/src/glsl/tests/lower_jumps/lower_unified_returns.opt_test.expected b/src/glsl/tests/lower_jumps/lower_unified_returns.opt_test.expected
index 271cd3b462e..c0b51e1baaa 100644
--- a/src/glsl/tests/lower_jumps/lower_unified_returns.opt_test.expected
+++ b/src/glsl/tests/lower_jumps/lower_unified_returns.opt_test.expected
@@ -6,15 +6,15 @@
(assign (x) (var_ref execute_flag) (constant bool (1)))
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (if (expression bool > (var_ref aa) (constant float (0.000000)))
- ((if (expression bool > (var_ref ab) (constant float (0.000000)))
+ (if (expression bool > (var_ref aa) (constant float (0.0)))
+ ((if (expression bool > (var_ref ab) (constant float (0.0)))
((assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))
())
(if (var_ref execute_flag)
- ((if (expression bool > (var_ref b) (constant float (0.000000)))
- ((if (expression bool > (var_ref c) (constant float (0.000000))) () ())
+ ((if (expression bool > (var_ref b) (constant float (0.0)))
+ ((if (expression bool > (var_ref c) (constant float (0.0))) () ())
(assign (x) (var_ref return_flag) (constant bool (1)))
(assign (x) (var_ref execute_flag) (constant bool (0))))
()))