summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/execution/expression/call/builtin/sign.cache.ts
blob: 09f4de19ac18e6ab8fb39fee36ffa41665a34060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { abstractInt, i32 } from '../../../../../util/conversion.js';
import { FP } from '../../../../../util/floating_point.js';
import { fullI32Range, fullI64Range } from '../../../../../util/math.js';
import { makeCaseCache } from '../../case_cache.js';

// Cases: [f32|f16|abstract]
const fp_cases = (['f32', 'f16', 'abstract'] as const)
  .map(trait => ({
    [`${trait === 'abstract' ? 'abstract_float' : trait}`]: () => {
      return FP[trait].generateScalarToIntervalCases(
        FP[trait].scalarRange(),
        'unfiltered',
        FP[trait].signInterval
      );
    },
  }))
  .reduce((a, b) => ({ ...a, ...b }), {});

export const d = makeCaseCache('sign', {
  ...fp_cases,
  i32: () =>
    fullI32Range().map(i => {
      const signFunc = (i: number): number => (i < 0 ? -1 : i > 0 ? 1 : 0);
      return { input: [i32(i)], expected: i32(signFunc(i)) };
    }),
  abstract_int: () =>
    fullI64Range().map(i => {
      const signFunc = (i: bigint): bigint => (i < 0n ? -1n : i > 0n ? 1n : 0n);
      return { input: [abstractInt(i)], expected: abstractInt(signFunc(i)) };
    }),
});