.file "abs.c" .text .globl naive_abs .type naive_abs, @function naive_abs: pushl %ebp movl %esp, %ebp cmpl $0, 8(%ebp) jns .L5 negl 8(%ebp) .L5: movl 8(%ebp), %eax popl %ebp ret .size naive_abs, .-naive_abs .globl sneaky_abs .type sneaky_abs, @function sneaky_abs: pushl %ebp movl %esp, %ebp #APP movl 8(%ebp), %eax cdq add %eax, %edx xor %eax, %edx #NO_APP popl %ebp ret .size sneaky_abs, .-sneaky_abs .section .rodata .LC0: .string "test" .LC1: .string "abs.c" .LC2: .string "0 == f(0)" .LC3: .string "0 == f(-0)" .LC4: .string "1 == f(1)" .LC5: .string "1 == f(-1)" .LC6: .string "0x7fffffff == f(-0x7fffffff)" .text .globl test .type test, @function test: pushl %ebp movl %esp, %ebp subl $24, %esp movl $0, (%esp) movl 8(%ebp), %eax call *%eax testl %eax, %eax je .L9 movl $.LC0, 12(%esp) movl $45, 8(%esp) movl $.LC1, 4(%esp) movl $.LC2, (%esp) call __assert_fail .L9: movl $0, (%esp) movl 8(%ebp), %eax call *%eax testl %eax, %eax je .L11 movl $.LC0, 12(%esp) movl $46, 8(%esp) movl $.LC1, 4(%esp) movl $.LC3, (%esp) call __assert_fail .L11: movl $1, (%esp) movl 8(%ebp), %eax call *%eax cmpl $1, %eax je .L13 movl $.LC0, 12(%esp) movl $47, 8(%esp) movl $.LC1, 4(%esp) movl $.LC4, (%esp) call __assert_fail .L13: movl $-1, (%esp) movl 8(%ebp), %eax call *%eax cmpl $1, %eax je .L15 movl $.LC0, 12(%esp) movl $48, 8(%esp) movl $.LC1, 4(%esp) movl $.LC5, (%esp) call __assert_fail .L15: movl $-2147483647, (%esp) movl 8(%ebp), %eax call *%eax cmpl $2147483647, %eax je .L7 movl $.LC0, 12(%esp) movl $49, 8(%esp) movl $.LC1, 4(%esp) movl $.LC6, (%esp) call __assert_fail .L7: leave ret .size test, .-test .local orig.0 .comm orig.0,8,8 .section .rodata .LC7: .string "%30s " .LC11: .string "%7.3f %4.0f%%\n" .align 8 .LC8: .long 0 .long 1093567616 .align 8 .LC10: .long 0 .long 1079574528 .text .type speed, @function speed: pushl %ebp movl %esp, %ebp subl $88, %esp movl 8(%ebp), %eax movl %eax, 4(%esp) movl $.LC7, (%esp) call printf movl 12(%ebp), %eax movl %eax, (%esp) call test movl $-67108864, -52(%ebp) movl $0, 4(%esp) leal -24(%ebp), %eax movl %eax, (%esp) call gettimeofday .L19: movl -52(%ebp), %eax movl %eax, (%esp) movl 12(%ebp), %eax call *%eax leal -52(%ebp), %eax incl (%eax) cmpl $1, -52(%ebp) jne .L19 movl $0, 4(%esp) leal -24(%ebp), %eax addl $8, %eax movl %eax, (%esp) call gettimeofday movl -24(%ebp), %eax imull $1000000, %eax, %eax addl -20(%ebp), %eax pushl %eax fildl (%esp) leal 4(%esp), %esp fstpl -40(%ebp) movl -16(%ebp), %eax imull $1000000, %eax, %eax addl -12(%ebp), %eax pushl %eax fildl (%esp) leal 4(%esp), %esp fstpl -32(%ebp) fldl -32(%ebp) fsubl -40(%ebp) fldl .LC8 fdivrp %st, %st(1) fstpl -48(%ebp) fldl orig.0 fldz fxch %st(1) fucompp fnstsw %ax sahf jp .L25 je .L24 .L25: jmp .L23 .L24: fldl -48(%ebp) fstpl orig.0 .L23: fldl orig.0 fdivl -48(%ebp) fldl .LC10 fmulp %st, %st(1) fldl .LC10 fsubrp %st, %st(1) fstpl 12(%esp) fldl -48(%ebp) fstpl 4(%esp) movl $.LC11, (%esp) call printf leave ret .size speed, .-speed .section .rodata .LC13: .string "%u iterations:\n" .LC14: .string "speedup" .LC15: .string "seconds" .LC16: .string "function" .LC17: .string "%30s %5s %s\n" .LC18: .string "stdlib abs" .LC19: .string "naive_abs" .LC20: .string "sneaky_abs" .text .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $24, %esp andl $-16, %esp movl $0, %eax subl %eax, %esp movl $67108864, 4(%esp) movl $.LC13, (%esp) call printf movl $.LC14, 12(%esp) movl $.LC15, 8(%esp) movl $.LC16, 4(%esp) movl $.LC17, (%esp) call printf movl $abs, 4(%esp) movl $.LC18, (%esp) call speed movl $naive_abs, 4(%esp) movl $.LC19, (%esp) call speed movl $sneaky_abs, 4(%esp) movl $.LC20, (%esp) call speed movl $0, %eax leave ret .size main, .-main .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)"