Re: [Mesa-dev] [PATCH 27/50] glsl: Add "built-in" function for 64-bit integer sign()

2016-12-01 Thread Ian Romanick
On 11/30/2016 12:46 PM, Matt Turner wrote:
> On 11/28, Ian Romanick wrote:
>> From: Ian Romanick 
>>
>> These functions are directly available in shaders.  A #define is added
>> to detect the presence.  This allows these functions to be tested using
>> piglit regardless of whether the driver uses them for lowering.  The
>> GLSL spec says that functions and macros beginning with __ are reserved
>> for use by the implementation... hey, that's us!
>>
>> Signed-off-by: Ian Romanick 
>> ---
>> src/compiler/glsl/builtin_functions.cpp |   4 +
>> src/compiler/glsl/builtin_functions.h   |   3 +
>> src/compiler/glsl/builtin_int64.h   |  26 
>> src/compiler/glsl/glcpp/glcpp-parse.y   |   1 +
>> src/compiler/glsl/int64.glsl|  11 ++
>> src/compiler/glsl/udivmod64.h   | 206
>> 
>> 6 files changed, 251 insertions(+)
>> create mode 100644 src/compiler/glsl/udivmod64.h
> 
> This is supposed to be in a later patch.

Blarg.  This isn't supposed to be in any patch. :( This was just junk
left in my tree.  The division and modulus routines are (correctly)
added to builtin_int64.h in patch 29.

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 27/50] glsl: Add "built-in" function for 64-bit integer sign()

2016-11-30 Thread Matt Turner

On 11/28, Ian Romanick wrote:

From: Ian Romanick 

These functions are directly available in shaders.  A #define is added
to detect the presence.  This allows these functions to be tested using
piglit regardless of whether the driver uses them for lowering.  The
GLSL spec says that functions and macros beginning with __ are reserved
for use by the implementation... hey, that's us!

Signed-off-by: Ian Romanick 
---
src/compiler/glsl/builtin_functions.cpp |   4 +
src/compiler/glsl/builtin_functions.h   |   3 +
src/compiler/glsl/builtin_int64.h   |  26 
src/compiler/glsl/glcpp/glcpp-parse.y   |   1 +
src/compiler/glsl/int64.glsl|  11 ++
src/compiler/glsl/udivmod64.h   | 206 
6 files changed, 251 insertions(+)
create mode 100644 src/compiler/glsl/udivmod64.h


This is supposed to be in a later patch.


signature.asc
Description: Digital signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 27/50] glsl: Add "built-in" function for 64-bit integer sign()

2016-11-28 Thread Ian Romanick
From: Ian Romanick 

These functions are directly available in shaders.  A #define is added
to detect the presence.  This allows these functions to be tested using
piglit regardless of whether the driver uses them for lowering.  The
GLSL spec says that functions and macros beginning with __ are reserved
for use by the implementation... hey, that's us!

Signed-off-by: Ian Romanick 
---
 src/compiler/glsl/builtin_functions.cpp |   4 +
 src/compiler/glsl/builtin_functions.h   |   3 +
 src/compiler/glsl/builtin_int64.h   |  26 
 src/compiler/glsl/glcpp/glcpp-parse.y   |   1 +
 src/compiler/glsl/int64.glsl|  11 ++
 src/compiler/glsl/udivmod64.h   | 206 
 6 files changed, 251 insertions(+)
 create mode 100644 src/compiler/glsl/udivmod64.h

diff --git a/src/compiler/glsl/builtin_functions.cpp 
b/src/compiler/glsl/builtin_functions.cpp
index 4f1a874..348aea9 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -3108,6 +3108,10 @@ builtin_builder::create_builtins()
add_function("allInvocationsARB", _vote(ir_unop_vote_all), NULL);
add_function("allInvocationsEqualARB", _vote(ir_unop_vote_eq), NULL);
 
+   add_function("__builtin_sign64",
+generate_ir::sign64(mem_ctx, integer_functions_supported),
+NULL);
+
add_function("__builtin_umul64",
 generate_ir::umul64(mem_ctx, integer_functions_supported),
 NULL);
diff --git a/src/compiler/glsl/builtin_functions.h 
b/src/compiler/glsl/builtin_functions.h
index a79fb97..c66f523 100644
--- a/src/compiler/glsl/builtin_functions.h
+++ b/src/compiler/glsl/builtin_functions.h
@@ -48,6 +48,9 @@ namespace generate_ir {
 ir_function_signature *
 umul64(void *mem_ctx, builtin_available_predicate avail);
 
+ir_function_signature *
+sign64(void *mem_ctx, builtin_available_predicate avail);
+
 }
 
 #endif /* BULITIN_FUNCTIONS_H */
diff --git a/src/compiler/glsl/builtin_int64.h 
b/src/compiler/glsl/builtin_int64.h
index 108da08..c12565d 100644
--- a/src/compiler/glsl/builtin_int64.h
+++ b/src/compiler/glsl/builtin_int64.h
@@ -28,3 +28,29 @@ umul64(void *mem_ctx, builtin_available_predicate avail)
sig->replace_parameters(_parameters);
return sig;
 }
+ir_function_signature *
+sign64(void *mem_ctx, builtin_available_predicate avail)
+{
+   ir_function_signature *const sig =
+  new(mem_ctx) ir_function_signature(glsl_type::ivec2_type, avail);
+   ir_factory body(>body, mem_ctx);
+   sig->is_defined = true;
+
+   exec_list sig_parameters;
+
+   ir_variable *const r0007 = new(mem_ctx) ir_variable(glsl_type::ivec2_type, 
"a", ir_var_function_in);
+   sig_parameters.push_tail(r0007);
+   ir_variable *const r0008 = new(mem_ctx) ir_variable(glsl_type::ivec2_type, 
"result", ir_var_auto);
+   body.emit(r0008);
+   body.emit(assign(r0008, rshift(swizzle_y(r0007), body.constant(int(31))), 
0x02));
+
+   ir_expression *const r0009 = bit_or(swizzle_x(r0007), swizzle_y(r0007));
+   ir_expression *const r000A = nequal(r0009, body.constant(int(0)));
+   ir_expression *const r000B = expr(ir_unop_b2i, r000A);
+   body.emit(assign(r0008, bit_or(swizzle_y(r0008), r000B), 0x01));
+
+   body.emit(ret(r0008));
+
+   sig->replace_parameters(_parameters);
+   return sig;
+}
diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
b/src/compiler/glsl/glcpp/glcpp-parse.y
index ee55377..39a7a89 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -2343,6 +2343,7 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t 
*parser, intmax_t versio
* those functions so that they can be tested.
*/
   if (parser->extension_list->MESA_shader_integer_functions) {
+ add_builtin_define(parser, "__have_builtin_builtin_sign64", 1);
  add_builtin_define(parser, "__have_builtin_builtin_umul64", 1);
   }
}
diff --git a/src/compiler/glsl/int64.glsl b/src/compiler/glsl/int64.glsl
index f5fb010..a2bec01 100644
--- a/src/compiler/glsl/int64.glsl
+++ b/src/compiler/glsl/int64.glsl
@@ -17,3 +17,14 @@ umul64(uvec2 a, uvec2 b)
 
return result;
 }
+
+ivec2
+sign64(ivec2 a)
+{
+   ivec2 result;
+
+   result.y = a.y >> 31;
+   result.x = result.y | int((a.x | a.y) != 0);
+
+   return result;
+}
diff --git a/src/compiler/glsl/udivmod64.h b/src/compiler/glsl/udivmod64.h
new file mode 100644
index 000..b434e45
--- /dev/null
+++ b/src/compiler/glsl/udivmod64.h
@@ -0,0 +1,206 @@
+ir_function_signature *
+udivmod64(void *mem_ctx, ir_factory )
+{
+   ir_function_signature *const sig =
+  new(mem_ctx) ir_function_signature(glsl_type::uvec4_type);
+   exec_list sig_parameters;
+
+   ir_variable *const r0001 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, 
"numer", ir_var_function_in);
+   sig_parameters.push_tail(r0001);
+   ir_variable *const r0002 = new(mem_ctx) ir_variable(glsl_type::uvec2_type, 
"denom",