<div dir="ltr"><div><div><div><div><div><div><div><div><div>This might "just work" on many targets by using the appropriate integral type.<br><br></div>e.g. on x86_64, something like<br><br></div>%a = add i128 %b, %c<br><br></div>will lower to<br><br></div>add rax,rbx<br></div>adc rcx,rdx<br><br></div>Some caveats, based on my experience with LLVM 3.3, so things may have changed by then:<br><br></div>- Not all targets support operations on integers wider than the "native width". e.g. on x86_64, trying to multiply i256 x i256 will net you an assert. I believe i128 x i128 is handled, perhaps by a function call, but nothing larger.<br></div>- At least on x86_64, everything is fully unrolled. So adding i2048 + i2048 will generate an ADD and 31 ADC instructions, with no looping. This makes sense for "small" multiprecision integers, but can get silly as things get wider.<br><br></div>In my project, I am using i128 in a few places (add, subtract, shift) to get efficient code, and relying on my own library functions for anything wider.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 9, 2015 at 11:46 PM, Clinton Mead via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm trying to work out LLVM code which generates something similar to the following when adding large multiword numbers stored as separate words:<div><br></div><div>ADD x1 x1</div><div>ADC x2 y2</div><div>ADC x3 y3</div><div><br></div><div>etc, where such a three argument add like ADC on x86 (which includes a carry in the addition) is available as a machine op.</div><div><br></div><div>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. </div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Any help or guidance appreciated.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Clinton</div><div><br></div></font></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>