Created
May 17, 2012 10:48
-
-
Save jessicah/2718089 to your computer and use it in GitHub Desktop.
Example of c-- output from ocamlopt
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
(data int 4096 global "camlTest" "camlTest": skip 32) | |
(data | |
int 3319 | |
"camlTest__2": | |
addr "caml_curry3" | |
int 7 | |
addr "camlTest__max_1035") | |
(data int 2295 "camlTest__3": addr "camlTest__squares_1032" int 3) | |
(data int 2295 "camlTest__4": addr "camlTest__fun_1047" int 3) | |
(data | |
global "camlTest__1" | |
int 6144 | |
"camlTest__1": | |
int 1 | |
int 21 | |
int 41 | |
int 51 | |
int 95 | |
int 121) | |
(function camlTest__fun_1047 (x/1034: addr) | |
(+ (* (+ x/1034 -1) (>>s x/1034 1)) 1)) | |
(function camlTest__squares_1032 (arr/1033: addr) | |
(app "camlArray__map_1076" "camlTest__4" arr/1033 addr)) | |
(function camlTest__max_1035 | |
(so_far/1036: addr arr/1037: addr pos/1038: addr) | |
(if (== pos/1038 (or (>>u (load (+a arr/1037 -8)) 9) 1)) so_far/1036 | |
(let | |
x/1039 | |
(let header/1053 (load (+a arr/1037 -8)) | |
(checkbound (>>u header/1053 9) pos/1038) | |
(if (!= (and header/1053 255) 254) | |
(load (+a (+a arr/1037 (<< pos/1038 2)) -4)) | |
(alloc 1277 (load float64u (+a (+a arr/1037 (<< pos/1038 2)) -4))))) | |
(if (!= (extcall "caml_greaterthan" x/1039 so_far/1036 addr) 1) | |
(app "camlTest__max_1035" x/1039 arr/1037 (+ pos/1038 2) addr) | |
(app "camlTest__max_1035" so_far/1036 arr/1037 (+ pos/1038 2) addr))))) | |
(function camlTest__entry () | |
(let array_of_ints/1030 (extcall "caml_obj_dup" "camlTest__1" addr) | |
(store "camlTest" array_of_ints/1030)) | |
(store (+a "camlTest" 8) 33) | |
(let squares/1032 "camlTest__3" (store (+a "camlTest" 16) squares/1032)) | |
(let clos/1050 "camlTest__2" (store (+a "camlTest" 24) clos/1050)) | |
(let | |
match/1045 | |
(let squares/1040 (app "camlTest__squares_1032" (load "camlTest") addr) | |
(let | |
i/1051 | |
(app "camlTest__max_1035" -9223372036854775807 squares/1040 1 | |
addr) | |
(app{pervasives.ml:365,18-56} "camlPervasives__output_string_1193" | |
(load (+a "camlPervasives" 184)) | |
(app{pervasives.ml:365,39-56} "camlPervasives__string_of_int_1132" | |
i/1051 addr) | |
unit)) | |
(let i/1052 (app "camlTest__max_1035" 33 (load "camlTest") 1 addr) | |
(app{pervasives.ml:365,18-56} "camlPervasives__output_string_1193" | |
(load (+a "camlPervasives" 184)) | |
(app{pervasives.ml:365,39-56} "camlPervasives__string_of_int_1132" | |
i/1052 addr) | |
addr))) | |
[]) | |
1a) | |
(data) |
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
let array_of_ints = [| 0; 10; 20; 25; 47; 60 |] | |
let constant = 16 | |
let squares arr = Array.map (fun x -> x * x) arr | |
let rec max so_far arr pos = | |
if pos = Array.length arr then so_far | |
else | |
let x = arr.(pos) in | |
if x > so_far then max x arr (pos + 1) | |
else max so_far arr (pos + 1) | |
let () = | |
let squares = squares array_of_ints in | |
print_int (max min_int squares 0); | |
print_int (max constant array_of_ints 0) |
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
.section .rodata.cst8,"a",@progbits | |
.align 16 | |
caml_negf_mask: .quad 0x8000000000000000, 0 | |
.align 16 | |
caml_absf_mask: .quad 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF | |
.data | |
.globl camlTest__data_begin | |
camlTest__data_begin: | |
.text | |
.globl camlTest__code_begin | |
camlTest__code_begin: | |
.data | |
.quad 4096 | |
.globl camlTest | |
camlTest: | |
.space 32 | |
.data | |
.quad 3319 | |
camlTest__2: | |
.quad caml_curry3 | |
.quad 7 | |
.quad camlTest__max_1035 | |
.data | |
.quad 2295 | |
camlTest__3: | |
.quad camlTest__squares_1032 | |
.quad 3 | |
.data | |
.quad 2295 | |
camlTest__4: | |
.quad camlTest__fun_1047 | |
.quad 3 | |
.data | |
.globl camlTest__1 | |
.quad 6144 | |
camlTest__1: | |
.quad 1 | |
.quad 21 | |
.quad 41 | |
.quad 51 | |
.quad 95 | |
.quad 121 | |
.text | |
.align 16 | |
.globl camlTest__fun_1047 | |
camlTest__fun_1047: | |
.L100: | |
movq %rax, %rbx | |
sarq $1, %rbx | |
decq %rax | |
imulq %rbx, %rax | |
incq %rax | |
ret | |
.type camlTest__fun_1047,@function | |
.size camlTest__fun_1047,.-camlTest__fun_1047 | |
.text | |
.align 16 | |
.globl camlTest__squares_1032 | |
camlTest__squares_1032: | |
.L101: | |
movq %rax, %rbx | |
movq camlTest__4@GOTPCREL(%rip), %rax | |
jmp camlArray__map_1076@PLT | |
.type camlTest__squares_1032,@function | |
.size camlTest__squares_1032,.-camlTest__squares_1032 | |
.text | |
.align 16 | |
.globl camlTest__max_1035 | |
camlTest__max_1035: | |
subq $40, %rsp | |
.L106: | |
movq %rax, %rsi | |
movq -8(%rbx), %rax | |
shrq $9, %rax | |
orq $1, %rax | |
cmpq %rax, %rdi | |
jne .L105 | |
movq %rsi, %rax | |
addq $40, %rsp | |
ret | |
.align 4 | |
.L105: | |
movq %rdi, 8(%rsp) | |
movq %rbx, 24(%rsp) | |
movq %rsi, 0(%rsp) | |
movq -8(%rbx), %rax | |
movq %rax, %rdx | |
shrq $9, %rdx | |
cmpq %rdi, %rdx | |
jbe .L107 | |
andq $255, %rax | |
cmpq $254, %rax | |
je .L104 | |
movq -4(%rbx, %rdi, 4), %rdi | |
movq %rdi, 16(%rsp) | |
jmp .L103 | |
.align 4 | |
.L104: | |
.L108: subq $16, %r15 | |
movq caml_young_limit@GOTPCREL(%rip), %rax | |
cmpq (%rax), %r15 | |
jb .L109 | |
leaq 8(%r15), %rax | |
movq $1277, -8(%rax) | |
movsd -4(%rbx, %rdi, 4), %xmm0 | |
movsd %xmm0, (%rax) | |
movq %rax, %rdi | |
movq %rdi, 16(%rsp) | |
.L103: | |
movq caml_greaterthan@GOTPCREL(%rip), %rax | |
call caml_c_call@PLT | |
.L111: | |
cmpq $1, %rax | |
je .L102 | |
movq 8(%rsp), %rdi | |
addq $2, %rdi | |
movq 16(%rsp), %rax | |
movq 24(%rsp), %rbx | |
jmp .L106 | |
.align 4 | |
.L102: | |
movq 8(%rsp), %rdi | |
addq $2, %rdi | |
movq 0(%rsp), %rax | |
movq 24(%rsp), %rbx | |
jmp .L106 | |
.L109: call caml_call_gc@PLT | |
.L110: jmp .L108 | |
.L107: call caml_ml_array_bound_error@PLT | |
.type camlTest__max_1035,@function | |
.size camlTest__max_1035,.-camlTest__max_1035 | |
.text | |
.align 16 | |
.globl camlTest__entry | |
camlTest__entry: | |
subq $8, %rsp | |
.L112: | |
movq camlTest__1@GOTPCREL(%rip), %rdi | |
movq caml_obj_dup@GOTPCREL(%rip), %rax | |
call caml_c_call@PLT | |
.L113: | |
movq camlTest@GOTPCREL(%rip), %rbx | |
movq %rax, (%rbx) | |
movq camlTest@GOTPCREL(%rip), %rax | |
movq $33, 8(%rax) | |
movq camlTest__3@GOTPCREL(%rip), %rbx | |
movq camlTest@GOTPCREL(%rip), %rax | |
movq %rbx, 16(%rax) | |
movq camlTest__2@GOTPCREL(%rip), %rbx | |
movq camlTest@GOTPCREL(%rip), %rax | |
movq %rbx, 24(%rax) | |
movq camlTest@GOTPCREL(%rip), %rax | |
movq (%rax), %rax | |
call camlTest__squares_1032@PLT | |
.L114: | |
movq %rax, %rbx | |
movq $1, %rdi | |
movabsq $-9223372036854775807, %rax | |
call camlTest__max_1035@PLT | |
.L115: | |
call camlPervasives__string_of_int_1132@PLT | |
.L116: | |
movq %rax, %rbx | |
movq camlPervasives@GOTPCREL(%rip), %rax | |
movq 184(%rax), %rax | |
call camlPervasives__output_string_1193@PLT | |
.L117: | |
movq $1, %rdi | |
movq camlTest@GOTPCREL(%rip), %rax | |
movq (%rax), %rbx | |
movq $33, %rax | |
call camlTest__max_1035@PLT | |
.L118: | |
call camlPervasives__string_of_int_1132@PLT | |
.L119: | |
movq %rax, %rbx | |
movq camlPervasives@GOTPCREL(%rip), %rax | |
movq 184(%rax), %rax | |
call camlPervasives__output_string_1193@PLT | |
.L120: | |
movq $1, %rax | |
addq $8, %rsp | |
ret | |
.type camlTest__entry,@function | |
.size camlTest__entry,.-camlTest__entry | |
.data | |
.text | |
.globl camlTest__code_end | |
camlTest__code_end: | |
.data | |
.globl camlTest__data_end | |
camlTest__data_end: | |
.long 0 | |
.globl camlTest__frametable | |
camlTest__frametable: | |
.quad 10 | |
.quad .L120 | |
.word 17 | |
.word 0 | |
.align 8 | |
.long (.L200000 - .) + 0xe0000000 | |
.long 0x16d120 | |
.quad .L119 | |
.word 17 | |
.word 0 | |
.align 8 | |
.long (.L200000 - .) + 0xe0000000 | |
.long 0x16d270 | |
.quad .L118 | |
.word 16 | |
.word 0 | |
.align 8 | |
.quad .L117 | |
.word 17 | |
.word 0 | |
.align 8 | |
.long (.L200000 - .) + 0xe0000000 | |
.long 0x16d120 | |
.quad .L116 | |
.word 17 | |
.word 0 | |
.align 8 | |
.long (.L200000 - .) + 0xe0000000 | |
.long 0x16d270 | |
.quad .L115 | |
.word 16 | |
.word 0 | |
.align 8 | |
.quad .L114 | |
.word 16 | |
.word 0 | |
.align 8 | |
.quad .L113 | |
.word 16 | |
.word 0 | |
.align 8 | |
.quad .L111 | |
.word 48 | |
.word 4 | |
.word 0 | |
.word 8 | |
.word 16 | |
.word 24 | |
.align 8 | |
.quad .L110 | |
.word 48 | |
.word 6 | |
.word 0 | |
.word 8 | |
.word 24 | |
.word 5 | |
.word 3 | |
.word 7 | |
.align 8 | |
.L200000: | |
.asciz "pervasives.ml" | |
.align 8 | |
.section .note.GNU-stack,"",%progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment