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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
export const description = `
Execution Tests for the AbstractFloat comparison operations
`;
import { makeTestGroup } from '../../../../../common/framework/test_group.js';
import { GPUTest } from '../../../../gpu_test.js';
import { anyOf } from '../../../../util/compare.js';
import {
abstractFloat,
bool,
Scalar,
TypeAbstractFloat,
TypeBool,
} from '../../../../util/conversion.js';
import { flushSubnormalNumberF64, vectorF64Range } from '../../../../util/math.js';
import { makeCaseCache } from '../case_cache.js';
import { allInputSources, Case, run } from '../expression.js';
import { binary } from './binary.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 af_lhs = abstractFloat(lhs);
const af_rhs = abstractFloat(rhs);
const lhs_options = new Set([af_lhs, abstractFloat(flushSubnormalNumberF64(lhs))]);
const rhs_options = new Set([af_rhs, abstractFloat(flushSubnormalNumberF64(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: [af_lhs, af_rhs], expected: anyOf(...expected) };
}
export const d = makeCaseCache('binary/af_logical', {
equals: () => {
const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => {
return (lhs.value as number) === (rhs.value as number);
};
return vectorF64Range(2).map(v => {
return makeCase(v[0], v[1], truthFunc);
});
},
not_equals: () => {
const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => {
return (lhs.value as number) !== (rhs.value as number);
};
return vectorF64Range(2).map(v => {
return makeCase(v[0], v[1], truthFunc);
});
},
less_than: () => {
const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => {
return (lhs.value as number) < (rhs.value as number);
};
return vectorF64Range(2).map(v => {
return makeCase(v[0], v[1], truthFunc);
});
},
less_equals: () => {
const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => {
return (lhs.value as number) <= (rhs.value as number);
};
return vectorF64Range(2).map(v => {
return makeCase(v[0], v[1], truthFunc);
});
},
greater_than: () => {
const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => {
return (lhs.value as number) > (rhs.value as number);
};
return vectorF64Range(2).map(v => {
return makeCase(v[0], v[1], truthFunc);
});
},
greater_equals: () => {
const truthFunc = (lhs: Scalar, rhs: Scalar): boolean => {
return (lhs.value as number) >= (rhs.value as number);
};
return vectorF64Range(2).map(v => {
return makeCase(v[0], v[1], truthFunc);
});
},
});
g.test('equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x == y
Accuracy: Correct result
`
)
.params(u =>
u
.combine('inputSource', [allInputSources[0]] /* const */)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('equals');
await run(t, binary('=='), [TypeAbstractFloat, TypeAbstractFloat], TypeBool, t.params, cases);
});
g.test('not_equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x != y
Accuracy: Correct result
`
)
.params(u =>
u
.combine('inputSource', [allInputSources[0]] /* const */)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('not_equals');
await run(t, binary('!='), [TypeAbstractFloat, TypeAbstractFloat], TypeBool, t.params, cases);
});
g.test('less_than')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x < y
Accuracy: Correct result
`
)
.params(u =>
u
.combine('inputSource', [allInputSources[0]] /* const */)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('less_than');
await run(t, binary('<'), [TypeAbstractFloat, TypeAbstractFloat], TypeBool, t.params, cases);
});
g.test('less_equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x <= y
Accuracy: Correct result
`
)
.params(u =>
u
.combine('inputSource', [allInputSources[0]] /* const */)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('less_equals');
await run(t, binary('<='), [TypeAbstractFloat, TypeAbstractFloat], TypeBool, t.params, cases);
});
g.test('greater_than')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x > y
Accuracy: Correct result
`
)
.params(u =>
u
.combine('inputSource', [allInputSources[0]] /* const */)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('greater_than');
await run(t, binary('>'), [TypeAbstractFloat, TypeAbstractFloat], TypeBool, t.params, cases);
});
g.test('greater_equals')
.specURL('https://www.w3.org/TR/WGSL/#comparison-expr')
.desc(
`
Expression: x >= y
Accuracy: Correct result
`
)
.params(u =>
u
.combine('inputSource', [allInputSources[0]] /* const */)
.combine('vectorize', [undefined, 2, 3, 4] as const)
)
.fn(async t => {
const cases = await d.get('greater_equals');
await run(t, binary('>='), [TypeAbstractFloat, TypeAbstractFloat], TypeBool, t.params, cases);
});
|