Skip to content

Commit

Permalink
wgsl: Implement AbstractInt division execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zoddicus committed Feb 13, 2024
1 parent 8506071 commit 86b86f7
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": "bf537bd0",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "1e43f807",
"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 @@ -899,6 +899,9 @@
"webgpu:shader,execution,expression,binary,ai_arithmetic:addition:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:addition_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:addition_vector_scalar:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:division:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:division_scalar_vector:*": { "subcaseMS": 0 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:division_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 },
"webgpu:shader,execution,expression,binary,ai_arithmetic:subtraction_vector_scalar:*": { "subcaseMS": 0 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function ai_add(x: bigint, y: bigint): bigint | undefined {
return !isOOB(result) ? result : undefined;
}

function ai_div(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 @@ -42,6 +49,27 @@ export const d = makeCaseCache('binary/ai_arithmetic', {
addition_vector4_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(4), sparseI64Range(), ai_add);
},
division: () => {
return generateBinaryToI64Cases(sparseI64Range(), sparseI64Range(), ai_div);
},
division_scalar_vector2: () => {
return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(2), ai_div);
},
division_scalar_vector3: () => {
return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(3), ai_div);
},
division_scalar_vector4: () => {
return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(4), ai_div);
},
division_vector2_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(2), sparseI64Range(), ai_div);
},
division_vector3_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(3), sparseI64Range(), ai_div);
},
division_vector4_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(4), sparseI64Range(), ai_div);
},
subtraction: () => {
return generateBinaryToI64Cases(sparseI64Range(), sparseI64Range(), ai_sub);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,64 @@ Expression: x + y
await run(t, abstractIntBinary('+'), [vec_type, TypeAbstractInt], vec_type, t.params, cases);
});

g.test('division')
.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('division');
await run(
t,
abstractIntBinary('/'),
[TypeAbstractInt, TypeAbstractInt],
TypeAbstractInt,
t.params,
cases
);
});

g.test('division_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(`division_scalar_vector${vec_size}`);
await run(t, abstractIntBinary('/'), [TypeAbstractInt, vec_type], vec_type, t.params, cases);
});

g.test('division_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(`division_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 86b86f7

Please sign in to comment.