Skip to content

spirv: saturating arithmetic implementation #24317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ivanstepanovftw
Copy link
Contributor

@ivanstepanovftw ivanstepanovftw commented Jul 1, 2025

This PR implements saturating arithmetic, like +|, -|=, etc for SPIR-V. It emulates the behavior like GCC STL does, without using special opcodes from the extended set (like OpenCL.std). I need this for Tsetlin machine implementation.

@ivanstepanovftw
Copy link
Contributor Author

cc @alichraghi

@ivanstepanovftw ivanstepanovftw marked this pull request as draft July 1, 2025 17:24
@ivanstepanovftw

This comment was marked as resolved.

@ivanstepanovftw

This comment was marked as outdated.

@alichraghi
Copy link
Contributor

alichraghi commented Jul 1, 2025

the tests on test/behavior/saturating_arithmetic.zig are fails. you can locally run the test using zig-spirv-test-executor:

zig test test/behavior/saturating_arithmetic.zig \
    --test-runner /path/to/zig-spirv-test-executor/src/test_runner.zig \
    -target spirv64-vulkan \
    -mcpu vulkan_v1_2+int64+float16+float64 \
    -fno-llvm \
    --test-cmd /path/to/zig-spirv-test-executor/zig-out/bin/zig-spirv-test-executor \
    --test-cmd --platform \
    --test-cmd radv \
    --test-cmd-bin -femit-bin=build/spv.spv

Also, i genuinely ask you to avoid using AI to fix the spirv backend. Though, you're welcome to ask me questions about SPIR-V at any time!

@ivanstepanovftw
Copy link
Contributor Author

ivanstepanovftw commented Jul 1, 2025

Nice. I didn't know about this test, I have only tested locally with simple kernel. Personally I like builder functions more than duplicating one for *Overflow, one for *Sat.

I will try to run tests now.

I will also add missing tests, so #24315 never regress.

@ivanstepanovftw ivanstepanovftw marked this pull request as ready for review July 2, 2025 17:44
@ivanstepanovftw ivanstepanovftw changed the title spirv: saturating arithmetic implementation (only add/sub) spirv: saturating arithmetic implementation Jul 2, 2025
@ivanstepanovftw
Copy link
Contributor Author

Seems like riscv64 does not know how to subtract zero from signed integers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants