MacArthur, Ian (SELEX) (UK) wrote:
> I've looked at the code generated for integer mod operations
> in the past, and a lot of compilers make a real mess of it..

        Really? Noticeably?

        I believe you, as sometimes compilers can sometimes make ugly assembly,
        but I figure that's an exception to the rule. And surely they won't
        get it wrong.

        Usually % just maps to an "IDIV", IIRC from my 8086 days.
        Even today, it doesn't look too bad:

% cat foo.C
#include <time.h>
int main() {
     int x = time(NULL);
     x = x % 20;   // <--
     return(x);
}

% g++ -g -c -Wa,-adhln -O1 foo.C | more
[..]
    4:foo.C         ****     x = x % 20;   // <--
   31                            .loc 1 4 0
   32 0013 BA14000000            movl    $20, %edx
   33 0018 89D1                  movl    %edx, %ecx
   34 001a 99                    cltd
   35 001b F7F9                  idivl   %ecx
[..]

        Removing -O1 is pretty much the same result.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to