summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/builtin_int64.h
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2016-10-17 13:55:27 -0700
committerIan Romanick <[email protected]>2017-01-20 15:41:23 -0800
commit6b03b345eb64e15e577bc8b2cf04b314a4c70537 (patch)
treeb472924f541ee22c833aef886065c4410611814e /src/compiler/glsl/builtin_int64.h
parent6c3af043633997633d03e5409939263162076e81 (diff)
glsl: Add "built-in" function for 64-bit integer sign()
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 <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/compiler/glsl/builtin_int64.h')
-rw-r--r--src/compiler/glsl/builtin_int64.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/compiler/glsl/builtin_int64.h b/src/compiler/glsl/builtin_int64.h
index 108da08ee48..c12565d14c7 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(&sig_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(&sig->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(&sig_parameters);
+ return sig;
+}