Do there exist intrinsics for ARM C compilers to do add-with-carry operations, or is it necessary to use assembly language?
On x86, there is _addcarry_u64
for add-with-carry. (There's also the newer _addcarryx_u64
for special purposes.)
There is no intrinsic with current versions of gcc. An issue is that communication of the 'carry flag'. However, the ARM backend does know and define a set of ADC
primitives such as addsi3_carryin.
For example,
unsigned long long big_inc(unsigned long long x)
{
return ++x;
}
Is translated to,
big_inc(unsigned long long):
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
adds r0, r0, #1
adc r1, r1, #0
bx lr
It is always instructive to look at open source multi-precision libraries when you have a question like this. There is OpenSSL bignum and GNU MP libraries without any research. As the intrinsic doesn't exist a more definitive answer (for your work) depends on exactly what it is you want to achieve; prime factors, multiply, add, etc. You can always use assembler or more powerfully use a script that generates assembler for your particular integer length.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With