fix(hal): add tanh + integer clamp to SPIR-V interpreter#225
Merged
Conversation
The software interpreter's GLSL.std.450 dispatch only handled float clamp (FClamp); the hyperbolics (Sinh/Cosh/Tanh and inverses) and the integer clamp variants (SClamp/UClamp) were missing. Unknown ext-inst opcodes fall through to `return ValUint(0)`, so any shader calling `tanh()` or integer `clamp()` silently produced zeros instead of the real result — wrong output, not a visible error. Surfaced by born's webgpu backend on the software path, where its Tanh and Int32 Clamp ops returned all-zeros. Add the missing opcodes (19–24, 44–45) plus ternary int helpers, with interpreter tests for each. Signed-off-by: Alejandro Mery <amery@geeks.cl>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
kolkov
approved these changes
Jun 24, 2026
kolkov
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Clean implementation, follows all existing patterns.
Verified:
- All 8 opcode numbers correct per GLSL.std.450 spec (Sinh=19–Atanh=24, UClamp=44, SClamp=45)
- Hyperbolic ops use
glslUnaryFloat— consistent with Sin/Cos/Tan pattern - Integer clamp ops use new
glslTernaryUint/glslTernaryInthelpers — mirrors existingglslBinary*style - Tests cover all branches: saturation boundaries (tanh ±10), domain boundaries (acosh(1)), negative range (SClamp)
- float32↔float64 conversion chain matches every other float op in the file
One systemic note (not blocking this PR): unknown GLSL.std.450 opcodes silently return ValUint(0) — this is how Born ML got zeros in the first place. Filed internally as BUG-SW-009 to add a warning log for unimplemented opcodes.
Thanks @amery — shipping in v0.30.3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The software SPIR-V interpreter's GLSL.std.450 dispatch was missing two
common math builtins. Unknown ext-inst opcodes fall through to
return ValUint(0), so shaders calling these got silently wrongresults (zeros) rather than an error:
tanh()—Tanh(21) absent (all hyperbolics, 19–24, were missing)clamp()—SClamp(45) andUClamp(44) absent; only thefloat
FClamp(43) was handledChanges
Sinh/Cosh/Tanh/Asinh/Acosh/Atanh(19–24) andUClamp/SClamp(44–45) inhal/software/shader/glsl_ext.go.glslTernaryUint/glslTernaryInthelpers, mirroring theexisting
glslBinary*ones.TestGLSLUnaryIntrinsics,plus
TestGLSLSClamp/TestGLSLUClamp.Testing
go test ./hal/software/shader/andgo vet ./hal/software/shader/pass.Discovery
Surfaced by the born ML framework's webgpu backend on the software path,
where its
TanhandInt32 Clampops returned all-zeros. With theseopcodes implemented, both produce correct results.
No existing issue tracked this; still reproducible on
main.