mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:38:36 +00:00
#1283 reduced the angle in turns with Fract. For a negative argument Fract is 1 - |x|, which rounds in binary32: sin(-2**-26 turns) became +0 and the absolute error was up to ~1.7e-7 at -0.1 turns. x - RoundEven(x) is exact in binary32 for every finite x and keeps the angle in [-pi, pi]. The change is inside turn_angle (shared by the f32 and f16 forms), with the variable names of the line that test_mutations.py anchors on kept. - tests/semantic/test_alu_sincos.py: f32/f16 against sin/cos(2*pi*x) in double, tiny arguments (fails on main), whole turns of either sign (+0, as measured on an RX 6800 by shelbykb2), +-0, inf/NaN, modifiers. - runtime/test/shaders/cs_w32_sincos.asm: wave32 GPU regression guard (tolerance 1e-3, the driver Sin is only good to 2^-11), registered in check.py and run_gpu_tests.py. - docs/design.md: contract row with the RX 6800 measurement and what is not matched (half/quarter turns, the small-x constant, inf/NaN words). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
61 lines
2.2 KiB
NASM
61 lines
2.2 KiB
NASM
; SHADER-88: v_sin_f32 / v_cos_f32 take the angle in turns and must reduce it in turns before scaling by 2*pi.
|
|
; Six large-angle cases (254.25, 254.5, -200.75, 100.3, 254.51, -254.51 turns); each stores 1 when
|
|
; |result - reference| < 1e-3 (the reference is sin/cos(2*pi*x) in double; a Vulkan Sin/Cos is only guaranteed to
|
|
; 2^-11 = 4.9e-4 in [-pi, pi], so the shader compares with a tolerance and stores a flag, not the float).
|
|
; Lane 0 stores out[0..5] = 1 1 1 1 1 1. (Expected references, f32 bits: 1.0, -1.0, 1.0, 0xbe9e39de,
|
|
; 0xbd808642, 0xbf7f7ed2.)
|
|
; group: 32,1,1
|
|
; Run: vk_compute_test cs_w32_sincos.spv 1 dump -> out[0..5] = 1 1 1 1 1 1
|
|
; mattr: +wavefrontsize32,-wavefrontsize64
|
|
v_mov_b32_e32 v9, 0x3a83126f
|
|
v_cmpx_eq_u32_e32 0, v0
|
|
v_mov_b32_e32 v1, 0x437e4000
|
|
v_sin_f32_e32 v2, v1
|
|
v_sub_f32_e32 v2, 0x3f800000, v2
|
|
v_and_b32_e32 v2, 0x7fffffff, v2
|
|
v_cmp_gt_f32_e32 vcc_lo, v9, v2
|
|
v_cndmask_b32_e64 v20, 0, 1, vcc_lo
|
|
v_mov_b32_e32 v21, 0
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
v_mov_b32_e32 v1, 0x437e8000
|
|
v_cos_f32_e32 v2, v1
|
|
v_sub_f32_e32 v2, 0xbf800000, v2
|
|
v_and_b32_e32 v2, 0x7fffffff, v2
|
|
v_cmp_gt_f32_e32 vcc_lo, v9, v2
|
|
v_cndmask_b32_e64 v20, 0, 1, vcc_lo
|
|
v_mov_b32_e32 v21, 4
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
v_mov_b32_e32 v1, 0xc348c000
|
|
v_sin_f32_e32 v2, v1
|
|
v_sub_f32_e32 v2, 0x3f800000, v2
|
|
v_and_b32_e32 v2, 0x7fffffff, v2
|
|
v_cmp_gt_f32_e32 vcc_lo, v9, v2
|
|
v_cndmask_b32_e64 v20, 0, 1, vcc_lo
|
|
v_mov_b32_e32 v21, 8
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
v_mov_b32_e32 v1, 0x42c8999a
|
|
v_cos_f32_e32 v2, v1
|
|
v_sub_f32_e32 v2, 0xbe9e39de, v2
|
|
v_and_b32_e32 v2, 0x7fffffff, v2
|
|
v_cmp_gt_f32_e32 vcc_lo, v9, v2
|
|
v_cndmask_b32_e64 v20, 0, 1, vcc_lo
|
|
v_mov_b32_e32 v21, 12
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
v_mov_b32_e32 v1, 0x437e828f
|
|
v_sin_f32_e32 v2, v1
|
|
v_sub_f32_e32 v2, 0xbd808642, v2
|
|
v_and_b32_e32 v2, 0x7fffffff, v2
|
|
v_cmp_gt_f32_e32 vcc_lo, v9, v2
|
|
v_cndmask_b32_e64 v20, 0, 1, vcc_lo
|
|
v_mov_b32_e32 v21, 16
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
v_mov_b32_e32 v1, 0xc37e828f
|
|
v_cos_f32_e32 v2, v1
|
|
v_sub_f32_e32 v2, 0xbf7f7ed2, v2
|
|
v_and_b32_e32 v2, 0x7fffffff, v2
|
|
v_cmp_gt_f32_e32 vcc_lo, v9, v2
|
|
v_cndmask_b32_e64 v20, 0, 1, vcc_lo
|
|
v_mov_b32_e32 v21, 20
|
|
buffer_store_dword v20, v21, s[0:3], 0 offen
|
|
s_endpgm
|