mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 17:48:40 +00:00
Covers the "16-bit results" contract row, which ended with "not yet GPU-verified".
Hardware evidence: AMD RX 6800 (gfx1030), the instructions run as a raw compute kernel in wave32 and
wave64, IEEE off, DX10 clamp on, denormals kept, round to nearest. The bytes assemble identically for
gfx1013 and gfx1030 (llvm-mc 21; the kernels themselves were assembled by the driver's comgr).
- v_med3_f16: all 16 op_sel patterns, neg/abs on a selected high half, clamp, destination also a source.
- v_add/sub/mul/max/min_f16 (_e32, _e64 with neg/abs/clamp), v_fmac_f16 (_e32, _e64), f16 unary
(rndne/floor/ceil/trunc/fract/sqrt/rcp/rsq, _e32 and _e64), v_cvt_f16_f32: low halves in, low half out,
high half of the destination kept; the v_fmac_f16 accumulator is the low half of the destination.
336 words per wave size, all as the rule says and as the translator computes.
- Not expressible: op_sel on the VOP2/VOP1 ops in VOP3 encoding (v_add/sub/mul/max/min_f16_e64,
v_fmac_f16_e64, unary _e64). llvm-mc rejects the modifier and its disassembler drops the bits, so
nothing was measured there and nothing was hand-encoded.
Translator fix (tools/rdna2spirv.py, new src_h): an inline float constant in an f16 operand is the f16
value in the low half over a zero high half. The translator unpacked the f32 pattern, whose low half is
zero, so v_add_f16 d, 1.0, v added 0.0 and v_cvt_f32_f16 d, 0.5 gave 0. Measured for v_add/mul/max_f16,
v_sub_f16_e64, v_fma_f16, v_fmac_f16, v_rcp_f16, v_med3_f16, v_cmp_lt_f16, v_cvt_f32_f16, v_cos_f16,
v_pk_add/mul_f16 and v_pack_b32_f16 (0.15915494 is 0x3118); the high half op_sel selects from a constant
reads +0.0. v_fma_mix* operands were not
measured and are unchanged.
Tests:
- runtime/test/shaders/ps_f16_{med3_opsel,med3_mods,vop2,vop2b,vop1,vop1b,const,const2,pack}.asm, wired into
check.py and scripts/run_gpu_tests.py. Their expected words are the ones the hardware gave for the same
instructions. Vulkan, AMD Radeon RX 6800, Windows, driver 26.11.2: 9/9 pass; with one expected word
flipped per test 0/9 pass; without the translator fix ps_f16_const, ps_f16_const2 and ps_f16_pack fail.
- tests/test_f16_hw_words.py: header, check.py and run_gpu_tests.py hold the hardware words; a
plain-Python reference of the rule and the translator (tests/spirv_interp.py) both give them. 12 of its
tests fail without the fix.
- tests/semantic: ps_f16_vop2 fixture and value test; the v_sin_f16 mutation anchor follows the edit.
- tests/spirv_interp.py: Floor/Ceil/Trunc/RoundEven keep the sign of a zero result (trunc(-0.75) is
0x8000 on the hardware and on Vulkan), Sin/Cos, component-wise vector arithmetic.
- python -m unittest discover -s tests/semantic: 388 -> 389, OK. pytest tests: 1467 -> 1514 passed.
scripts/run_gpu_tests.py (test tools rebuilt): 48/49 -> 57/58 passed, 1 skipped.
docs/design.md: the "16-bit results" row says what was verified and what is not expressible; new row
"f16 inline constants".
AI-assisted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19 lines
815 B
NASM
19 lines
815 B
NASM
; f16 unary (VOP1) rounding ops read the low half and keep the high half of the destination.
|
|
; v0 = 2.5 | -1.5 << 16, v1 = -0.75 | 3.5 << 16 (low | high half); destinations start as 0xaaaa5555.
|
|
; v_rndne_f16 2.5 -> 2.0 (ties to even) v_floor_f16 -0.75 -> -1.0 v_ceil_f16_e64 -v0: ceil(-2.5) = -2.0
|
|
; v_trunc_f16 -0.75 -> -0.0 (0x8000: the zero keeps the sign)
|
|
; The words are the ones an RX 6800 (gfx1030) gave for this body run as a raw kernel, wave32 and wave64.
|
|
; Expected mrt0 bits: 0xaaaa4000, 0xaaaabc00, 0xaaaac000, 0xaaaa8000
|
|
v_mov_b32 v0, 0xbe004100
|
|
v_mov_b32 v1, 0x4300ba00
|
|
v_mov_b32 v2, 0xaaaa5555
|
|
v_mov_b32 v3, 0xaaaa5555
|
|
v_mov_b32 v4, 0xaaaa5555
|
|
v_mov_b32 v5, 0xaaaa5555
|
|
v_rndne_f16 v2, v0
|
|
v_floor_f16 v3, v1
|
|
v_ceil_f16_e64 v4, -v0
|
|
v_trunc_f16 v5, v1
|
|
exp mrt0 v2, v3, v4, v5 done vm
|
|
s_endpgm
|