Skip to content

Commit

Permalink
wgsl: Implement AbstractInt remainder execution tests (#3400)
Browse files Browse the repository at this point in the history
Issue #1626
  • Loading branch information
zoddicus authored Feb 13, 2024
1 parent 42b0189 commit f6337a4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/resources/cache/hashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Binary file not shown.
3 changes: 3 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f6337a4

Please sign in to comment.