Skip to content

Commit

Permalink
wgsl: Implement AbstractInt subtract execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zoddicus committed Feb 13, 2024
1 parent b87bbf6 commit 1d34bd1
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
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": "5399470c",
"webgpu/shader/execution/binary/ai_arithmetic.bin": "bf537bd0",
"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: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 },
"webgpu:shader,execution,expression,binary,af_addition:scalar:*": { "subcaseMS": 815.300 },
"webgpu:shader,execution,expression,binary,af_addition:scalar_vector:*": { "subcaseMS": 1803.434 },
"webgpu:shader,execution,expression,binary,af_addition:vector:*": { "subcaseMS": 719.600 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import {
} from '../case.js';
import { makeCaseCache } from '../case_cache.js';

function isOOB(val: bigint): boolean {
return val > kValue.i64.positive.max || val < kValue.i64.negative.min;
}
function ai_add(x: bigint, y: bigint): bigint | undefined {
const result = x + y;
if (result > kValue.i64.positive.max || result < kValue.i64.negative.min) {
return undefined;
}
return result;
return !isOOB(result) ? result : undefined;
}

function ai_sub(x: bigint, y: bigint): bigint | undefined {
const result = x - y;
return !isOOB(result) ? result : undefined;
}

export const d = makeCaseCache('binary/ai_arithmetic', {
Expand All @@ -37,4 +42,25 @@ export const d = makeCaseCache('binary/ai_arithmetic', {
addition_vector4_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(4), sparseI64Range(), ai_add);
},
subtraction: () => {
return generateBinaryToI64Cases(sparseI64Range(), sparseI64Range(), ai_sub);
},
subtraction_scalar_vector2: () => {
return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(2), ai_sub);
},
subtraction_scalar_vector3: () => {
return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(3), ai_sub);
},
subtraction_scalar_vector4: () => {
return generateI64VectorBinaryToVectorCases(sparseI64Range(), vectorI64Range(4), ai_sub);
},
subtraction_vector2_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(2), sparseI64Range(), ai_sub);
},
subtraction_vector3_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(3), sparseI64Range(), ai_sub);
},
subtraction_vector4_scalar: () => {
return generateVectorI64BinaryToVectorCases(vectorI64Range(4), sparseI64Range(), ai_sub);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { abstractIntBinary } from './binary.js';
export const g = makeTestGroup(GPUTest);

g.test('addition')
.specURL('https://www.w3.org/TR/WGSL/#floating-point-evaluation')
.specURL('https://www.w3.org/TR/WGSL/#arithmetic-expr')
.desc(
`
Expression: x + y
Expand Down Expand Up @@ -69,3 +69,61 @@ Expression: x + y
const cases = await d.get(`addition_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(
`
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('subtraction');
await run(
t,
abstractIntBinary('-'),
[TypeAbstractInt, TypeAbstractInt],
TypeAbstractInt,
t.params,
cases
);
});

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

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

0 comments on commit 1d34bd1

Please sign in to comment.