This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Portable "add with carry" loop for arbitrary precision arithmetic
- From: Tom St Denis <tstdenis at ellipticsemi dot com>
- To: Alexander Konovalenko <alexkon at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 23 Jun 2008 06:55:26 -0400
- Subject: Re: Portable "add with carry" loop for arbitrary precision arithmetic
- References: <c7b40f9d0806221803o3611616by4a47b790ea96eee5@mail.gmail.com>
Alexander Konovalenko wrote:
There is an "add with carry" instruction on some architectures which
enables efficient implementation of arbitrary precision (bignum)
integer addition. Is it possible to make gcc generate efficient
machine code from pure C or C++ code for bignum addition on those
architectures?
It looks like the popular libraries like GMP and CLN use hand-coded
assembly for that. I wonder if gcc can help rewrite that kind of code
in a more portable way.
GCC will use them in most cases. For example,
extern unsigned long long a, b, c;
int main(void)
{
c = a + b;
return 0;
}
Produces this with "-O3 -fomit-frame-pointer"
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ecx
movl a, %eax
movl a+4, %edx
addl b, %eax
adcl b+4, %edx
movl %eax, c
xorl %eax, %eax
movl %edx, c+4
popl %ecx
leal -4(%ecx), %esp
ret
Tom