[ create a new paste ] login | about

Link: http://codepad.org/ugwQ37sh    [ raw code | fork ]

C, pasted on Sep 7:
#include "stdlib.h"

// this is an useful operation, it's a safe
// unsigned product with overflow-safety test;
// this version is designed to help the compiler
unsigned int mul(unsigned int a, unsigned int b) {
    unsigned long long c = a;
    c *= b;
    if ((unsigned int)c != c)
        exit(1);
    return c;
}

/*
Args used to compile with gcc and llvm-gcc:
-Wall -O3 -fomit-frame-pointer -msse3 -march=native -S
On Windows
gcc: version 4.3.3-dw2-tdm-1 (GCC)
llvm-gcc: gcc version 4.2.1 (Based on Apple Inc. build 5636) (LLVM build)

----------------------------------

GCC:

_mul:
    pushl   %ebx
    subl    $8, %esp
    movl    20(%esp), %eax
    mull    16(%esp)
    movl    %eax, %ecx
    testl   %edx, %edx
    jne L5
    movl    %ecx, %eax
    addl    $8, %esp
    popl    %ebx
    ret
L5:
    movl    $1, (%esp)
    call    _exit

----------------------------------

LLVM-GCC:

_mul:
    subl    $4, %esp
    movl    12(%esp), %eax
    mull    8(%esp)
    testl   %edx, %edx
    jne LBB1_2  # bb
    addl    $4, %esp
    ret
LBB1_2: # bb
    movl    $1, (%esp)
    call    _exit

*/


Create a new paste based on this one


Comments: