[llvm-dev] Generating Big Num addition code which uses ADC (add with carry) instructions

Clinton Mead via llvm-dev llvm-dev at lists.llvm.org
Mon Nov 9 20:46:34 PST 2015


I'm trying to work out LLVM code which generates something similar to the
following when adding large multiword numbers stored as separate words:

ADD x1 x1
ADC x2 y2
ADC x3 y3

etc, where such a three argument add like ADC on x86 (which includes a
carry in the addition) is available as a machine op.

The background to this is that I'm trying to implement fast multiword
addition in Haskell, which can compile via LLVM, so I thought if I knew
what LLVM code generates the ideal assembly I can work backwards and use
the appropriate Haskell prim-ops.

Of course one can use GMP, but I'd suspect with two-four word additions the
loss of inlining opportunities and the cost of the external call would be
greater than the addition itself. So it would be great to be able to work
out how to do it in LLVM and then either implement it with current GHC or
add an extra GHC prim-op which allows GHC to access the appropriate LLVM
code.

Sorry I don't know much about LLVM besides my brief readings of the docs,
and I've posted here because I couldn't find an llvm-users list. There's a
clang-users list, but I didn't think that would be appropriate because GHC
compiles via LLVM directly, not via clang.

Any help or guidance appreciated.

Clinton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151110/b22e8e2b/attachment.html>


More information about the llvm-dev mailing list