by peter_d_sherman · 6y ago · 0 comments
"
julia> a = function (x); x += 1; x += 1; return x; end
#13 (generic function with 1 method)
julia> @code_llvm a(3)
; @ none:1 within `#13'
define i64 @"julia_#13_17607"(i64) {
top:
; ┌ @ int.jl:53 within `+'
%1 = add i64 %0, 2 <-- <one instruction, not two>
; └ ret i64 %1
}"Prior to reading this article, I did not know that Julia could compile LLVM at the function level... very cool!
julia> a=1+2im; b=2+4im; @code_native a+b
.text
; ┌ @ complex.jl:271 within `+'
pushq %rbp
movq %rsp, %rbp
; │ @ complex.jl:271 within `+' @ int.jl:53
vmovdqu (%r8), %xmm0
vpaddq (%rdx), %xmm0, %xmm0
; │ @ complex.jl:271 within `+'
vmovdqu %xmm0, (%rcx)
movq %rcx, %rax
popq %rbp
retq
nopw %cs:(%rax,%rax)
; └