This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgcc documentation problems?



So I'm looking at using gcc in an embedded environment, and providing my own libgcc (long story). So I was looking at the libgcc documentation at:


http://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#Integer-library-routines

which gives the prototype for __umoddi3 and __umodti3 as:
unsigned long __umoddi3 (unsigned long a, unsigned long b)
unsigned long long __umodti3 (unsigned long long a, unsigned long long b)

From this, it looks like the code should call __umodti3 to do a long long
modulo. The problem is, when I compile the code:

unsigned long long foo(unsigned long long a, unsigned long long b) {
    return a%b;
}

the resulting assembly calls __umoddi3, not __umodti3:

foo:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movl    8(%ebp), %eax
        movl    12(%ebp), %edx
        movl    %eax, -8(%ebp)
        movl    %edx, -4(%ebp)
        movl    16(%ebp), %eax
        movl    20(%ebp), %edx
        movl    %eax, -16(%ebp)
        movl    %edx, -12(%ebp)
        movl    -8(%ebp), %eax
        movl    -4(%ebp), %edx
        pushl   -12(%ebp)
        pushl   -16(%ebp)
        pushl   %edx
        pushl   %eax
        call    __umoddi3
        addl    $16, %esp
        leave
        ret

This is gcc 3.3.4:
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-slackware-linux/3.3.4/specs
Configured with: ../gcc-3.3.4/configure --prefix=/usr --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld --verbose --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.3.4


but I remember seeing this behavior on 2.9 as well.

Now, things work correctly, so this isn't a bug with the compiler- it's the documentation which is unclear. I see two possibilities:

1) The prototypes on that website are just wrong- __umoddi3 is always called to to do long long modulo. In this case, is __umodti3 ever even used?

2) __umodsi3 handles 32-bit words on all systems (ignoring weird systems for the moment), __umoddi3 handles 64-bit words- longs on 64-bit systems, long longs on 32-bit systems, and __umodti3 handles 128 bit words- long long on 64-bit systems and not used on 32-bit systems.

So my question is: which is it?

Please cc: bhurt@visualcircuits.com, as I'm not currently subscribed to this list.

Thanks.

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]