Skip to content
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

Operations with saturation/ceil #65

Closed
davidbp opened this issue Feb 21, 2020 · 3 comments · Fixed by #63
Closed

Operations with saturation/ceil #65

davidbp opened this issue Feb 21, 2020 · 3 comments · Fixed by #63

Comments

@davidbp
Copy link

davidbp commented Feb 21, 2020

Hello,

I could not find saturation operations implemented (maybe they are not there).

The standard + operator does

x = Vec(UInt8.((255,255,255,255)))
y = Vec(UInt8.((1,0,0,0)))
x + y
<4 x UInt8>[0, 255, 255, 255]

I would like to do a sum_ceil that keeps the maximum value of the datatype in case of overflow or the min in case of underflow.

x = Vec(UInt8.((255,255,255,255)))
y = Vec(UInt8.((1,0,0,0)))
sum_ceil(x,y)  
<4 x UInt8>[255, 255, 255, 255]

According to intel_X86 there are specific instructions that do this (no need to check manually overflow etc..) in a single instruction call. Do you have plans to add them? Or are they there but I could not see them.

@KristofferC
Copy link
Collaborator

Yes, these exist in LLVM (https://llvm.org/docs/LangRef.html#saturation-arithmetic-intrinsics).

They could easily be added to https://github.com/eschnett/SIMD.jl/pull/63/files#diff-04c8d1e34d3b52bf0e6db708969277ecR127. I might do it soon unless I get beaten to it.

@davidbp
Copy link
Author

davidbp commented Feb 21, 2020

Thanks for your fast answer Kristoffer, I hope that you can manage to do it. This is beyond the current knowledge that I have about the low level parts interfacing LLVM and Julia. Nevertheles I hope to be able to build upon this features once they are ready !.

@KristofferC
Copy link
Collaborator

Added in e3321e5 (you need to use the branch for that PR for now).


julia> x = Vec(UInt8.((255,255,255,255)))
<4 x UInt8>[255, 255, 255, 255]

julia> y = Vec(UInt8.((1,0,0,0)))
<4 x UInt8>[1, 0, 0, 0]

julia> SIMD.add_saturate(x, y)
<4 x UInt8>[255, 255, 255, 255]

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