[Mesa-dev] [PATCH 03/47] glsl: Add "built-in" function to do sign(fp64)

Elie Tournier tournier.elie at gmail.com
Wed Aug 23 11:07:33 UTC 2017


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

diff --git a/src/compiler/glsl/builtin_float64.h b/src/compiler/glsl/builtin_float64.h
index d8c25da825..d41d114b84 100644
--- a/src/compiler/glsl/builtin_float64.h
+++ b/src/compiler/glsl/builtin_float64.h
@@ -89,3 +89,52 @@ fneg64(void *mem_ctx, builtin_available_predicate avail)
    sig->replace_parameters(&sig_parameters);
    return sig;
 }
+ir_function_signature *
+fsign64(void *mem_ctx, builtin_available_predicate avail)
+{
+   ir_function_signature *const sig =
+      new(mem_ctx) ir_function_signature(glsl_type::uvec2_type, avail);
+   ir_factory body(&sig->body, mem_ctx);
+   sig->is_defined = true;
+
+   exec_list sig_parameters;
+
+   ir_variable *const r001E = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
+   sig_parameters.push_tail(r001E);
+   ir_variable *const r001F = body.make_temp(glsl_type::uvec2_type, "return_value");
+   ir_variable *const r0020 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "retval", ir_var_auto);
+   body.emit(r0020);
+   /* IF CONDITION */
+   ir_expression *const r0022 = lshift(swizzle_y(r001E), body.constant(int(1)));
+   ir_expression *const r0023 = bit_or(r0022, swizzle_x(r001E));
+   ir_expression *const r0024 = equal(r0023, body.constant(0u));
+   ir_if *f0021 = new(mem_ctx) ir_if(operand(r0024).val);
+   exec_list *const f0021_parent_instructions = body.instructions;
+
+      /* THEN INSTRUCTIONS */
+      body.instructions = &f0021->then_instructions;
+
+      body.emit(assign(r001F, ir_constant::zero(mem_ctx, glsl_type::uvec2_type), 0x03));
+
+
+      /* ELSE INSTRUCTIONS */
+      body.instructions = &f0021->else_instructions;
+
+      body.emit(assign(r0020, body.constant(0u), 0x01));
+
+      ir_expression *const r0025 = bit_and(swizzle_y(r001E), body.constant(2147483648u));
+      body.emit(assign(r0020, bit_or(r0025, body.constant(1072693248u)), 0x02));
+
+      body.emit(assign(r001F, r0020, 0x03));
+
+
+   body.instructions = f0021_parent_instructions;
+   body.emit(f0021);
+
+   /* END IF */
+
+   body.emit(ret(r001F));
+
+   sig->replace_parameters(&sig_parameters);
+   return sig;
+}
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 0445f733ab..1e3101bac3 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -3332,6 +3332,10 @@ builtin_builder::create_builtins()
                 generate_ir::fneg64(mem_ctx, integer_functions_supported),
                 NULL);
 
+   add_function("__builtin_fsign64",
+                generate_ir::fsign64(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 adec424292..7954373154 100644
--- a/src/compiler/glsl/builtin_functions.h
+++ b/src/compiler/glsl/builtin_functions.h
@@ -73,6 +73,9 @@ fabs64(void *mem_ctx, builtin_available_predicate avail);
 ir_function_signature *
 fneg64(void *mem_ctx, builtin_available_predicate avail);
 
+ir_function_signature *
+fsign64(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 cef939323b..6561c0e7e6 100644
--- a/src/compiler/glsl/float64.glsl
+++ b/src/compiler/glsl/float64.glsl
@@ -50,3 +50,15 @@ fneg64(uvec2 a)
    a.y ^= (1u<<31);
    return a;
 }
+
+uvec2
+fsign64(uvec2 a)
+{
+   if ((a.y << 1 | a.x) == 0u)
+      return uvec2(0u, 0u);
+
+   uvec2 retval;
+   retval.x = 0u;
+   retval.y = (a.y & 0x80000000u) | 0x3FF00000u;
+   return retval;
+}
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index 4486326d86..72011dec68 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -2451,6 +2451,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
          add_builtin_define(parser, "__have_builtin_builtin_imod64", 1);
          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);
       }
    }
 
-- 
2.14.1



More information about the mesa-dev mailing list