mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:00:52 +01:00
[PR #78] [MERGED] spirv_asm: float literals and DebugPrintf as spirv-as reads them (OLD-3911, OLD-4237, OLD-4286, OLD-4322, OLD-4330) #130
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#130
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/78
Author: @ItsMrDubey
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism
Base:
main← Head:spirv-asm-float-fixes📝 Commits (5)
ba49ba2spirv_asm: a hex-float constant is truncated toward zero, as spirv-as reads it4e8aa91spirv_asm: a decimal f32 constant is rounded once, and an f16 one is that f32 cut toward zero, as spirv-as reads them1f11a0fspirv_asm: a decimal float constant that overflows its type, or spells inf or nan, is refused as spirv-as refuses it3d0664aspirv_asm: a BFloat16KHR constant is encoded as bfloat16, not as an IEEE halfc389dbcspirv_asm: OpExtInst takes DebugPrintf by name from the NonSemantic.DebugPrintf set, as spirv-dis writes it📊 Changes
3 files changed (+208 additions, -37 deletions)
View changed files
📝
tests/test_spirv_asm.py(+104 -0)📝
tools/spirv_asm.py(+97 -35)📝
tools/spirv_asm_tables.py(+7 -2)📄 Description
Claimed in the coordination issue as: OLD-3911, OLD-4237, OLD-4286, OLD-4322, OLD-4330 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964)
What and why
Five float-literal and extended-instruction differences between
tools/spirv_asm.pyand spirv-as. There is one commit per issue, and each comes with a regression test intests/test_spirv_asm.py. I reproduced all five on origin/main before fixing them. No open PR or old-pr branch addressed them (the only spirv_asm branch in #17,old-pr/10025, is about output aliasing), so nothing was cherry-picked.spirv-as is not installed here (
where spirv-asfinds nothing), so the reference behaviour comes from reading SPIRV-Tools'source/util/parse_number.cpp(ParseAndEncodeFloatingPointNumber) andsource/util/hex_float.h(operator>>forHexFloat,ParseNormalFloatand itsFloat16andBFloat16specialisations, andcastTo). The tests assert the values that code produces.HexFloat'soperator>>and it is correct. That parser drops the significand bits that don't fit, both normal and subnormal, so the result is truncated toward zero. A value too large for the type becomes infinity, and the exponent-all-ones spelling still carries a NaN payload. spirv_asm used to round to nearest throughfloat.fromhexandstruct.pack. For example, f320x1.0000018p0gave 0x3F800001 and now gives 0x3F800000. f320x1.fffffffp127used to round up to +Inf and now gives 0x7F7FFFFF.1.00000005960464477539062500000001now gives 0x3F800001; it used to give 0x3F800000.Note that f16 is not round-to-nearest in spirv-as, even though the issue says it is.
ParseNormalFloat<Float16>reads the decimal as an f32 and then narrows it withcastTo(..., round_direction::kToZero). spirv_asm now does the same thing, so1.0006gives 0x3C00, not the nearer 0x3C01, and65535gives 0x7BFF instead of +Inf.1e400, f321e39and f1665536. It also took Python-only spellings such asinf,nan,infinityand1_0. All of these are now refused, and the error names the line. Underflow still rounds to zero, as strtod does. A hex-float can still spell infinity, as it can in spirv-as.OpTypeFloat 16 BFloat16KHRand encoded its constants as IEEE halves, so1.5gave 0x3E00. They now use the bfloat16 layout (8 exponent bits, 7 fraction bits), so1.5gives 0x3FC0. As SPIRV-Tools does, a decimal is read as an f32 and truncated, and a hex-float is truncated.OpExtInst %void %set DebugPrintf ..., the spelling spirv-dis prints forNonSemantic.DebugPrintf, used to fail with "invalid integer literal 'DebugPrintf'". The set now has a one-entry table (NONSEMANTIC_DEBUGPRINTF, fromextinst.nonsemantic.debugprintf.grammar.json), and the numeric form1still works.Tested
Windows 11, Python 3.11.9, no GPU needed. spirv-as and spirv-val are not installed, so the tests that compare against spirv-as, and the
_validatecall, skip.python -I tests/test_spirv_asm.py: 36 tests OK (1 skipped: the comparison against spirv-as). Withtools/reverted to origin/main, the new tests fail: 10 of the hex-float cases, 8 decimal cases, all 12 overflow and non-finite cases, 10 BF16 cases plus its overflow check, and the DebugPrintf test with an error.python -I tests/test_spirv_asm_tables.py: OKpython -I tests/test_desc_cache.py, andpython -m unittest discover -s tests/semantic -p test_<name>.pyfor each semantic test that imports spirv_asm (alu_div_fmas, alu_ldexp_f64, global_sub_dword, lds_atomics_cas, scmp_u64_mask_pairs, wave64_emulate_opt, wave64_mov_b32_cross_half): all OKpython -I scripts/run_semantic_tests.py tests/semantic: 463 files, 6075 tests; 4 files fail (test_exec_computed 2, test_image_atomics_guard 47, test_sopc_validation 1, test_unary_f16_validation 15 failures), and withtools/reverted to origin/main the same 4 files fail with the same counts, so the failures were already on mainpython -m compileall -q make_game.py tools tests, andpython -I tests/test_text_write_line_endings.py: OKpython -I scripts/check_no_game_data.py tools/spirv_asm.py tools/spirv_asm_tables.py tests/test_spirv_asm.py: cleanAI-assisted: yes
Checklist
docs/design.md(assembler only).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.