Mesa (master): glsl: Use M_LOG2E constant instead of calling log2

Ian Romanick idr at kemper.freedesktop.org
Wed Dec 1 20:04:33 UTC 2010


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Nov 24 14:03:57 2010 -0800

glsl: Use M_LOG2E constant instead of calling log2

---

 src/glsl/lower_instructions.cpp |    6 +++---
 src/mesa/main/compiler.h        |    4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/glsl/lower_instructions.cpp b/src/glsl/lower_instructions.cpp
index d460ba1..0d9374d 100644
--- a/src/glsl/lower_instructions.cpp
+++ b/src/glsl/lower_instructions.cpp
@@ -70,7 +70,7 @@
  * opportunity to do things like constant fold the (1.0 / op1) easily.
  */
 
-#include "main/core.h" /* for M_E */
+#include "main/core.h" /* for M_LOG2E */
 #include "glsl_types.h"
 #include "ir.h"
 #include "ir_optimization.h"
@@ -172,7 +172,7 @@ lower_instructions_visitor::div_to_mul_rcp(ir_expression *ir)
 void
 lower_instructions_visitor::exp_to_exp2(ir_expression *ir)
 {
-   ir_constant *log2_e = new(ir) ir_constant(log2f(M_E));
+   ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E));
 
    ir->operation = ir_unop_exp2;
    ir->operands[0] = new(ir) ir_expression(ir_binop_mul, ir->operands[0]->type,
@@ -186,7 +186,7 @@ lower_instructions_visitor::log_to_log2(ir_expression *ir)
    ir->operation = ir_binop_mul;
    ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type,
 					   ir->operands[0], NULL);
-   ir->operands[1] = new(ir) ir_constant(1.0f / log2f(M_E));
+   ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E));
    this->progress = true;
 }
 
diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
index 800eb83..5557a3b 100644
--- a/src/mesa/main/compiler.h
+++ b/src/mesa/main/compiler.h
@@ -358,6 +358,10 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
 #define M_E (2.7182818284590452354)
 #endif
 
+#ifndef M_LOG2E
+#define M_LOG2E     (1.4426950408889634074)
+#endif
+
 #ifndef ONE_DIV_LN2
 #define ONE_DIV_LN2 (1.442695040888963456)
 #endif




More information about the mesa-commit mailing list