Skip to content

Instantly share code, notes, and snippets.

@lucasb-eyer
Last active January 2, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasb-eyer/8375355 to your computer and use it in GitHub Desktop.
Save lucasb-eyer/8375355 to your computer and use it in GitHub Desktop.
Julia Codegen analysis!
julia> function f(x)
for i=1:length(x)
@inbounds x[i] *= 2
end
end
f (generic function with 1 method)
julia> code_llvm(f, (Matrix{Float64},))
define internal void @julia_f(%jl_value_t*) {
top:
%1 = getelementptr inbounds %jl_value_t* %0, i64 2, i32 0, !dbg !578
%2 = load %jl_value_t** %1, align 8, !dbg !578
%3 = icmp slt %jl_value_t* %2, inttoptr (i64 1 to %jl_value_t*), !dbg !583
br i1 %3, label %L2, label %if.lr.ph, !dbg !583
if.lr.ph: ; preds = %top
%4 = getelementptr inbounds %jl_value_t* %0, i64 1, i32 0, !dbg !578
%5 = load %jl_value_t** %4, align 8, !dbg !578
%6 = ptrtoint %jl_value_t* %2 to i64, !dbg !578
br label %if, !dbg !583
if: ; preds = %if.lr.ph, %if
%"#s1.03" = phi i64 [ 1, %if.lr.ph ], [ %12, %if ]
%7 = add i64 %"#s1.03", -1, !dbg !584
%8 = getelementptr %jl_value_t* %5, i64 %7, !dbg !584
%9 = bitcast %jl_value_t* %8 to double*, !dbg !584
%10 = load double* %9, align 8, !dbg !584
%11 = fmul double %10, 2.000000e+00, !dbg !584
store double %11, double* %9, align 8, !dbg !584
%12 = add i64 %"#s1.03", 1, !dbg !585
%13 = icmp sgt i64 %12, %6, !dbg !583
br i1 %13, label %L2, label %if, !dbg !583
L2: ; preds = %if, %top
ret void, !dbg !585
}
julia> code_native(f, (Matrix{Float64},))
.text
Filename: none
Source line: 2
push RBP
mov RBP, RSP
Source line: 2
mov RAX, QWORD PTR [RDI + 16]
test RAX, RAX
jle 37
mov RCX, QWORD PTR [RDI + 8]
mov EDX, 1
Source line: 151
vmovsd XMM0, QWORD PTR [RCX]
vaddsd XMM0, XMM0, XMM0
vmovsd QWORD PTR [RCX], XMM0
Source line: 2
add RCX, 8
Source line: 152
inc RDX
cmp RDX, RAX
Source line: 2
jle -28
Source line: 152
pop RBP
ret
julia>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment