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

carry intrinsics? #90

Closed
Seelengrab opened this issue Aug 5, 2021 · 3 comments
Closed

carry intrinsics? #90

Seelengrab opened this issue Aug 5, 2021 · 3 comments

Comments

@Seelengrab
Copy link
Contributor

Seelengrab commented Aug 5, 2021

I'm surprised to see that the carry intrinsics (e.g. adding with carry, I think it's called @llvm.x86.addcarry.64) are not available here. Are they provided in some other package and I've just missed them?

I'd be happy to add them, but I've never worked with LLVM intrinsics before, so I'd be happy about some guidance.

@KristofferC
Copy link
Collaborator

Are you talking about an architecture-specific intrinsic (which is a quite different thing from an LLVM intrinsic)

See some discussion about that here: #89 (comment)

@Seelengrab
Copy link
Contributor Author

Very much possible! Thanks for the pointer.

@eschnett
Copy link
Owner

eschnett commented Aug 5, 2021

@Seelengrab I'd be happy to have generic add-with-carry functions in SIMD.jl. However, these need to work on (and be reasonably efficient on) all architectures. You would use the architecture-specific intrinsics if they are available, but a generic fallback needs to exist.

If I recall correctly, the condition for "overflow" (i.e. "carry is set") is (when adding):

  • both summands have the same sign
  • the sum has a different sign

This can be implemented with respective exclusive or statements. This code might work for 32-bit signed integers (r holds the result of the addition, c is the outgoing carry):
r = s1 + s2
c = (~(s1 ⊻ s2) & (r ⊻ s1)) >> 31

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

No branches or pull requests

3 participants