diff --git a/src/resources/cache/hashes.json b/src/resources/cache/hashes.json index 1a698f89cac3..e7953a0afc90 100644 --- a/src/resources/cache/hashes.json +++ b/src/resources/cache/hashes.json @@ -104,6 +104,6 @@ "webgpu/shader/execution/unary/u32_complement.bin": "d00cdf00", "webgpu/shader/execution/unary/u32_conversion.bin": "2940ba5e", "webgpu/shader/execution/unary/ai_assignment.bin": "9c0d8f91", - "webgpu/shader/execution/binary/ai_arithmetic.bin": "f48612cb", + "webgpu/shader/execution/binary/ai_arithmetic.bin": "e17954", "webgpu/shader/execution/unary/ai_arithmetic.bin": "2a1ff461" } \ No newline at end of file diff --git a/src/resources/cache/webgpu/shader/execution/binary/ai_arithmetic.bin b/src/resources/cache/webgpu/shader/execution/binary/ai_arithmetic.bin index 49a8c9701890..658eb46d3949 100644 Binary files a/src/resources/cache/webgpu/shader/execution/binary/ai_arithmetic.bin and b/src/resources/cache/webgpu/shader/execution/binary/ai_arithmetic.bin differ diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index d93198dad8c4..aa2efaddf530 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -904,6 +904,9 @@ "webgpu:shader,execution,expression,binary,ai_arithmetic:division_vector_scalar:*": { "subcaseMS": 0 }, "webgpu:shader,execution,expression,binary,ai_arithmetic:multiplication:*": { "subcaseMS": 0 }, "webgpu:shader,execution,expression,binary,ai_arithmetic:multiplication_scalar_vector:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,binary,ai_arithmetic:remainder:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,binary,ai_arithmetic:remainder_scalar_vector:*": { "subcaseMS": 0 }, + "webgpu:shader,execution,expression,binary,ai_arithmetic:remainder_vector_scalar:*": { "subcaseMS": 0 }, "webgpu:shader,execution,expression,binary,ai_arithmetic:multiplication_vector_scalar:*": { "subcaseMS": 0 }, "webgpu:shader,execution,expression,binary,ai_arithmetic:subtraction:*": { "subcaseMS": 0 }, "webgpu:shader,execution,expression,binary,ai_arithmetic:subtraction_scalar_vector:*": { "subcaseMS": 0 }, diff --git a/src/webgpu/shader/execution/expression/binary/ai_arithmetic.cache.ts b/src/webgpu/shader/execution/expression/binary/ai_arithmetic.cache.ts index f2f15bc5f42b..bb68b8d1c5f9 100644 --- a/src/webgpu/shader/execution/expression/binary/ai_arithmetic.cache.ts +++ b/src/webgpu/shader/execution/expression/binary/ai_arithmetic.cache.ts @@ -27,6 +27,13 @@ function ai_mul(x: bigint, y: bigint): bigint | undefined { return !isOOB(result) ? result : undefined; } +function ai_rem(x: bigint, y: bigint): bigint | undefined { + if (y === 0n) return undefined; + if (x === kValue.i64.negative.min && y === -1n) return undefined; + const result = x % y; + return !isOOB(result) ? result : undefined; +} + function ai_sub(x: bigint, y: bigint): bigint | undefined { const result = x - y; return !isOOB(result) ? result : undefined; @@ -96,6 +103,27 @@ export const d = makeCaseCache('binary/ai_arithmetic', { multiplication_vector4_scalar: () => { return generateVectorI64BinaryToVectorCases(vectorI64Range(4), sparseI64Range(), ai_mul); }, + remainder: () => { + return generateBinaryToI64Cases(sparseI64Range(), sparseI64Range(), ai_rem); + }, + remainder_scalar_vector2: () => { + return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(2), ai_rem); + }, + remainder_scalar_vector3: () => { + return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(3), ai_rem); + }, + remainder_scalar_vector4: () => { + return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(4), ai_rem); + }, + remainder_vector2_scalar: () => { + return generateVectorI64BinaryToVectorCases(vectorI64Range(2), sparseI64Range(), ai_rem); + }, + remainder_vector3_scalar: () => { + return generateVectorI64BinaryToVectorCases(vectorI64Range(3), sparseI64Range(), ai_rem); + }, + remainder_vector4_scalar: () => { + return generateVectorI64BinaryToVectorCases(vectorI64Range(4), sparseI64Range(), ai_rem); + }, subtraction: () => { return generateBinaryToI64Cases(sparseI64Range(), sparseI64Range(), ai_sub); }, diff --git a/src/webgpu/shader/execution/expression/binary/ai_arithmetic.spec.ts b/src/webgpu/shader/execution/expression/binary/ai_arithmetic.spec.ts index ac848a2bddc3..ae8b6ccf483b 100644 --- a/src/webgpu/shader/execution/expression/binary/ai_arithmetic.spec.ts +++ b/src/webgpu/shader/execution/expression/binary/ai_arithmetic.spec.ts @@ -186,6 +186,64 @@ Expression: x * y await run(t, abstractIntBinary('*'), [vec_type, TypeAbstractInt], vec_type, t.params, cases); }); +g.test('remainder') + .specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr') + .desc( + ` +Expression: x % y +` + ) + .params(u => + u + .combine('inputSource', onlyConstInputSource) + .combine('vectorize', [undefined, 2, 3, 4] as const) + ) + .fn(async t => { + const cases = await d.get('remainder'); + await run( + t, + abstractIntBinary('%'), + [TypeAbstractInt, TypeAbstractInt], + TypeAbstractInt, + t.params, + cases + ); + }); + +g.test('remainder_scalar_vector') + .specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr') + .desc( + ` +Expression: x % y +` + ) + .params(u => + u.combine('inputSource', onlyConstInputSource).combine('vectorize_rhs', [2, 3, 4] as const) + ) + .fn(async t => { + const vec_size = t.params.vectorize_rhs; + const vec_type = TypeVec(vec_size, TypeAbstractInt); + const cases = await d.get(`remainder_scalar_vector${vec_size}`); + await run(t, abstractIntBinary('%'), [TypeAbstractInt, vec_type], vec_type, t.params, cases); + }); + +g.test('remainder_vector_scalar') + .specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr') + .desc( + ` +Expression: x % y +` + ) + .params(u => + u.combine('inputSource', onlyConstInputSource).combine('vectorize_lhs', [2, 3, 4] as const) + ) + .fn(async t => { + const vec_size = t.params.vectorize_lhs; + const vec_type = TypeVec(vec_size, TypeAbstractInt); + const cases = await d.get(`remainder_vector${vec_size}_scalar`); + await run(t, abstractIntBinary('%'), [vec_type, TypeAbstractInt], vec_type, t.params, cases); + }); + g.test('subtraction') .specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr') .desc(