summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/int64.glsl
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2016-10-18 16:46:35 -0700
committerIan Romanick <[email protected]>2017-01-20 15:41:23 -0800
commit695b04f7eb24bff108e8d85c476adb5cf9de6f2d (patch)
treecdb68980096ab9f21fba88aa3018ac9a1f26de45 /src/compiler/glsl/int64.glsl
parent82c31f3eb957a0089773db47a4aca8bf3eb4a29e (diff)
glsl: Add "built-in" functions to do 64%64 => 64 modulus
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! v2: Use function inlining. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/compiler/glsl/int64.glsl')
-rw-r--r--src/compiler/glsl/int64.glsl18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/compiler/glsl/int64.glsl b/src/compiler/glsl/int64.glsl
index 84e80ee349b..b1036e379c9 100644
--- a/src/compiler/glsl/int64.glsl
+++ b/src/compiler/glsl/int64.glsl
@@ -101,3 +101,21 @@ idiv64(ivec2 _n, ivec2 _d)
return negate ? unpackInt2x32(-int64_t(packUint2x32(quot))) : ivec2(quot);
}
+
+uvec2
+umod64(uvec2 n, uvec2 d)
+{
+ return udivmod64(n, d).zw;
+}
+
+ivec2
+imod64(ivec2 _n, ivec2 _d)
+{
+ const bool negate = (_n.y < 0) != (_d.y < 0);
+ uvec2 n = unpackUint2x32(uint64_t(abs(packInt2x32(_n))));
+ uvec2 d = unpackUint2x32(uint64_t(abs(packInt2x32(_d))));
+
+ uvec2 rem = udivmod64(n, d).zy;
+
+ return negate ? unpackInt2x32(-int64_t(packUint2x32(rem))) : ivec2(rem);
+}