diff options
Diffstat (limited to 'dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/binary/f32_comparison.spec.ts')
-rw-r--r-- | dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/binary/f32_comparison.spec.ts | 159 |
1 files changed, 9 insertions, 150 deletions
diff --git a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/binary/f32_comparison.spec.ts b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/binary/f32_comparison.spec.ts index ef862e7757..42eb8934a4 100644 --- a/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/binary/f32_comparison.spec.ts +++ b/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/binary/f32_comparison.spec.ts @@ -4,155 +4,14 @@ Execution Tests for the f32 comparison operations import { makeTestGroup } from '../../../../../common/framework/test_group.js'; import { GPUTest } from '../../../../gpu_test.js'; -import { anyOf } from '../../../../util/compare.js'; -import { bool, f32, Scalar, TypeBool, TypeF32 } from '../../../../util/conversion.js'; -import { flushSubnormalNumberF32, vectorF32Range } from '../../../../util/math.js'; -import { makeCaseCache } from '../case_cache.js'; -import { allInputSources, Case, run } from '../expression.js'; +import { Type } from '../../../../util/conversion.js'; +import { allInputSources, run } from '../expression.js'; import { binary } from './binary.js'; +import { d } from './f32_comparison.cache.js'; export const g = makeTestGroup(GPUTest); -/** - * @returns a test case for the provided left hand & right hand values and truth function. - * Handles quantization and subnormals. - */ -function makeCase( - lhs: number, - rhs: number, - truthFunc: (lhs: Scalar, rhs: Scalar) => boolean -): Case { - // Subnormal float values may be flushed at any time. - // https://www.w3.org/TR/WGSL/#floating-point-evaluation - const f32_lhs = f32(lhs); - const f32_rhs = f32(rhs); - const lhs_options = new Set([f32_lhs, f32(flushSubnormalNumberF32(lhs))]); - const rhs_options = new Set([f32_rhs, f32(flushSubnormalNumberF32(rhs))]); - const expected: Array<Scalar> = []; - lhs_options.forEach(l => { - rhs_options.forEach(r => { - const result = bool(truthFunc(l, r)); - if (!expected.includes(result)) { - expected.push(result); - } - }); - }); - - return { input: [f32_lhs, f32_rhs], expected: anyOf(...expected) }; -} - -export const d = makeCaseCache('binary/f32_logical', { - equals_non_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) === (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - equals_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) === (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - not_equals_non_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) !== (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - not_equals_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) !== (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - less_than_non_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) < (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - less_than_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) < (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - less_equals_non_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) <= (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - less_equals_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) <= (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - greater_than_non_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) > (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - greater_than_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) > (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - greater_equals_non_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) >= (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, - greater_equals_const: () => { - const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => { - return (lhs.value as number) >= (rhs.value as number); - }; - - return vectorF32Range(2).map(v => { - return makeCase(v[0], v[1], truthFunc); - }); - }, -}); - g.test('equals') .specURL('https://www.w3.org/TR/WGSL/#comparison-expr') .desc( @@ -168,7 +27,7 @@ Accuracy: Correct result const cases = await d.get( t.params.inputSource === 'const' ? 'equals_const' : 'equals_non_const' ); - await run(t, binary('=='), [TypeF32, TypeF32], TypeBool, t.params, cases); + await run(t, binary('=='), [Type.f32, Type.f32], Type.bool, t.params, cases); }); g.test('not_equals') @@ -186,7 +45,7 @@ Accuracy: Correct result const cases = await d.get( t.params.inputSource === 'const' ? 'not_equals_const' : 'not_equals_non_const' ); - await run(t, binary('!='), [TypeF32, TypeF32], TypeBool, t.params, cases); + await run(t, binary('!='), [Type.f32, Type.f32], Type.bool, t.params, cases); }); g.test('less_than') @@ -204,7 +63,7 @@ Accuracy: Correct result const cases = await d.get( t.params.inputSource === 'const' ? 'less_than_const' : 'less_than_non_const' ); - await run(t, binary('<'), [TypeF32, TypeF32], TypeBool, t.params, cases); + await run(t, binary('<'), [Type.f32, Type.f32], Type.bool, t.params, cases); }); g.test('less_equals') @@ -222,7 +81,7 @@ Accuracy: Correct result const cases = await d.get( t.params.inputSource === 'const' ? 'less_equals_const' : 'less_equals_non_const' ); - await run(t, binary('<='), [TypeF32, TypeF32], TypeBool, t.params, cases); + await run(t, binary('<='), [Type.f32, Type.f32], Type.bool, t.params, cases); }); g.test('greater_than') @@ -240,7 +99,7 @@ Accuracy: Correct result const cases = await d.get( t.params.inputSource === 'const' ? 'greater_than_const' : 'greater_than_non_const' ); - await run(t, binary('>'), [TypeF32, TypeF32], TypeBool, t.params, cases); + await run(t, binary('>'), [Type.f32, Type.f32], Type.bool, t.params, cases); }); g.test('greater_equals') @@ -258,5 +117,5 @@ Accuracy: Correct result const cases = await d.get( t.params.inputSource === 'const' ? 'greater_equals_const' : 'greater_equals_non_const' ); - await run(t, binary('>='), [TypeF32, TypeF32], TypeBool, t.params, cases); + await run(t, binary('>='), [Type.f32, Type.f32], Type.bool, t.params, cases); }); |