# Mesa (master): glsl/builtins: Simplify degenerate scalar float cases.

Kenneth Graunke kwg at kemper.freedesktop.org
Wed Sep 8 12:11:49 PDT 2010

```Module: Mesa
Branch: master
Commit: 84160a0454b17306e6b9bff5b6e50e54959c5680
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=84160a0454b17306e6b9bff5b6e50e54959c5680

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Sep  7 23:16:26 2010 -0700

glsl/builtins: Simplify degenerate scalar float cases.

The code being generated was just stupid, considering that:
- normalize(x) = 1.0
- length(x) = x
- distance(x, y) = x - y

---

src/glsl/builtins/ir/distance  |    4 +---
src/glsl/builtins/ir/length    |    2 +-
src/glsl/builtins/ir/normalize |    2 +-
3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/glsl/builtins/ir/distance b/src/glsl/builtins/ir/distance
index 1595bf6..f73f755 100644
--- a/src/glsl/builtins/ir/distance
+++ b/src/glsl/builtins/ir/distance
@@ -3,9 +3,7 @@
(parameters
(declare (in) float p0)
(declare (in) float p1))
-     ((declare () float p)
-      (assign (constant bool (1)) (x) (var_ref p) (expression float - (var_ref p0) (var_ref p1)))
-      (return (expression float sqrt (expression float dot (var_ref p) (var_ref p))))))
+     ((return (expression float - (var_ref p0) (var_ref p1)))))

(signature float
(parameters
diff --git a/src/glsl/builtins/ir/length b/src/glsl/builtins/ir/length
index 89ff7f3..3fc3103 100644
--- a/src/glsl/builtins/ir/length
+++ b/src/glsl/builtins/ir/length
@@ -2,7 +2,7 @@
(signature float
(parameters
(declare (in) float arg0))
-     ((return (expression float sqrt (expression float dot (var_ref arg0) (var_ref arg0))))))
+     ((return (var_ref arg0))))

(signature float
(parameters
diff --git a/src/glsl/builtins/ir/normalize b/src/glsl/builtins/ir/normalize
index be88a98..02b249a 100644
--- a/src/glsl/builtins/ir/normalize
+++ b/src/glsl/builtins/ir/normalize
@@ -2,7 +2,7 @@
(signature float
(parameters
(declare (in) float arg0))
-     ((return (expression float * (var_ref arg0) (expression float rsq (expression float dot (var_ref arg0) (var_ref arg0)))))))
+     ((return (constant float (1.0)))))

(signature vec2
(parameters

```