Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Last active February 28, 2016 11:17
Show Gist options
  • Save KristofferC/4be0fea644ef22a4b773 to your computer and use it in GitHub Desktop.
Save KristofferC/4be0fea644ef22a4b773 to your computer and use it in GitHub Desktop.
✔ ~/julia [adr/invert|…6⚑ 3]
12:12 $ ./julia -O
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.5.0-dev+2769 (2016-02-27 17:37 UTC)
_/ |\__'_|_|_|\__'_| | adr/invert/30fb043* (fork: 1 commits, 8 days)
|__/ | x86_64-linux-gnu
julia> immutable Banana{T} # Marked type
x :: T
end
julia> typealias V NTuple{4,Banana{Float32}}
Tuple{Banana{Float32},Banana{Float32},Banana{Float32},Banana{Float32}}
julia> add(u,v) = (Banana(u[1].x+v[1].x),
Banana(u[2].x+v[2].x),
Banana(u[3].x+v[3].x),
Banana(u[4].x+v[4].x))
add (generic function with 1 method)
julia> code_llvm(add,(V,V))
define void @julia_add_22329([4 x %Banana]* sret, [4 x %Banana]*, [4 x %Banana]*) #0 {
top:
%3 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %1, i64 0, i64 0, i32 0
%4 = load float, float* %3, align 4
%5 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %2, i64 0, i64 0, i32 0
%6 = load float, float* %5, align 4
%7 = fadd float %4, %6
%8 = insertvalue %Banana undef, float %7, 0
%9 = insertvalue [4 x %Banana] undef, %Banana %8, 0
%10 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %1, i64 0, i64 1, i32 0
%11 = load float, float* %10, align 4
%12 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %2, i64 0, i64 1, i32 0
%13 = load float, float* %12, align 4
%14 = fadd float %11, %13
%15 = insertvalue %Banana undef, float %14, 0
%16 = insertvalue [4 x %Banana] %9, %Banana %15, 1
%17 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %1, i64 0, i64 2, i32 0
%18 = load float, float* %17, align 4
%19 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %2, i64 0, i64 2, i32 0
%20 = load float, float* %19, align 4
%21 = fadd float %18, %20
%22 = insertvalue %Banana undef, float %21, 0
%23 = insertvalue [4 x %Banana] %16, %Banana %22, 2
%24 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %1, i64 0, i64 3, i32 0
%25 = load float, float* %24, align 4
%26 = getelementptr inbounds [4 x %Banana], [4 x %Banana]* %2, i64 0, i64 3, i32 0
%27 = load float, float* %26, align 4
%28 = fadd float %25, %27
%29 = insertvalue %Banana undef, float %28, 0
%30 = insertvalue [4 x %Banana] %23, %Banana %29, 3
store [4 x %Banana] %30, [4 x %Banana]* %0, align 4
ret void
}
julia> code_native(add,(V,V))
.text
Filename: none
Source line: 0
pushq %rbp
movq %rsp, %rbp
Source line: 1
vmovss (%rsi), %xmm0 # xmm0 = mem[0],zero,zero,zero
vmovss 4(%rsi), %xmm1 # xmm1 = mem[0],zero,zero,zero
vaddss (%rdx), %xmm0, %xmm0
vaddss 4(%rdx), %xmm1, %xmm1
vmovss 8(%rsi), %xmm2 # xmm2 = mem[0],zero,zero,zero
vaddss 8(%rdx), %xmm2, %xmm2
vmovss 12(%rsi), %xmm3 # xmm3 = mem[0],zero,zero,zero
vaddss 12(%rdx), %xmm3, %xmm3
vmovss %xmm3, 12(%rdi)
vmovss %xmm2, 8(%rdi)
vmovss %xmm1, 4(%rdi)
vmovss %xmm0, (%rdi)
movq %rdi, %rax
popq %rbp
retq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment