[Mesa-dev] [PATCH 04/50] glsl: Add "built-in" functions to do eq(fp64, fp64)

Dave Airlie airlied at gmail.com
Tue Mar 13 04:24:29 UTC 2018


From: Elie Tournier <tournier.elie at gmail.com>

Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
---
 src/compiler/glsl/builtin_float64.h     | 104 ++++++++++++++++++++++++++++++++
 src/compiler/glsl/builtin_functions.cpp |   4 ++
 src/compiler/glsl/builtin_functions.h   |   3 +
 src/compiler/glsl/float64.glsl          |  44 ++++++++++++++
 src/compiler/glsl/glcpp/glcpp-parse.y   |   1 +
 5 files changed, 156 insertions(+)

diff --git a/src/compiler/glsl/builtin_float64.h b/src/compiler/glsl/builtin_float64.h
index 8546048..2340c48 100644
--- a/src/compiler/glsl/builtin_float64.h
+++ b/src/compiler/glsl/builtin_float64.h
@@ -96,3 +96,107 @@ fsign64(void *mem_ctx, builtin_available_predicate avail)
    sig->replace_parameters(&sig_parameters);
    return sig;
 }
+ir_function_signature *
+extractFloat64FracLo(void *mem_ctx, builtin_available_predicate avail)
+{
+   ir_function_signature *const sig =
+      new(mem_ctx) ir_function_signature(glsl_type::uint_type, avail);
+   ir_factory body(&sig->body, mem_ctx);
+   sig->is_defined = true;
+
+   exec_list sig_parameters;
+
+   ir_variable *const r0024 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
+   sig_parameters.push_tail(r0024);
+   ir_swizzle *const r0025 = swizzle_x(r0024);
+   body.emit(ret(r0025));
+
+   sig->replace_parameters(&sig_parameters);
+   return sig;
+}
+ir_function_signature *
+extractFloat64FracHi(void *mem_ctx, builtin_available_predicate avail)
+{
+   ir_function_signature *const sig =
+      new(mem_ctx) ir_function_signature(glsl_type::uint_type, avail);
+   ir_factory body(&sig->body, mem_ctx);
+   sig->is_defined = true;
+
+   exec_list sig_parameters;
+
+   ir_variable *const r0026 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
+   sig_parameters.push_tail(r0026);
+   ir_expression *const r0027 = bit_and(swizzle_y(r0026), body.constant(1048575u));
+   body.emit(ret(r0027));
+
+   sig->replace_parameters(&sig_parameters);
+   return sig;
+}
+ir_function_signature *
+extractFloat64Exp(void *mem_ctx, builtin_available_predicate avail)
+{
+   ir_function_signature *const sig =
+      new(mem_ctx) ir_function_signature(glsl_type::int_type, avail);
+   ir_factory body(&sig->body, mem_ctx);
+   sig->is_defined = true;
+
+   exec_list sig_parameters;
+
+   ir_variable *const r0028 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
+   sig_parameters.push_tail(r0028);
+   ir_expression *const r0029 = rshift(swizzle_y(r0028), body.constant(int(20)));
+   ir_expression *const r002A = bit_and(r0029, body.constant(2047u));
+   ir_expression *const r002B = expr(ir_unop_u2i, r002A);
+   body.emit(ret(r002B));
+
+   sig->replace_parameters(&sig_parameters);
+   return sig;
+}
+ir_function_signature *
+feq64(void *mem_ctx, builtin_available_predicate avail)
+{
+   ir_function_signature *const sig =
+      new(mem_ctx) ir_function_signature(glsl_type::bool_type, avail);
+   ir_factory body(&sig->body, mem_ctx);
+   sig->is_defined = true;
+
+   exec_list sig_parameters;
+
+   ir_variable *const r002C = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
+   sig_parameters.push_tail(r002C);
+   ir_variable *const r002D = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "b", ir_var_function_in);
+   sig_parameters.push_tail(r002D);
+   ir_variable *const r002E = body.make_temp(glsl_type::bool_type, "mix_retval");
+   ir_expression *const r002F = rshift(swizzle_y(r002C), body.constant(int(20)));
+   ir_expression *const r0030 = bit_and(r002F, body.constant(2047u));
+   ir_expression *const r0031 = expr(ir_unop_u2i, r0030);
+   ir_expression *const r0032 = equal(r0031, body.constant(int(2047)));
+   ir_expression *const r0033 = bit_and(swizzle_y(r002C), body.constant(1048575u));
+   ir_expression *const r0034 = bit_or(r0033, swizzle_x(r002C));
+   ir_expression *const r0035 = nequal(r0034, body.constant(0u));
+   ir_expression *const r0036 = logic_and(r0032, r0035);
+   ir_expression *const r0037 = rshift(swizzle_y(r002D), body.constant(int(20)));
+   ir_expression *const r0038 = bit_and(r0037, body.constant(2047u));
+   ir_expression *const r0039 = expr(ir_unop_u2i, r0038);
+   ir_expression *const r003A = equal(r0039, body.constant(int(2047)));
+   ir_expression *const r003B = bit_and(swizzle_y(r002D), body.constant(1048575u));
+   ir_expression *const r003C = bit_or(r003B, swizzle_x(r002D));
+   ir_expression *const r003D = nequal(r003C, body.constant(0u));
+   ir_expression *const r003E = logic_and(r003A, r003D);
+   ir_expression *const r003F = logic_or(r0036, r003E);
+   ir_expression *const r0040 = equal(swizzle_x(r002C), swizzle_x(r002D));
+   ir_expression *const r0041 = equal(swizzle_y(r002C), swizzle_y(r002D));
+   ir_expression *const r0042 = equal(swizzle_x(r002C), body.constant(0u));
+   ir_expression *const r0043 = bit_or(swizzle_y(r002C), swizzle_y(r002D));
+   ir_expression *const r0044 = lshift(r0043, body.constant(int(1)));
+   ir_expression *const r0045 = equal(r0044, body.constant(0u));
+   ir_expression *const r0046 = logic_and(r0042, r0045);
+   ir_expression *const r0047 = logic_or(r0041, r0046);
+   ir_expression *const r0048 = logic_and(r0040, r0047);
+   body.emit(assign(r002E, expr(ir_triop_csel, r003F, body.constant(false), r0048), 0x01));
+
+   body.emit(ret(r002E));
+
+   sig->replace_parameters(&sig_parameters);
+   return sig;
+}
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 17aa868..2298c40 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -3354,6 +3354,10 @@ builtin_builder::create_builtins()
                 generate_ir::fsign64(mem_ctx, integer_functions_supported),
                 NULL);
 
+   add_function("__builtin_feq64",
+                generate_ir::feq64(mem_ctx, integer_functions_supported),
+                NULL);
+
 #undef F
 #undef FI
 #undef FIUD_VEC
diff --git a/src/compiler/glsl/builtin_functions.h b/src/compiler/glsl/builtin_functions.h
index 7954373..8cfdf49 100644
--- a/src/compiler/glsl/builtin_functions.h
+++ b/src/compiler/glsl/builtin_functions.h
@@ -76,6 +76,9 @@ fneg64(void *mem_ctx, builtin_available_predicate avail);
 ir_function_signature *
 fsign64(void *mem_ctx, builtin_available_predicate avail);
 
+ir_function_signature *
+feq64(void *mem_ctx, builtin_available_predicate avail);
+
 }
 
 #endif /* BULITIN_FUNCTIONS_H */
diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
index f8eb1f3..0cd7991 100644
--- a/src/compiler/glsl/float64.glsl
+++ b/src/compiler/glsl/float64.glsl
@@ -60,3 +60,47 @@ fsign64(uvec2 a)
    retval.y = mix((a.y & 0x80000000u) | 0x3FF00000u, 0u, (a.y << 1 | a.x) == 0u);
    return retval;
 }
+
+/* Returns the fraction bits of the double-precision floating-point value `a'.*/
+uint
+extractFloat64FracLo(uvec2 a)
+{
+   return a.x;
+}
+
+uint
+extractFloat64FracHi(uvec2 a)
+{
+   return a.y & 0x000FFFFFu;
+}
+
+/* Returns the exponent bits of the double-precision floating-point value `a'.*/
+int
+extractFloat64Exp(uvec2 a)
+{
+   return int((a.y>>20) & 0x7FFu);
+}
+
+/* Returns true if the double-precision floating-point value `a' is equal to the
+ * corresponding value `b', and false otherwise.  The comparison is performed
+ * according to the IEEE Standard for Floating-Point Arithmetic.
+ */
+bool
+feq64(uvec2 a, uvec2 b)
+{
+   bool isaNaN;
+   bool isbNaN;
+
+   uint aFracLo = extractFloat64FracLo(a);
+   uint aFracHi = extractFloat64FracHi(a);
+   uint bFracLo = extractFloat64FracLo(b);
+   uint bFracHi = extractFloat64FracHi(b);
+   isaNaN = (extractFloat64Exp(a) == 0x7FF) &&
+      ((aFracHi | aFracLo) != 0u);
+   isbNaN = (extractFloat64Exp(b) == 0x7FF) &&
+      ((bFracHi | bFracLo) != 0u);
+
+   bool result = (a.x == b.x) &&
+      ((a.y == b.y) || ((a.x == 0u) && (((a.y | b.y)<<1) == 0u)));
+   return mix(result, false, isaNaN || isbNaN);
+}
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index 666543b..9ffca67 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -2371,6 +2371,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
          add_builtin_define(parser, "__have_builtin_builtin_fabs64", 1);
          add_builtin_define(parser, "__have_builtin_builtin_fneg64", 1);
          add_builtin_define(parser, "__have_builtin_builtin_fsign64", 1);
+         add_builtin_define(parser, "__have_builtin_builtin_feq64", 1);
       }
    }
 
-- 
2.9.5



More information about the mesa-dev mailing list