-
-
Save jumbojets/2c0e51c8a11d69ec1ab4bae6047f697d to your computer and use it in GitHub Desktop.
optimization levels can change program output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -O1 fma.c | |
// gcc -O3 fma.c | |
#include <stdio.h> | |
inline float mul(float a, float b) { | |
return a * b; | |
} | |
int main() { | |
float a, b, c, d; | |
scanf("%f", &a); | |
scanf("%f", &b); | |
scanf("%f", &c); | |
d = mul(a, b) + c; | |
printf("%f\n", d); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.arch armv8-a | |
.text | |
.cstring | |
.align 3 | |
lC0: | |
.ascii "%f\0" | |
.align 3 | |
lC1: | |
.ascii "%f\12\0" | |
.section __TEXT,__text_startup,regular,pure_instructions | |
.align 2 | |
.globl _main | |
_main: | |
LFB2: | |
sub sp, sp, #64 | |
LCFI0: | |
stp x29, x30, [sp, 16] | |
LCFI1: | |
add x29, sp, 16 | |
str x19, [sp, 32] | |
LCFI2: | |
adrp x19, lC0@PAGE | |
add x19, x19, lC0@PAGEOFF;momd | |
add x0, sp, 60 | |
str x0, [sp] | |
mov x0, x19 | |
bl _scanf | |
add x0, sp, 56 | |
str x0, [sp] | |
mov x0, x19 | |
bl _scanf | |
add x0, sp, 52 | |
str x0, [sp] | |
mov x0, x19 | |
bl _scanf | |
ldr s0, [sp, 60] | |
ldr s1, [sp, 56] | |
fmul s0, s0, s1 | |
ldr s1, [sp, 52] | |
fadd s0, s0, s1 | |
fcvt d0, s0 | |
str d0, [sp] | |
adrp x0, lC1@PAGE | |
add x0, x0, lC1@PAGEOFF;momd | |
bl _printf | |
mov w0, 0 | |
ldr x19, [sp, 32] | |
ldp x29, x30, [sp, 16] | |
add sp, sp, 64 | |
LCFI3: | |
ret | |
LFE2: | |
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support | |
EH_frame1: | |
.set L$set$0,LECIE1-LSCIE1 | |
.long L$set$0 | |
LSCIE1: | |
.long 0 | |
.byte 0x1 | |
.ascii "zR\0" | |
.uleb128 0x1 | |
.sleb128 -8 | |
.byte 0x1e | |
.uleb128 0x1 | |
.byte 0x10 | |
.byte 0xc | |
.uleb128 0x1f | |
.uleb128 0 | |
.align 3 | |
LECIE1: | |
LSFDE1: | |
.set L$set$1,LEFDE1-LASFDE1 | |
.long L$set$1 | |
LASFDE1: | |
.long LASFDE1-EH_frame1 | |
.quad LFB2-. | |
.set L$set$2,LFE2-LFB2 | |
.quad L$set$2 | |
.uleb128 0 | |
.byte 0x4 | |
.set L$set$3,LCFI0-LFB2 | |
.long L$set$3 | |
.byte 0xe | |
.uleb128 0x40 | |
.byte 0x4 | |
.set L$set$4,LCFI1-LCFI0 | |
.long L$set$4 | |
.byte 0x9d | |
.uleb128 0x6 | |
.byte 0x9e | |
.uleb128 0x5 | |
.byte 0x4 | |
.set L$set$5,LCFI2-LCFI1 | |
.long L$set$5 | |
.byte 0x93 | |
.uleb128 0x4 | |
.byte 0x4 | |
.set L$set$6,LCFI3-LCFI2 | |
.long L$set$6 | |
.byte 0xdd | |
.byte 0xde | |
.byte 0xd3 | |
.byte 0xe | |
.uleb128 0 | |
.align 3 | |
LEFDE1: | |
.ident "GCC: (Homebrew GCC 13.2.0) 13.2.0" | |
.subsections_via_symbols |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.arch armv8-a | |
.text | |
.cstring | |
.align 3 | |
lC0: | |
.ascii "%f\0" | |
.align 3 | |
lC1: | |
.ascii "%f\12\0" | |
.section __TEXT,__text_startup,regular,pure_instructions | |
.align 2 | |
.p2align 4,,11 | |
.globl _main | |
_main: | |
LFB2: | |
sub sp, sp, #64 | |
LCFI0: | |
add x0, sp, 52 | |
stp x29, x30, [sp, 16] | |
LCFI1: | |
add x29, sp, 16 | |
str x0, [sp] | |
str x19, [sp, 32] | |
LCFI2: | |
adrp x19, lC0@PAGE | |
add x19, x19, lC0@PAGEOFF;momd | |
mov x0, x19 | |
bl _scanf | |
add x0, sp, 56 | |
str x0, [sp] | |
mov x0, x19 | |
bl _scanf | |
add x0, sp, 60 | |
str x0, [sp] | |
mov x0, x19 | |
bl _scanf | |
ldp s2, s1, [sp, 52] | |
adrp x0, lC1@PAGE | |
ldr s0, [sp, 60] | |
add x0, x0, lC1@PAGEOFF;momd | |
fmadd s0, s2, s1, s0 | |
fcvt d0, s0 | |
str d0, [sp] | |
bl _printf | |
ldp x29, x30, [sp, 16] | |
mov w0, 0 | |
ldr x19, [sp, 32] | |
add sp, sp, 64 | |
LCFI3: | |
ret | |
LFE2: | |
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support | |
EH_frame1: | |
.set L$set$0,LECIE1-LSCIE1 | |
.long L$set$0 | |
LSCIE1: | |
.long 0 | |
.byte 0x1 | |
.ascii "zR\0" | |
.uleb128 0x1 | |
.sleb128 -8 | |
.byte 0x1e | |
.uleb128 0x1 | |
.byte 0x10 | |
.byte 0xc | |
.uleb128 0x1f | |
.uleb128 0 | |
.align 3 | |
LECIE1: | |
LSFDE1: | |
.set L$set$1,LEFDE1-LASFDE1 | |
.long L$set$1 | |
LASFDE1: | |
.long LASFDE1-EH_frame1 | |
.quad LFB2-. | |
.set L$set$2,LFE2-LFB2 | |
.quad L$set$2 | |
.uleb128 0 | |
.byte 0x4 | |
.set L$set$3,LCFI0-LFB2 | |
.long L$set$3 | |
.byte 0xe | |
.uleb128 0x40 | |
.byte 0x4 | |
.set L$set$4,LCFI1-LCFI0 | |
.long L$set$4 | |
.byte 0x9d | |
.uleb128 0x6 | |
.byte 0x9e | |
.uleb128 0x5 | |
.byte 0x4 | |
.set L$set$5,LCFI2-LCFI1 | |
.long L$set$5 | |
.byte 0x93 | |
.uleb128 0x4 | |
.byte 0x4 | |
.set L$set$6,LCFI3-LCFI2 | |
.long L$set$6 | |
.byte 0xdd | |
.byte 0xde | |
.byte 0xd3 | |
.byte 0xe | |
.uleb128 0 | |
.align 3 | |
LEFDE1: | |
.ident "GCC: (Homebrew GCC 13.2.0) 13.2.0" | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment