Signed-off-by: Elie Tournier <elie.tourn...@collabora.com> --- src/compiler/glsl/builtin_float64.h | 72 +++++++++++++++++++++++++++++++++ src/compiler/glsl/builtin_functions.cpp | 4 ++ src/compiler/glsl/builtin_functions.h | 3 ++ src/compiler/glsl/float64.glsl | 23 +++++++++++ src/compiler/glsl/glcpp/glcpp-parse.y | 1 + 5 files changed, 103 insertions(+)
diff --git a/src/compiler/glsl/builtin_float64.h b/src/compiler/glsl/builtin_float64.h index 7b572314fa..d8c25da825 100644 --- a/src/compiler/glsl/builtin_float64.h +++ b/src/compiler/glsl/builtin_float64.h @@ -17,3 +17,75 @@ fabs64(void *mem_ctx, builtin_available_predicate avail) sig->replace_parameters(&sig_parameters); return sig; } +ir_function_signature * +is_nan(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 r000C = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in); + sig_parameters.push_tail(r000C); + ir_expression *const r000D = lshift(swizzle_y(r000C), body.constant(int(1))); + ir_expression *const r000E = lequal(body.constant(4292870144u), r000D); + ir_expression *const r000F = nequal(swizzle_x(r000C), body.constant(0u)); + ir_expression *const r0010 = bit_and(swizzle_y(r000C), body.constant(1048575u)); + ir_expression *const r0011 = nequal(r0010, body.constant(0u)); + ir_expression *const r0012 = logic_or(r000F, r0011); + ir_expression *const r0013 = logic_and(r000E, r0012); + body.emit(ret(r0013)); + + sig->replace_parameters(&sig_parameters); + return sig; +} +ir_function_signature * +fneg64(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 r0014 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in); + sig_parameters.push_tail(r0014); + ir_variable *const r0015 = body.make_temp(glsl_type::uvec2_type, "return_value"); + /* IF CONDITION */ + ir_expression *const r0017 = lshift(swizzle_y(r0014), body.constant(int(1))); + ir_expression *const r0018 = lequal(body.constant(4292870144u), r0017); + ir_expression *const r0019 = nequal(swizzle_x(r0014), body.constant(0u)); + ir_expression *const r001A = bit_and(swizzle_y(r0014), body.constant(1048575u)); + ir_expression *const r001B = nequal(r001A, body.constant(0u)); + ir_expression *const r001C = logic_or(r0019, r001B); + ir_expression *const r001D = logic_and(r0018, r001C); + ir_if *f0016 = new(mem_ctx) ir_if(operand(r001D).val); + exec_list *const f0016_parent_instructions = body.instructions; + + /* THEN INSTRUCTIONS */ + body.instructions = &f0016->then_instructions; + + body.emit(assign(r0015, r0014, 0x03)); + + + /* ELSE INSTRUCTIONS */ + body.instructions = &f0016->else_instructions; + + body.emit(assign(r0014, bit_xor(swizzle_y(r0014), body.constant(2147483648u)), 0x02)); + + body.emit(assign(r0015, r0014, 0x03)); + + + body.instructions = f0016_parent_instructions; + body.emit(f0016); + + /* END IF */ + + body.emit(ret(r0015)); + + sig->replace_parameters(&sig_parameters); + return sig; +} diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp index 37cc164a73..0445f733ab 100644 --- a/src/compiler/glsl/builtin_functions.cpp +++ b/src/compiler/glsl/builtin_functions.cpp @@ -3328,6 +3328,10 @@ builtin_builder::create_builtins() generate_ir::fabs64(mem_ctx, integer_functions_supported), NULL); + add_function("__builtin_fneg64", + generate_ir::fneg64(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 deaf640447..adec424292 100644 --- a/src/compiler/glsl/builtin_functions.h +++ b/src/compiler/glsl/builtin_functions.h @@ -70,6 +70,9 @@ udivmod64(void *mem_ctx, builtin_available_predicate avail); ir_function_signature * fabs64(void *mem_ctx, builtin_available_predicate avail); +ir_function_signature * +fneg64(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 d798d7e7ac..cef939323b 100644 --- a/src/compiler/glsl/float64.glsl +++ b/src/compiler/glsl/float64.glsl @@ -27,3 +27,26 @@ fabs64(uvec2 a) a.y &= 0x7FFFFFFFu; return a; } + +/* Returns 1 if the double-precision floating-point value `a' is a NaN; + * otherwise returns 0. + */ +bool +is_nan(uvec2 a) +{ + return (0xFFE00000u <= (a.y<<1)) && + ((a.x != 0u) || ((a.y & 0x000FFFFFu) != 0u)); +} + +/* Negate value of a Float64 : + * Toggle the sign bit + */ +uvec2 +fneg64(uvec2 a) +{ + if(is_nan(a)) + return a; + + a.y ^= (1u<<31); + return a; +} diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index 5b68887c8e..4486326d86 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -2450,6 +2450,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio add_builtin_define(parser, "__have_builtin_builtin_idiv64", 1); 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); } } -- 2.14.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev