tint/transform: Implement div / mod polyfill

Prevents UB for divide-by-zero and integer overflow when dividing

Fixed: tint:1349
Change-Id: Ieef66d27d7aec3011628ced076b2bccc7770a8af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108925
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2022-11-09 22:04:11 +00:00
committed by Dawn LUCI CQ
parent 9418152d08
commit 46ee63933c
427 changed files with 7255 additions and 3789 deletions

View File

@@ -25,8 +25,11 @@ int bar() {
void main() {
S x = (S)0;
const int tint_symbol_2 = foo();
const int tint_symbol_save = tint_symbol_2;
const int tint_symbol_save = foo();
const int tint_symbol_1 = bar();
set_int4(x.a[tint_symbol_save], tint_symbol_1, (x.a[tint_symbol_save][tint_symbol_1] + 5));
{
int4 tint_symbol_3[4] = x.a;
set_int4(tint_symbol_3[tint_symbol_save], tint_symbol_1, (x.a[tint_symbol_save][tint_symbol_1] + 5));
x.a = tint_symbol_3;
}
}

View File

@@ -25,8 +25,11 @@ int bar() {
void main() {
S x = (S)0;
const int tint_symbol_2 = foo();
const int tint_symbol_save = tint_symbol_2;
const int tint_symbol_save = foo();
const int tint_symbol_1 = bar();
set_int4(x.a[tint_symbol_save], tint_symbol_1, (x.a[tint_symbol_save][tint_symbol_1] + 5));
{
int4 tint_symbol_3[4] = x.a;
set_int4(tint_symbol_3[tint_symbol_save], tint_symbol_1, (x.a[tint_symbol_save][tint_symbol_1] + 5));
x.a = tint_symbol_3;
}
}

View File

@@ -3,14 +3,22 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
int tint_mod(int lhs, int rhs) {
return (lhs % (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
static int a = 0;
static float b = 0.0f;
void foo(int maybe_zero) {
a = (a / 1);
a = (a % 1);
a = (a / (maybe_zero == 0 ? 1 : maybe_zero));
a = (a % (maybe_zero == 0 ? 1 : maybe_zero));
a = tint_div(a, 0);
a = tint_mod(a, 0);
a = tint_div(a, maybe_zero);
a = tint_mod(a, maybe_zero);
b = (b / 0.0f);
b = (b % 0.0f);
b = (b / float(maybe_zero));

View File

@@ -3,14 +3,22 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
int tint_mod(int lhs, int rhs) {
return (lhs % (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
static int a = 0;
static float b = 0.0f;
void foo(int maybe_zero) {
a = (a / 1);
a = (a % 1);
a = (a / (maybe_zero == 0 ? 1 : maybe_zero));
a = (a % (maybe_zero == 0 ? 1 : maybe_zero));
a = tint_div(a, 0);
a = tint_mod(a, 0);
a = tint_div(a, maybe_zero);
a = tint_mod(a, maybe_zero);
b = (b / 0.0f);
b = (b % 0.0f);
b = (b / float(maybe_zero));

View File

@@ -9,13 +9,21 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
int tint_mod(int lhs, int rhs) {
return (lhs % (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
int a = 0;
float b = 0.0f;
void foo(int maybe_zero) {
a = (a / 0);
a = (a % 0);
a = (a / maybe_zero);
a = (a % maybe_zero);
a = tint_div(a, 0);
a = tint_mod(a, 0);
a = tint_div(a, maybe_zero);
a = tint_mod(a, maybe_zero);
b = (b / 0.0f);
b = tint_float_modulo(b, 0.0f);
b = (b / float(maybe_zero));

View File

@@ -1,13 +1,21 @@
#include <metal_stdlib>
using namespace metal;
int tint_div(int lhs, int rhs) {
return (lhs / select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
int tint_mod(int lhs, int rhs) {
return (lhs % select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
void foo(int maybe_zero) {
thread int tint_symbol = 0;
thread float tint_symbol_1 = 0.0f;
tint_symbol = (tint_symbol / 0);
tint_symbol = (tint_symbol % 0);
tint_symbol = (tint_symbol / maybe_zero);
tint_symbol = (tint_symbol % maybe_zero);
tint_symbol = tint_div(tint_symbol, 0);
tint_symbol = tint_mod(tint_symbol, 0);
tint_symbol = tint_div(tint_symbol, maybe_zero);
tint_symbol = tint_mod(tint_symbol, maybe_zero);
tint_symbol_1 = (tint_symbol_1 / 0.0f);
tint_symbol_1 = fmod(tint_symbol_1, 0.0f);
tint_symbol_1 = (tint_symbol_1 / float(maybe_zero));

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 35
; Bound: 62
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -10,6 +10,12 @@
OpName %a "a"
OpName %b "b"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_div "tint_div"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %tint_mod "tint_mod"
OpName %lhs_0 "lhs"
OpName %rhs_0 "rhs"
OpName %foo "foo"
OpName %maybe_zero "maybe_zero"
%int = OpTypeInt 32 1
@@ -22,39 +28,70 @@
%b = OpVariable %_ptr_Private_float Private %8
%void = OpTypeVoid
%9 = OpTypeFunction %void
%13 = OpTypeFunction %void %int
%13 = OpTypeFunction %int %int %int
%bool = OpTypeBool
%int_n2147483648 = OpConstant %int -2147483648
%int_n1 = OpConstant %int -1
%int_1 = OpConstant %int 1
%40 = OpTypeFunction %void %int
%unused_entry_point = OpFunction %void None %9
%12 = OpLabel
OpReturn
OpFunctionEnd
%foo = OpFunction %void None %13
%tint_div = OpFunction %int None %13
%lhs = OpFunctionParameter %int
%rhs = OpFunctionParameter %int
%17 = OpLabel
%19 = OpIEqual %bool %rhs %4
%22 = OpIEqual %bool %lhs %int_n2147483648
%24 = OpIEqual %bool %rhs %int_n1
%25 = OpLogicalAnd %bool %22 %24
%26 = OpLogicalOr %bool %19 %25
%18 = OpSelect %int %26 %int_1 %rhs
%28 = OpSDiv %int %lhs %18
OpReturnValue %28
OpFunctionEnd
%tint_mod = OpFunction %int None %13
%lhs_0 = OpFunctionParameter %int
%rhs_0 = OpFunctionParameter %int
%32 = OpLabel
%34 = OpIEqual %bool %rhs_0 %4
%35 = OpIEqual %bool %lhs_0 %int_n2147483648
%36 = OpIEqual %bool %rhs_0 %int_n1
%37 = OpLogicalAnd %bool %35 %36
%38 = OpLogicalOr %bool %34 %37
%33 = OpSelect %int %38 %int_1 %rhs_0
%39 = OpSMod %int %lhs_0 %33
OpReturnValue %39
OpFunctionEnd
%foo = OpFunction %void None %40
%maybe_zero = OpFunctionParameter %int
%16 = OpLabel
%17 = OpLoad %int %a
%18 = OpSDiv %int %17 %4
OpStore %a %18
%19 = OpLoad %int %a
%20 = OpSMod %int %19 %4
OpStore %a %20
%21 = OpLoad %int %a
%22 = OpSDiv %int %21 %maybe_zero
OpStore %a %22
%23 = OpLoad %int %a
%24 = OpSMod %int %23 %maybe_zero
OpStore %a %24
%25 = OpLoad %float %b
%26 = OpFDiv %float %25 %8
OpStore %b %26
%27 = OpLoad %float %b
%28 = OpFRem %float %27 %8
OpStore %b %28
%29 = OpLoad %float %b
%30 = OpConvertSToF %float %maybe_zero
%31 = OpFDiv %float %29 %30
OpStore %b %31
%32 = OpLoad %float %b
%33 = OpConvertSToF %float %maybe_zero
%34 = OpFRem %float %32 %33
OpStore %b %34
%43 = OpLabel
%45 = OpLoad %int %a
%44 = OpFunctionCall %int %tint_div %45 %4
OpStore %a %44
%47 = OpLoad %int %a
%46 = OpFunctionCall %int %tint_mod %47 %4
OpStore %a %46
%49 = OpLoad %int %a
%48 = OpFunctionCall %int %tint_div %49 %maybe_zero
OpStore %a %48
%51 = OpLoad %int %a
%50 = OpFunctionCall %int %tint_mod %51 %maybe_zero
OpStore %a %50
%52 = OpLoad %float %b
%53 = OpFDiv %float %52 %8
OpStore %b %53
%54 = OpLoad %float %b
%55 = OpFRem %float %54 %8
OpStore %b %55
%56 = OpLoad %float %b
%57 = OpConvertSToF %float %maybe_zero
%58 = OpFDiv %float %56 %57
OpStore %b %58
%59 = OpLoad %float %b
%60 = OpConvertSToF %float %maybe_zero
%61 = OpFRem %float %59 %60
OpStore %b %61
OpReturn
OpFunctionEnd

View File

@@ -23,20 +23,18 @@ int idx3() {
void foo() {
float a[4] = (float[4])0;
const int tint_symbol_2 = idx1();
const int tint_symbol_save = tint_symbol_2;
const int tint_symbol_save = idx1();
{
a[tint_symbol_save] = (a[tint_symbol_save] * 2.0f);
while (true) {
const int tint_symbol_3 = idx2();
if (!((a[tint_symbol_3] < 10.0f))) {
const int tint_symbol_2 = idx2();
if (!((a[tint_symbol_2] < 10.0f))) {
break;
}
{
}
{
const int tint_symbol_4 = idx3();
const int tint_symbol_1_save = tint_symbol_4;
const int tint_symbol_1_save = idx3();
a[tint_symbol_1_save] = (a[tint_symbol_1_save] + 1.0f);
}
}

View File

@@ -23,20 +23,18 @@ int idx3() {
void foo() {
float a[4] = (float[4])0;
const int tint_symbol_2 = idx1();
const int tint_symbol_save = tint_symbol_2;
const int tint_symbol_save = idx1();
{
a[tint_symbol_save] = (a[tint_symbol_save] * 2.0f);
while (true) {
const int tint_symbol_3 = idx2();
if (!((a[tint_symbol_3] < 10.0f))) {
const int tint_symbol_2 = idx2();
if (!((a[tint_symbol_2] < 10.0f))) {
break;
}
{
}
{
const int tint_symbol_4 = idx3();
const int tint_symbol_1_save = tint_symbol_4;
const int tint_symbol_1_save = idx3();
a[tint_symbol_1_save] = (a[tint_symbol_1_save] + 1.0f);
}
}

View File

@@ -3,11 +3,15 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
void foo() {
int a = 0;
float4 b = float4(0.0f, 0.0f, 0.0f, 0.0f);
float2x2 c = float2x2(0.0f, 0.0f, 0.0f, 0.0f);
a = (a / 2);
a = tint_div(a, 2);
b = mul(float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx), b);
c = (c * 2.0f);
}

View File

@@ -3,11 +3,15 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
void foo() {
int a = 0;
float4 b = float4(0.0f, 0.0f, 0.0f, 0.0f);
float2x2 c = float2x2(0.0f, 0.0f, 0.0f, 0.0f);
a = (a / 2);
a = tint_div(a, 2);
b = mul(float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx), b);
c = (c * 2.0f);
}

View File

@@ -4,11 +4,15 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
void foo() {
int a = 0;
vec4 b = vec4(0.0f, 0.0f, 0.0f, 0.0f);
mat2 c = mat2(0.0f, 0.0f, 0.0f, 0.0f);
a = (a / 2);
a = tint_div(a, 2);
b = (b * mat4(vec4(0.0f), vec4(0.0f), vec4(0.0f), vec4(0.0f)));
c = (c * 2.0f);
}

View File

@@ -1,11 +1,15 @@
#include <metal_stdlib>
using namespace metal;
int tint_div(int lhs, int rhs) {
return (lhs / select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
void foo() {
int a = 0;
float4 b = 0.0f;
float2x2 c = float2x2(0.0f);
a = (a / 2);
a = tint_div(a, 2);
b = (b * float4x4(float4(0.0f), float4(0.0f), float4(0.0f), float4(0.0f)));
c = (c * 2.0f);
}

View File

@@ -1,13 +1,16 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 31
; Bound: 47
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %tint_div "tint_div"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
OpName %a "a"
OpName %b "b"
@@ -15,37 +18,55 @@
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%5 = OpTypeFunction %int %int %int
%12 = OpConstantNull %int
%bool = OpTypeBool
%int_n2147483648 = OpConstant %int -2147483648
%int_n1 = OpConstant %int -1
%int_1 = OpConstant %int 1
%_ptr_Function_int = OpTypePointer Function %int
%10 = OpConstantNull %int
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Function_v4float = OpTypePointer Function %v4float
%15 = OpConstantNull %v4float
%31 = OpConstantNull %v4float
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_ptr_Function_mat2v2float = OpTypePointer Function %mat2v2float
%20 = OpConstantNull %mat2v2float
%36 = OpConstantNull %mat2v2float
%int_2 = OpConstant %int 2
%mat4v4float = OpTypeMatrix %v4float 4
%26 = OpConstantNull %mat4v4float
%42 = OpConstantNull %mat4v4float
%float_2 = OpConstant %float 2
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%tint_div = OpFunction %int None %5
%lhs = OpFunctionParameter %int
%rhs = OpFunctionParameter %int
%10 = OpLabel
%13 = OpIEqual %bool %rhs %12
%16 = OpIEqual %bool %lhs %int_n2147483648
%18 = OpIEqual %bool %rhs %int_n1
%19 = OpLogicalAnd %bool %16 %18
%20 = OpLogicalOr %bool %13 %19
%11 = OpSelect %int %20 %int_1 %rhs
%22 = OpSDiv %int %lhs %11
OpReturnValue %22
OpFunctionEnd
%foo = OpFunction %void None %1
%6 = OpLabel
%a = OpVariable %_ptr_Function_int Function %10
%b = OpVariable %_ptr_Function_v4float Function %15
%c = OpVariable %_ptr_Function_mat2v2float Function %20
%21 = OpLoad %int %a
%23 = OpSDiv %int %21 %int_2
OpStore %a %23
%24 = OpLoad %v4float %b
%27 = OpVectorTimesMatrix %v4float %24 %26
OpStore %b %27
%28 = OpLoad %mat2v2float %c
%30 = OpMatrixTimesScalar %mat2v2float %28 %float_2
OpStore %c %30
%24 = OpLabel
%a = OpVariable %_ptr_Function_int Function %12
%b = OpVariable %_ptr_Function_v4float Function %31
%c = OpVariable %_ptr_Function_mat2v2float Function %36
%38 = OpLoad %int %a
%37 = OpFunctionCall %int %tint_div %38 %int_2
OpStore %a %37
%40 = OpLoad %v4float %b
%43 = OpVectorTimesMatrix %v4float %40 %42
OpStore %b %43
%44 = OpLoad %mat2v2float %c
%46 = OpMatrixTimesScalar %mat2v2float %44 %float_2
OpStore %c %46
OpReturn
OpFunctionEnd

View File

@@ -3,12 +3,16 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
static int a = 0;
static float4 b = float4(0.0f, 0.0f, 0.0f, 0.0f);
static float2x2 c = float2x2(0.0f, 0.0f, 0.0f, 0.0f);
void foo() {
a = (a / 2);
a = tint_div(a, 2);
b = mul(float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx), b);
c = (c * 2.0f);
}

View File

@@ -3,12 +3,16 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
static int a = 0;
static float4 b = float4(0.0f, 0.0f, 0.0f, 0.0f);
static float2x2 c = float2x2(0.0f, 0.0f, 0.0f, 0.0f);
void foo() {
a = (a / 2);
a = tint_div(a, 2);
b = mul(float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx), b);
c = (c * 2.0f);
}

View File

@@ -4,11 +4,15 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
int a = 0;
vec4 b = vec4(0.0f, 0.0f, 0.0f, 0.0f);
mat2 c = mat2(0.0f, 0.0f, 0.0f, 0.0f);
void foo() {
a = (a / 2);
a = tint_div(a, 2);
b = (b * mat4(vec4(0.0f), vec4(0.0f), vec4(0.0f), vec4(0.0f)));
c = (c * 2.0f);
}

View File

@@ -1,11 +1,15 @@
#include <metal_stdlib>
using namespace metal;
int tint_div(int lhs, int rhs) {
return (lhs / select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
void foo() {
thread int tint_symbol = 0;
thread float4 tint_symbol_1 = 0.0f;
thread float2x2 tint_symbol_2 = float2x2(0.0f);
tint_symbol = (tint_symbol / 2);
tint_symbol = tint_div(tint_symbol, 2);
tint_symbol_1 = (tint_symbol_1 * float4x4(float4(0.0f), float4(0.0f), float4(0.0f), float4(0.0f)));
tint_symbol_2 = (tint_symbol_2 * 2.0f);
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 31
; Bound: 47
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -11,6 +11,9 @@
OpName %b "b"
OpName %c "c"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_div "tint_div"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
%int = OpTypeInt 32 1
%_ptr_Private_int = OpTypePointer Private %int
@@ -28,24 +31,42 @@
%c = OpVariable %_ptr_Private_mat2v2float Private %14
%void = OpTypeVoid
%15 = OpTypeFunction %void
%19 = OpTypeFunction %int %int %int
%bool = OpTypeBool
%int_n2147483648 = OpConstant %int -2147483648
%int_n1 = OpConstant %int -1
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%mat4v4float = OpTypeMatrix %v4float 4
%26 = OpConstantNull %mat4v4float
%42 = OpConstantNull %mat4v4float
%float_2 = OpConstant %float 2
%unused_entry_point = OpFunction %void None %15
%18 = OpLabel
OpReturn
OpFunctionEnd
%tint_div = OpFunction %int None %19
%lhs = OpFunctionParameter %int
%rhs = OpFunctionParameter %int
%23 = OpLabel
%25 = OpIEqual %bool %rhs %4
%28 = OpIEqual %bool %lhs %int_n2147483648
%30 = OpIEqual %bool %rhs %int_n1
%31 = OpLogicalAnd %bool %28 %30
%32 = OpLogicalOr %bool %25 %31
%24 = OpSelect %int %32 %int_1 %rhs
%34 = OpSDiv %int %lhs %24
OpReturnValue %34
OpFunctionEnd
%foo = OpFunction %void None %15
%20 = OpLabel
%21 = OpLoad %int %a
%23 = OpSDiv %int %21 %int_2
OpStore %a %23
%24 = OpLoad %v4float %b
%27 = OpVectorTimesMatrix %v4float %24 %26
OpStore %b %27
%28 = OpLoad %mat2v2float %c
%30 = OpMatrixTimesScalar %mat2v2float %28 %float_2
OpStore %c %30
%36 = OpLabel
%38 = OpLoad %int %a
%37 = OpFunctionCall %int %tint_div %38 %int_2
OpStore %a %37
%40 = OpLoad %v4float %b
%43 = OpVectorTimesMatrix %v4float %40 %42
OpStore %b %43
%44 = OpLoad %mat2v2float %c
%46 = OpMatrixTimesScalar %mat2v2float %44 %float_2
OpStore %c %46
OpReturn
OpFunctionEnd

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store(0u, asuint((asint(v.Load(0u)) / 2)));
const int tint_symbol = tint_div(asint(v.Load(0u)), 2);
v.Store(0u, asuint(tint_symbol));
}

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store(0u, asuint((asint(v.Load(0u)) / 2)));
const int tint_symbol = tint_div(asint(v.Load(0u)), 2);
v.Store(0u, asuint(tint_symbol));
}

View File

@@ -4,6 +4,10 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
struct S {
int a;
};
@@ -13,6 +17,7 @@ layout(binding = 0, std430) buffer v_block_ssbo {
} v;
void foo() {
v.inner.a = (v.inner.a / 2);
int tint_symbol = tint_div(v.inner.a, 2);
v.inner.a = tint_symbol;
}

View File

@@ -1,11 +1,16 @@
#include <metal_stdlib>
using namespace metal;
int tint_div(int lhs, int rhs) {
return (lhs / select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
struct S {
/* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a / 2);
void foo(device S* const tint_symbol_1) {
int const tint_symbol = tint_div((*(tint_symbol_1)).a, 2);
(*(tint_symbol_1)).a = tint_symbol;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 20
; Bound: 37
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,6 +13,9 @@
OpMemberName %S 0 "a"
OpName %v "v"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_div "tint_div"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
OpDecorate %v_block Block
OpMemberDecorate %v_block 0 Offset 0
@@ -26,6 +29,12 @@
%v = OpVariable %_ptr_StorageBuffer_v_block StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%10 = OpTypeFunction %int %int %int
%16 = OpConstantNull %int
%bool = OpTypeBool
%int_n2147483648 = OpConstant %int -2147483648
%int_n1 = OpConstant %int -1
%int_1 = OpConstant %int 1
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
@@ -34,12 +43,25 @@
%9 = OpLabel
OpReturn
OpFunctionEnd
%tint_div = OpFunction %int None %10
%lhs = OpFunctionParameter %int
%rhs = OpFunctionParameter %int
%14 = OpLabel
%17 = OpIEqual %bool %rhs %16
%20 = OpIEqual %bool %lhs %int_n2147483648
%22 = OpIEqual %bool %rhs %int_n1
%23 = OpLogicalAnd %bool %20 %22
%24 = OpLogicalOr %bool %17 %23
%15 = OpSelect %int %24 %int_1 %rhs
%26 = OpSDiv %int %lhs %15
OpReturnValue %26
OpFunctionEnd
%foo = OpFunction %void None %6
%11 = OpLabel
%15 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
%16 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
%17 = OpLoad %int %16
%19 = OpSDiv %int %17 %int_2
OpStore %15 %19
%28 = OpLabel
%33 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
%34 = OpLoad %int %33
%29 = OpFunctionCall %int %tint_div %34 %int_2
%36 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
OpStore %36 %29
OpReturn
OpFunctionEnd

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int tint_mod(int lhs, int rhs) {
return (lhs % (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store(0u, asuint((asint(v.Load(0u)) % 2)));
const int tint_symbol = tint_mod(asint(v.Load(0u)), 2);
v.Store(0u, asuint(tint_symbol));
}

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int tint_mod(int lhs, int rhs) {
return (lhs % (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store(0u, asuint((asint(v.Load(0u)) % 2)));
const int tint_symbol = tint_mod(asint(v.Load(0u)), 2);
v.Store(0u, asuint(tint_symbol));
}

View File

@@ -4,6 +4,10 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int tint_mod(int lhs, int rhs) {
return (lhs % (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
struct S {
int a;
};
@@ -13,6 +17,7 @@ layout(binding = 0, std430) buffer v_block_ssbo {
} v;
void foo() {
v.inner.a = (v.inner.a % 2);
int tint_symbol = tint_mod(v.inner.a, 2);
v.inner.a = tint_symbol;
}

View File

@@ -1,11 +1,16 @@
#include <metal_stdlib>
using namespace metal;
int tint_mod(int lhs, int rhs) {
return (lhs % select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
struct S {
/* 0x0000 */ int a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a % 2);
void foo(device S* const tint_symbol_1) {
int const tint_symbol = tint_mod((*(tint_symbol_1)).a, 2);
(*(tint_symbol_1)).a = tint_symbol;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 20
; Bound: 37
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,6 +13,9 @@
OpMemberName %S 0 "a"
OpName %v "v"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_mod "tint_mod"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
OpDecorate %v_block Block
OpMemberDecorate %v_block 0 Offset 0
@@ -26,6 +29,12 @@
%v = OpVariable %_ptr_StorageBuffer_v_block StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%10 = OpTypeFunction %int %int %int
%16 = OpConstantNull %int
%bool = OpTypeBool
%int_n2147483648 = OpConstant %int -2147483648
%int_n1 = OpConstant %int -1
%int_1 = OpConstant %int 1
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
@@ -34,12 +43,25 @@
%9 = OpLabel
OpReturn
OpFunctionEnd
%tint_mod = OpFunction %int None %10
%lhs = OpFunctionParameter %int
%rhs = OpFunctionParameter %int
%14 = OpLabel
%17 = OpIEqual %bool %rhs %16
%20 = OpIEqual %bool %lhs %int_n2147483648
%22 = OpIEqual %bool %rhs %int_n1
%23 = OpLogicalAnd %bool %20 %22
%24 = OpLogicalOr %bool %17 %23
%15 = OpSelect %int %24 %int_1 %rhs
%26 = OpSMod %int %lhs %15
OpReturnValue %26
OpFunctionEnd
%foo = OpFunction %void None %6
%11 = OpLabel
%15 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
%16 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
%17 = OpLoad %int %16
%19 = OpSMod %int %17 %int_2
OpStore %15 %19
%28 = OpLabel
%33 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
%34 = OpLoad %int %33
%29 = OpFunctionCall %int %tint_mod %34 %int_2
%36 = OpAccessChain %_ptr_StorageBuffer_int %v %uint_0 %uint_0
OpStore %36 %29
OpReturn
OpFunctionEnd

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int4 tint_div(int4 lhs, int4 rhs) {
return (lhs / (((rhs == (0).xxxx) | ((lhs == (-2147483648).xxxx) & (rhs == (-1).xxxx))) ? (1).xxxx : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store4(0u, asuint((asint(v.Load4(0u)) / (2).xxxx)));
const int4 tint_symbol = tint_div(asint(v.Load4(0u)), (2).xxxx);
v.Store4(0u, asuint(tint_symbol));
}

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int4 tint_div(int4 lhs, int4 rhs) {
return (lhs / (((rhs == (0).xxxx) | ((lhs == (-2147483648).xxxx) & (rhs == (-1).xxxx))) ? (1).xxxx : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store4(0u, asuint((asint(v.Load4(0u)) / (2).xxxx)));
const int4 tint_symbol = tint_div(asint(v.Load4(0u)), (2).xxxx);
v.Store4(0u, asuint(tint_symbol));
}

View File

@@ -4,6 +4,10 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
ivec4 tint_div(ivec4 lhs, ivec4 rhs) {
return (lhs / mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(rhs, ivec4(-1))))))));
}
struct S {
ivec4 a;
};
@@ -13,6 +17,7 @@ layout(binding = 0, std430) buffer v_block_ssbo {
} v;
void foo() {
v.inner.a = (v.inner.a / ivec4(2));
ivec4 tint_symbol = tint_div(v.inner.a, ivec4(2));
v.inner.a = tint_symbol;
}

View File

@@ -1,11 +1,16 @@
#include <metal_stdlib>
using namespace metal;
int4 tint_div(int4 lhs, int4 rhs) {
return (lhs / select(rhs, int4(1), ((rhs == int4(0)) | ((lhs == int4((-2147483647 - 1))) & (rhs == int4(-1))))));
}
struct S {
/* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a / int4(2));
void foo(device S* const tint_symbol_1) {
int4 const tint_symbol = tint_div((*(tint_symbol_1)).a, int4(2));
(*(tint_symbol_1)).a = tint_symbol;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 22
; Bound: 43
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,6 +13,9 @@
OpMemberName %S 0 "a"
OpName %v "v"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_div "tint_div"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
OpDecorate %v_block Block
OpMemberDecorate %v_block 0 Offset 0
@@ -27,21 +30,44 @@
%v = OpVariable %_ptr_StorageBuffer_v_block StorageBuffer
%void = OpTypeVoid
%7 = OpTypeFunction %void
%11 = OpTypeFunction %v4int %v4int %v4int
%17 = OpConstantNull %v4int
%bool = OpTypeBool
%v4bool = OpTypeVector %bool 4
%int_n2147483648 = OpConstant %int -2147483648
%22 = OpConstantComposite %v4int %int_n2147483648 %int_n2147483648 %int_n2147483648 %int_n2147483648
%int_n1 = OpConstant %int -1
%25 = OpConstantComposite %v4int %int_n1 %int_n1 %int_n1 %int_n1
%int_1 = OpConstant %int 1
%30 = OpConstantComposite %v4int %int_1 %int_1 %int_1 %int_1
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_v4int = OpTypePointer StorageBuffer %v4int
%int_2 = OpConstant %int 2
%20 = OpConstantComposite %v4int %int_2 %int_2 %int_2 %int_2
%41 = OpConstantComposite %v4int %int_2 %int_2 %int_2 %int_2
%unused_entry_point = OpFunction %void None %7
%10 = OpLabel
OpReturn
OpFunctionEnd
%tint_div = OpFunction %v4int None %11
%lhs = OpFunctionParameter %v4int
%rhs = OpFunctionParameter %v4int
%15 = OpLabel
%18 = OpIEqual %v4bool %rhs %17
%23 = OpIEqual %v4bool %lhs %22
%26 = OpIEqual %v4bool %rhs %25
%27 = OpLogicalAnd %v4bool %23 %26
%28 = OpLogicalOr %v4bool %18 %27
%16 = OpSelect %v4int %28 %30 %rhs
%31 = OpSDiv %v4int %lhs %16
OpReturnValue %31
OpFunctionEnd
%foo = OpFunction %void None %7
%12 = OpLabel
%16 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%17 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%18 = OpLoad %v4int %17
%21 = OpSDiv %v4int %18 %20
OpStore %16 %21
%33 = OpLabel
%38 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%39 = OpLoad %v4int %38
%34 = OpFunctionCall %v4int %tint_div %39 %41
%42 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
OpStore %42 %34
OpReturn
OpFunctionEnd

View File

@@ -3,8 +3,14 @@ void unused_entry_point() {
return;
}
int4 tint_mod(int4 lhs, int rhs) {
const int4 r = int4((rhs).xxxx);
return (lhs % (((r == (0).xxxx) | ((lhs == (-2147483648).xxxx) & (r == (-1).xxxx))) ? (1).xxxx : r));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store4(0u, asuint((asint(v.Load4(0u)) % 2)));
const int4 tint_symbol = tint_mod(asint(v.Load4(0u)), 2);
v.Store4(0u, asuint(tint_symbol));
}

View File

@@ -3,8 +3,14 @@ void unused_entry_point() {
return;
}
int4 tint_mod(int4 lhs, int rhs) {
const int4 r = int4((rhs).xxxx);
return (lhs % (((r == (0).xxxx) | ((lhs == (-2147483648).xxxx) & (r == (-1).xxxx))) ? (1).xxxx : r));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store4(0u, asuint((asint(v.Load4(0u)) % 2)));
const int4 tint_symbol = tint_mod(asint(v.Load4(0u)), 2);
v.Store4(0u, asuint(tint_symbol));
}

View File

@@ -4,6 +4,11 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
ivec4 tint_mod(ivec4 lhs, int rhs) {
ivec4 r = ivec4(rhs);
return (lhs % mix(r, ivec4(1), bvec4(uvec4(equal(r, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(r, ivec4(-1))))))));
}
struct S {
ivec4 a;
};
@@ -13,6 +18,7 @@ layout(binding = 0, std430) buffer v_block_ssbo {
} v;
void foo() {
v.inner.a = (v.inner.a % 2);
ivec4 tint_symbol = tint_mod(v.inner.a, 2);
v.inner.a = tint_symbol;
}

View File

@@ -1,11 +1,17 @@
#include <metal_stdlib>
using namespace metal;
int4 tint_mod(int4 lhs, int rhs) {
int4 const r = int4(rhs);
return (lhs % select(r, int4(1), ((r == int4(0)) | ((lhs == int4((-2147483647 - 1))) & (r == int4(-1))))));
}
struct S {
/* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a % 2);
void foo(device S* const tint_symbol_1) {
int4 const tint_symbol = tint_mod((*(tint_symbol_1)).a, 2);
(*(tint_symbol_1)).a = tint_symbol;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 25
; Bound: 43
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,6 +13,9 @@
OpMemberName %S 0 "a"
OpName %v "v"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_mod "tint_mod"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
OpDecorate %v_block Block
OpMemberDecorate %v_block 0 Offset 0
@@ -27,24 +30,44 @@
%v = OpVariable %_ptr_StorageBuffer_v_block StorageBuffer
%void = OpTypeVoid
%7 = OpTypeFunction %void
%11 = OpTypeFunction %v4int %v4int %int
%18 = OpConstantNull %v4int
%bool = OpTypeBool
%v4bool = OpTypeVector %bool 4
%int_n2147483648 = OpConstant %int -2147483648
%23 = OpConstantComposite %v4int %int_n2147483648 %int_n2147483648 %int_n2147483648 %int_n2147483648
%int_n1 = OpConstant %int -1
%26 = OpConstantComposite %v4int %int_n1 %int_n1 %int_n1 %int_n1
%int_1 = OpConstant %int 1
%31 = OpConstantComposite %v4int %int_1 %int_1 %int_1 %int_1
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_v4int = OpTypePointer StorageBuffer %v4int
%int_2 = OpConstant %int 2
%_ptr_Function_v4int = OpTypePointer Function %v4int
%23 = OpConstantNull %v4int
%unused_entry_point = OpFunction %void None %7
%10 = OpLabel
OpReturn
OpFunctionEnd
%tint_mod = OpFunction %v4int None %11
%lhs = OpFunctionParameter %v4int
%rhs = OpFunctionParameter %int
%15 = OpLabel
%16 = OpCompositeConstruct %v4int %rhs %rhs %rhs %rhs
%19 = OpIEqual %v4bool %16 %18
%24 = OpIEqual %v4bool %lhs %23
%27 = OpIEqual %v4bool %16 %26
%28 = OpLogicalAnd %v4bool %24 %27
%29 = OpLogicalOr %v4bool %19 %28
%17 = OpSelect %v4int %29 %31 %16
%32 = OpSMod %v4int %lhs %17
OpReturnValue %32
OpFunctionEnd
%foo = OpFunction %void None %7
%12 = OpLabel
%21 = OpVariable %_ptr_Function_v4int Function %23
%16 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%17 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%18 = OpLoad %v4int %17
%24 = OpCompositeConstruct %v4int %int_2 %int_2 %int_2 %int_2
%20 = OpSMod %v4int %18 %24
OpStore %16 %20
%34 = OpLabel
%39 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%40 = OpLoad %v4int %39
%35 = OpFunctionCall %v4int %tint_mod %40 %int_2
%42 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
OpStore %42 %35
OpReturn
OpFunctionEnd

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int4 tint_mod(int4 lhs, int4 rhs) {
return (lhs % (((rhs == (0).xxxx) | ((lhs == (-2147483648).xxxx) & (rhs == (-1).xxxx))) ? (1).xxxx : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store4(0u, asuint((asint(v.Load4(0u)) % (2).xxxx)));
const int4 tint_symbol = tint_mod(asint(v.Load4(0u)), (2).xxxx);
v.Store4(0u, asuint(tint_symbol));
}

View File

@@ -3,8 +3,13 @@ void unused_entry_point() {
return;
}
int4 tint_mod(int4 lhs, int4 rhs) {
return (lhs % (((rhs == (0).xxxx) | ((lhs == (-2147483648).xxxx) & (rhs == (-1).xxxx))) ? (1).xxxx : rhs));
}
RWByteAddressBuffer v : register(u0, space0);
void foo() {
v.Store4(0u, asuint((asint(v.Load4(0u)) % (2).xxxx)));
const int4 tint_symbol = tint_mod(asint(v.Load4(0u)), (2).xxxx);
v.Store4(0u, asuint(tint_symbol));
}

View File

@@ -4,6 +4,10 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
ivec4 tint_mod(ivec4 lhs, ivec4 rhs) {
return (lhs % mix(rhs, ivec4(1), bvec4(uvec4(equal(rhs, ivec4(0))) | uvec4(bvec4(uvec4(equal(lhs, ivec4(-2147483648))) & uvec4(equal(rhs, ivec4(-1))))))));
}
struct S {
ivec4 a;
};
@@ -13,6 +17,7 @@ layout(binding = 0, std430) buffer v_block_ssbo {
} v;
void foo() {
v.inner.a = (v.inner.a % ivec4(2));
ivec4 tint_symbol = tint_mod(v.inner.a, ivec4(2));
v.inner.a = tint_symbol;
}

View File

@@ -1,11 +1,16 @@
#include <metal_stdlib>
using namespace metal;
int4 tint_mod(int4 lhs, int4 rhs) {
return (lhs % select(rhs, int4(1), ((rhs == int4(0)) | ((lhs == int4((-2147483647 - 1))) & (rhs == int4(-1))))));
}
struct S {
/* 0x0000 */ int4 a;
};
void foo(device S* const tint_symbol) {
(*(tint_symbol)).a = ((*(tint_symbol)).a % int4(2));
void foo(device S* const tint_symbol_1) {
int4 const tint_symbol = tint_mod((*(tint_symbol_1)).a, int4(2));
(*(tint_symbol_1)).a = tint_symbol;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 22
; Bound: 43
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,6 +13,9 @@
OpMemberName %S 0 "a"
OpName %v "v"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_mod "tint_mod"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
OpDecorate %v_block Block
OpMemberDecorate %v_block 0 Offset 0
@@ -27,21 +30,44 @@
%v = OpVariable %_ptr_StorageBuffer_v_block StorageBuffer
%void = OpTypeVoid
%7 = OpTypeFunction %void
%11 = OpTypeFunction %v4int %v4int %v4int
%17 = OpConstantNull %v4int
%bool = OpTypeBool
%v4bool = OpTypeVector %bool 4
%int_n2147483648 = OpConstant %int -2147483648
%22 = OpConstantComposite %v4int %int_n2147483648 %int_n2147483648 %int_n2147483648 %int_n2147483648
%int_n1 = OpConstant %int -1
%25 = OpConstantComposite %v4int %int_n1 %int_n1 %int_n1 %int_n1
%int_1 = OpConstant %int 1
%30 = OpConstantComposite %v4int %int_1 %int_1 %int_1 %int_1
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_v4int = OpTypePointer StorageBuffer %v4int
%int_2 = OpConstant %int 2
%20 = OpConstantComposite %v4int %int_2 %int_2 %int_2 %int_2
%41 = OpConstantComposite %v4int %int_2 %int_2 %int_2 %int_2
%unused_entry_point = OpFunction %void None %7
%10 = OpLabel
OpReturn
OpFunctionEnd
%tint_mod = OpFunction %v4int None %11
%lhs = OpFunctionParameter %v4int
%rhs = OpFunctionParameter %v4int
%15 = OpLabel
%18 = OpIEqual %v4bool %rhs %17
%23 = OpIEqual %v4bool %lhs %22
%26 = OpIEqual %v4bool %rhs %25
%27 = OpLogicalAnd %v4bool %23 %26
%28 = OpLogicalOr %v4bool %18 %27
%16 = OpSelect %v4int %28 %30 %rhs
%31 = OpSMod %v4int %lhs %16
OpReturnValue %31
OpFunctionEnd
%foo = OpFunction %void None %7
%12 = OpLabel
%16 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%17 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%18 = OpLoad %v4int %17
%21 = OpSMod %v4int %18 %20
OpStore %16 %21
%33 = OpLabel
%38 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
%39 = OpLoad %v4int %38
%34 = OpFunctionCall %v4int %tint_mod %39 %41
%42 = OpAccessChain %_ptr_StorageBuffer_v4int %v %uint_0 %uint_0
OpStore %42 %34
OpReturn
OpFunctionEnd

View File

@@ -3,12 +3,16 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
groupshared int a;
groupshared float4 b;
groupshared float2x2 c;
void foo() {
a = (a / 2);
a = tint_div(a, 2);
b = mul(float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx), b);
c = (c * 2.0f);
}

View File

@@ -3,12 +3,16 @@ void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (((rhs == 0) | ((lhs == -2147483648) & (rhs == -1))) ? 1 : rhs));
}
groupshared int a;
groupshared float4 b;
groupshared float2x2 c;
void foo() {
a = (a / 2);
a = tint_div(a, 2);
b = mul(float4x4((0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx, (0.0f).xxxx), b);
c = (c * 2.0f);
}

View File

@@ -4,11 +4,15 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int tint_div(int lhs, int rhs) {
return (lhs / (bool(uint((rhs == 0)) | uint(bool(uint((lhs == -2147483648)) & uint((rhs == -1))))) ? 1 : rhs));
}
shared int a;
shared vec4 b;
shared mat2 c;
void foo() {
a = (a / 2);
a = tint_div(a, 2);
b = (b * mat4(vec4(0.0f), vec4(0.0f), vec4(0.0f), vec4(0.0f)));
c = (c * 2.0f);
}

View File

@@ -1,8 +1,12 @@
#include <metal_stdlib>
using namespace metal;
int tint_div(int lhs, int rhs) {
return (lhs / select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}
void foo(threadgroup int* const tint_symbol, threadgroup float4* const tint_symbol_1, threadgroup float2x2* const tint_symbol_2) {
*(tint_symbol) = (*(tint_symbol) / 2);
*(tint_symbol) = tint_div(*(tint_symbol), 2);
*(tint_symbol_1) = (*(tint_symbol_1) * float4x4(float4(0.0f), float4(0.0f), float4(0.0f), float4(0.0f)));
*(tint_symbol_2) = (*(tint_symbol_2) * 2.0f);
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 28
; Bound: 45
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -11,6 +11,9 @@
OpName %b "b"
OpName %c "c"
OpName %unused_entry_point "unused_entry_point"
OpName %tint_div "tint_div"
OpName %lhs "lhs"
OpName %rhs "rhs"
OpName %foo "foo"
%int = OpTypeInt 32 1
%_ptr_Workgroup_int = OpTypePointer Workgroup %int
@@ -25,24 +28,43 @@
%c = OpVariable %_ptr_Workgroup_mat2v2float Workgroup
%void = OpTypeVoid
%12 = OpTypeFunction %void
%16 = OpTypeFunction %int %int %int
%22 = OpConstantNull %int
%bool = OpTypeBool
%int_n2147483648 = OpConstant %int -2147483648
%int_n1 = OpConstant %int -1
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%mat4v4float = OpTypeMatrix %v4float 4
%23 = OpConstantNull %mat4v4float
%40 = OpConstantNull %mat4v4float
%float_2 = OpConstant %float 2
%unused_entry_point = OpFunction %void None %12
%15 = OpLabel
OpReturn
OpFunctionEnd
%tint_div = OpFunction %int None %16
%lhs = OpFunctionParameter %int
%rhs = OpFunctionParameter %int
%20 = OpLabel
%23 = OpIEqual %bool %rhs %22
%26 = OpIEqual %bool %lhs %int_n2147483648
%28 = OpIEqual %bool %rhs %int_n1
%29 = OpLogicalAnd %bool %26 %28
%30 = OpLogicalOr %bool %23 %29
%21 = OpSelect %int %30 %int_1 %rhs
%32 = OpSDiv %int %lhs %21
OpReturnValue %32
OpFunctionEnd
%foo = OpFunction %void None %12
%17 = OpLabel
%18 = OpLoad %int %a
%20 = OpSDiv %int %18 %int_2
OpStore %a %20
%21 = OpLoad %v4float %b
%24 = OpVectorTimesMatrix %v4float %21 %23
OpStore %b %24
%25 = OpLoad %mat2v2float %c
%27 = OpMatrixTimesScalar %mat2v2float %25 %float_2
OpStore %c %27
%34 = OpLabel
%36 = OpLoad %int %a
%35 = OpFunctionCall %int %tint_div %36 %int_2
OpStore %a %35
%38 = OpLoad %v4float %b
%41 = OpVectorTimesMatrix %v4float %38 %40
OpStore %b %41
%42 = OpLoad %mat2v2float %c
%44 = OpMatrixTimesScalar %mat2v2float %42 %float_2
OpStore %c %44
OpReturn
OpFunctionEnd