[MLton-devel] detecting overflow with the C codegen

Henry Cejtin henry@sourcelight.com
Thu, 21 Nov 2002 16:09:58 -0600


To make the test a bit more reasonable, at least compile with
    -fomit-frame-pointer
(only the add* functions need this).

I  don't understand the logic behind the add3 code.  If you know that n2 is a
constant (so a compare of n1 against a constant does  the  job  for  overflow
detection) then the return should be of n1 plus a constant, not plus n2.

Note,  the  code  for  add3  is  incredibly bad.  The whole song and dance of
saving and restoring %ebx is a complete waste since they could just have used
%eax  instead.   This  would  save  the subtract of 8 from %esp, the store of
%ebx, the load of %ebx.  I.e.:

    add3:
            pushl   %ebx
            movl    %esp, %ebp
            movl    8(%ebp), %eax
            cmpl    $2147360191, %eax
            jg      .L8
            addl    12(%ebp), %eax
            popl    %ebp
            ret
            call    overflow
            jmp     .L7

and with -fomit-frame-pointer,

    add3:
            movl    4(%esp), %eax
            cmpl    $2147360191, %eax
            jg      .L8
            addl    8(%esp), %eax
            ret
            call    overflow
            jmp     .L7

(Probably typos in the above code.)


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel