Last active
December 18, 2015 19:49
-
-
Save tetsu-koba/5835724 to your computer and use it in GitHub Desktop.
Compiler output gcc 4.8.1 vs clang +llvm 3.3 in armv7-a with -O.
This file contains 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
int sum(x) | |
{ | |
int sum = 0; | |
int i; | |
for (i = 1; i <= x; i++) { | |
sum += i; | |
} | |
return sum; | |
} | |
#include <stdio.h> | |
int main() | |
{ | |
int n; | |
n = 100; | |
printf("sum(%d) = %d\n", n, sum(n)); | |
} |
This file contains 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
.syntax unified | |
.cpu cortex-a8 | |
.eabi_attribute 6, 10 | |
.eabi_attribute 7, 65 | |
.eabi_attribute 8, 1 | |
.eabi_attribute 9, 2 | |
.eabi_attribute 10, 3 | |
.fpu vfpv3 | |
.eabi_attribute 20, 1 | |
.eabi_attribute 21, 1 | |
.eabi_attribute 23, 3 | |
.eabi_attribute 24, 1 | |
.eabi_attribute 25, 1 | |
.file "sum.c" | |
.text | |
.globl sum | |
.align 2 | |
.type sum,%function | |
sum: | |
mov r1, #0 | |
cmp r0, #1 | |
blt .LBB0_2 | |
sub r1, r0, #2 | |
sub r2, r0, #1 | |
umull r1, r2, r2, r1 | |
and r2, r2, #1 | |
lsrs r2, r2, #1 | |
rrx r1, r1 | |
add r0, r1, r0, lsl #1 | |
sub r1, r0, #1 | |
.LBB0_2: | |
mov r0, r1 | |
bx lr | |
.Ltmp0: | |
.size sum, .Ltmp0-sum | |
.globl main | |
.align 2 | |
.type main,%function | |
main: | |
push {r11, lr} | |
movw r0, :lower16:.L.str | |
mov r1, #100 | |
movt r0, :upper16:.L.str | |
movw r2, #5050 | |
mov r11, sp | |
bl printf | |
mov r0, #0 | |
pop {r11, pc} | |
.Ltmp1: | |
.size main, .Ltmp1-main | |
.type .L.str,%object | |
.section .rodata.str1.1,"aMS",%progbits,1 | |
.L.str: | |
.asciz "sum(%d) = %d\n" | |
.size .L.str, 14 | |
This file contains 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
.syntax unified | |
.arch armv7-a | |
.eabi_attribute 27, 3 | |
.eabi_attribute 28, 1 | |
.fpu vfpv3-d16 | |
.eabi_attribute 20, 1 | |
.eabi_attribute 21, 1 | |
.eabi_attribute 23, 3 | |
.eabi_attribute 24, 1 | |
.eabi_attribute 25, 1 | |
.eabi_attribute 26, 1 | |
.eabi_attribute 30, 2 | |
.eabi_attribute 34, 1 | |
.eabi_attribute 18, 4 | |
.thumb | |
.file "sum.c" | |
.text | |
.align 2 | |
.global sum | |
.thumb | |
.thumb_func | |
.type sum, %function | |
sum: | |
@ args = 0, pretend = 0, frame = 0 | |
@ frame_needed = 0, uses_anonymous_args = 0 | |
@ link register save eliminated. | |
cmp r0, #0 | |
ble .L4 | |
adds r2, r0, #1 | |
movs r3, #1 | |
movs r0, #0 | |
.L3: | |
add r0, r0, r3 | |
adds r3, r3, #1 | |
cmp r3, r2 | |
bne .L3 | |
bx lr | |
.L4: | |
movs r0, #0 | |
bx lr | |
.size sum, .-sum | |
.section .text.startup,"ax",%progbits | |
.align 2 | |
.global main | |
.thumb | |
.thumb_func | |
.type main, %function | |
main: | |
@ args = 0, pretend = 0, frame = 0 | |
@ frame_needed = 0, uses_anonymous_args = 0 | |
@ link register save eliminated. | |
movs r3, #1 | |
movs r2, #0 | |
.L9: | |
add r2, r2, r3 | |
adds r3, r3, #1 | |
cmp r3, #101 | |
bne .L9 | |
movw r0, #:lower16:.LC0 | |
movs r1, #100 | |
movt r0, #:upper16:.LC0 | |
b printf | |
.size main, .-main | |
.section .rodata.str1.4,"aMS",%progbits,1 | |
.align 2 | |
.LC0: | |
.ascii "sum(%d) = %d\012\000" | |
.ident "GCC: (GNU) 4.8.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment