mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 14:08:04 +00:00
tint: polyfill remainder to handle negative operands
Bug: tint:1802 Change-Id: Ie9baa045feda08523e5ca4f5ce94b6db7d4477e5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119100 Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
78583a14e6
commit
ec20758675
@@ -1,6 +1,11 @@
|
||||
int3 tint_mod(int3 lhs, int rhs) {
|
||||
const int3 r = int3((rhs).xxx);
|
||||
return (lhs % (((r == (0).xxx) | ((lhs == (-2147483648).xxx) & (r == (-1).xxx))) ? (1).xxx : r));
|
||||
const int3 rhs_or_one = (((r == (0).xxx) | ((lhs == (-2147483648).xxx) & (r == (-1).xxx))) ? (1).xxx : r);
|
||||
if (any(((uint3((lhs | rhs_or_one)) & (2147483648u).xxx) != (0u).xxx))) {
|
||||
return (lhs - ((lhs / rhs_or_one) * rhs_or_one));
|
||||
} else {
|
||||
return (lhs % rhs_or_one);
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
int3 tint_mod(int3 lhs, int rhs) {
|
||||
const int3 r = int3((rhs).xxx);
|
||||
return (lhs % (((r == (0).xxx) | ((lhs == (-2147483648).xxx) & (r == (-1).xxx))) ? (1).xxx : r));
|
||||
const int3 rhs_or_one = (((r == (0).xxx) | ((lhs == (-2147483648).xxx) & (r == (-1).xxx))) ? (1).xxx : r);
|
||||
if (any(((uint3((lhs | rhs_or_one)) & (2147483648u).xxx) != (0u).xxx))) {
|
||||
return (lhs - ((lhs / rhs_or_one) * rhs_or_one));
|
||||
} else {
|
||||
return (lhs % rhs_or_one);
|
||||
}
|
||||
}
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
ivec3 tint_mod(ivec3 lhs, int rhs) {
|
||||
ivec3 r = ivec3(rhs);
|
||||
return (lhs % mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1))))))));
|
||||
ivec3 rhs_or_one = mix(r, ivec3(1), bvec3(uvec3(equal(r, ivec3(0))) | uvec3(bvec3(uvec3(equal(lhs, ivec3(-2147483648))) & uvec3(equal(r, ivec3(-1)))))));
|
||||
if (any(notEqual((uvec3((lhs | rhs_or_one)) & uvec3(2147483648u)), uvec3(0u)))) {
|
||||
return (lhs - ((lhs / rhs_or_one) * rhs_or_one));
|
||||
} else {
|
||||
return (lhs % rhs_or_one);
|
||||
}
|
||||
}
|
||||
|
||||
void f() {
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
using namespace metal;
|
||||
int3 tint_mod(int3 lhs, int rhs) {
|
||||
int3 const r = int3(rhs);
|
||||
return (lhs % select(r, int3(1), ((r == int3(0)) | ((lhs == int3((-2147483647 - 1))) & (r == int3(-1))))));
|
||||
int3 const rhs_or_one = select(r, int3(1), ((r == int3(0)) | ((lhs == int3((-2147483647 - 1))) & (r == int3(-1)))));
|
||||
if (any(((uint3((lhs | rhs_or_one)) & uint3(2147483648u)) != uint3(0u)))) {
|
||||
return as_type<int3>((as_type<uint3>(lhs) - as_type<uint3>(as_type<int3>((as_type<uint3>((lhs / rhs_or_one)) * as_type<uint3>(rhs_or_one))))));
|
||||
} else {
|
||||
return (lhs % rhs_or_one);
|
||||
}
|
||||
}
|
||||
|
||||
kernel void f() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 34
|
||||
; Bound: 57
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
@@ -10,41 +10,74 @@
|
||||
OpName %tint_mod "tint_mod"
|
||||
OpName %lhs "lhs"
|
||||
OpName %rhs "rhs"
|
||||
OpName %tint_return_flag "tint_return_flag"
|
||||
OpName %tint_return_value "tint_return_value"
|
||||
OpName %f "f"
|
||||
%int = OpTypeInt 32 1
|
||||
%v3int = OpTypeVector %int 3
|
||||
%1 = OpTypeFunction %v3int %v3int %int
|
||||
%10 = OpConstantNull %v3int
|
||||
%bool = OpTypeBool
|
||||
%_ptr_Function_bool = OpTypePointer Function %bool
|
||||
%11 = OpConstantNull %bool
|
||||
%_ptr_Function_v3int = OpTypePointer Function %v3int
|
||||
%14 = OpConstantNull %v3int
|
||||
%v3bool = OpTypeVector %bool 3
|
||||
%int_n2147483648 = OpConstant %int -2147483648
|
||||
%15 = OpConstantComposite %v3int %int_n2147483648 %int_n2147483648 %int_n2147483648
|
||||
%20 = OpConstantComposite %v3int %int_n2147483648 %int_n2147483648 %int_n2147483648
|
||||
%int_n1 = OpConstant %int -1
|
||||
%18 = OpConstantComposite %v3int %int_n1 %int_n1 %int_n1
|
||||
%23 = OpConstantComposite %v3int %int_n1 %int_n1 %int_n1
|
||||
%int_1 = OpConstant %int 1
|
||||
%23 = OpConstantComposite %v3int %int_1 %int_1 %int_1
|
||||
%28 = OpConstantComposite %v3int %int_1 %int_1 %int_1
|
||||
%uint = OpTypeInt 32 0
|
||||
%v3uint = OpTypeVector %uint 3
|
||||
%uint_2147483648 = OpConstant %uint 2147483648
|
||||
%35 = OpConstantComposite %v3uint %uint_2147483648 %uint_2147483648 %uint_2147483648
|
||||
%37 = OpConstantNull %v3uint
|
||||
%true = OpConstantTrue %bool
|
||||
%void = OpTypeVoid
|
||||
%25 = OpTypeFunction %void
|
||||
%48 = OpTypeFunction %void
|
||||
%int_2 = OpConstant %int 2
|
||||
%int_3 = OpConstant %int 3
|
||||
%31 = OpConstantComposite %v3int %int_1 %int_2 %int_3
|
||||
%54 = OpConstantComposite %v3int %int_1 %int_2 %int_3
|
||||
%int_4 = OpConstant %int 4
|
||||
%tint_mod = OpFunction %v3int None %1
|
||||
%lhs = OpFunctionParameter %v3int
|
||||
%rhs = OpFunctionParameter %int
|
||||
%7 = OpLabel
|
||||
%8 = OpCompositeConstruct %v3int %rhs %rhs %rhs
|
||||
%11 = OpIEqual %v3bool %8 %10
|
||||
%16 = OpIEqual %v3bool %lhs %15
|
||||
%19 = OpIEqual %v3bool %8 %18
|
||||
%20 = OpLogicalAnd %v3bool %16 %19
|
||||
%21 = OpLogicalOr %v3bool %11 %20
|
||||
%9 = OpSelect %v3int %21 %23 %8
|
||||
%24 = OpSRem %v3int %lhs %9
|
||||
OpReturnValue %24
|
||||
%tint_return_flag = OpVariable %_ptr_Function_bool Function %11
|
||||
%tint_return_value = OpVariable %_ptr_Function_v3int Function %14
|
||||
%15 = OpCompositeConstruct %v3int %rhs %rhs %rhs
|
||||
%17 = OpIEqual %v3bool %15 %14
|
||||
%21 = OpIEqual %v3bool %lhs %20
|
||||
%24 = OpIEqual %v3bool %15 %23
|
||||
%25 = OpLogicalAnd %v3bool %21 %24
|
||||
%26 = OpLogicalOr %v3bool %17 %25
|
||||
%16 = OpSelect %v3int %26 %28 %15
|
||||
%33 = OpBitwiseOr %v3int %lhs %16
|
||||
%30 = OpBitcast %v3uint %33
|
||||
%36 = OpBitwiseAnd %v3uint %30 %35
|
||||
%38 = OpINotEqual %v3bool %36 %37
|
||||
%29 = OpAny %bool %38
|
||||
OpSelectionMerge %39 None
|
||||
OpBranchConditional %29 %40 %41
|
||||
%40 = OpLabel
|
||||
OpStore %tint_return_flag %true
|
||||
%43 = OpSDiv %v3int %lhs %16
|
||||
%44 = OpIMul %v3int %43 %16
|
||||
%45 = OpISub %v3int %lhs %44
|
||||
OpStore %tint_return_value %45
|
||||
OpBranch %39
|
||||
%41 = OpLabel
|
||||
OpStore %tint_return_flag %true
|
||||
%46 = OpSRem %v3int %lhs %16
|
||||
OpStore %tint_return_value %46
|
||||
OpBranch %39
|
||||
%39 = OpLabel
|
||||
%47 = OpLoad %v3int %tint_return_value
|
||||
OpReturnValue %47
|
||||
OpFunctionEnd
|
||||
%f = OpFunction %void None %25
|
||||
%28 = OpLabel
|
||||
%33 = OpFunctionCall %v3int %tint_mod %31 %int_4
|
||||
%f = OpFunction %void None %48
|
||||
%51 = OpLabel
|
||||
%56 = OpFunctionCall %v3int %tint_mod %54 %int_4
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
|
||||
Reference in New Issue
Block a user