3 * glsl_compiler --version 400 --dump-builder int64.glsl > builtin_int64.h
5 * Version 4.00+ is required for umulExtended.
8 #extension GL_ARB_gpu_shader_int64: require
9 #extension GL_ARB_shading_language_420pack: require
12 umul64(uvec2 a, uvec2 b)
16 umulExtended(a.x, b.x, result.y, result.x);
17 result.y += a.x * b.y + a.y * b.x;
28 result.x = result.y | int((a.x | a.y) != 0);
34 udivmod64(uvec2 n, uvec2 d)
36 uvec2 quot = uvec2(0U, 0U);
37 int log2_denom = findMSB(d.y) + 32;
39 /* If the upper 32 bits of denom are non-zero, it is impossible for shifts
40 * greater than 32 bits to occur. If the upper 32 bits of the numerator
41 * are zero, it is impossible for (denom << [63, 32]) <= numer unless
44 if (d.y == 0 && n.y >= d.x) {
45 log2_denom = findMSB(d.x);
47 /* Since the upper 32 bits of denom are zero, log2_denom <= 31 and we
48 * don't have to compare log2_denom inside the loop as is done in the
49 * general case (below).
51 for (int i = 31; i >= 1; i--) {
52 if (log2_denom <= 31 - i && (d.x << i) <= n.y) {
58 /* log2_denom is always <= 31, so manually peel the last loop
67 uint64_t d64 = packUint2x32(d);
68 uint64_t n64 = packUint2x32(n);
69 for (int i = 31; i >= 1; i--) {
70 if (log2_denom <= 63 - i && (d64 << i) <= n64) {
76 /* log2_denom is always <= 63, so manually peel the last loop
84 return uvec4(quot, unpackUint2x32(n64));
88 udiv64(uvec2 n, uvec2 d)
90 return udivmod64(n, d).xy;
94 idiv64(ivec2 _n, ivec2 _d)
96 const bool negate = (_n.y < 0) != (_d.y < 0);
97 uvec2 n = unpackUint2x32(uint64_t(abs(packInt2x32(_n))));
98 uvec2 d = unpackUint2x32(uint64_t(abs(packInt2x32(_d))));
100 uvec2 quot = udivmod64(n, d).xy;
102 return negate ? unpackInt2x32(-int64_t(packUint2x32(quot))) : ivec2(quot);
106 umod64(uvec2 n, uvec2 d)
108 return udivmod64(n, d).zw;
112 imod64(ivec2 _n, ivec2 _d)
114 const bool negate = (_n.y < 0) != (_d.y < 0);
115 uvec2 n = unpackUint2x32(uint64_t(abs(packInt2x32(_n))));
116 uvec2 d = unpackUint2x32(uint64_t(abs(packInt2x32(_d))));
118 uvec2 rem = udivmod64(n, d).zw;
120 return negate ? unpackInt2x32(-int64_t(packUint2x32(rem))) : ivec2(rem);