Skip to content

Instantly share code, notes, and snippets.

@toivoh
toivoh / TestSIMD.jl
Created October 31, 2014 21:02
Trying to get Julia to produce an unrolled loop with SIMD instructions in it
module TestSIMD
immutable TypeConst{T} end
function innerloop!{T, M}(dest::Vector{T}, dest_ofs, src::Vector{T}, src_ofs, ::TypeConst{M})
@simd for i=1:M
@inbounds dest[i + dest_ofs] $= src[i + src_ofs]
end
end
@toivoh
toivoh / TestSIMD2.jl
Created November 2, 2014 09:08
Trying to get Julia to emit an efficient sequence of SIMD instructions with the aid of llvmcall
module TestSIMD2
# requires Julia 0.4 for llvmcall
typealias Uint64x2 NTuple{2, Uint64}
function ($)(x::Uint64x2, y::Uint64x2)
Base.llvmcall("""%3 = xor <2 x i64> %1, %0
ret <2 x i64> %3""",
Uint64x2, (Uint64x2, Uint64x2), x, y)
end
@toivoh
toivoh / TestSIMDrmw.jl
Created November 5, 2014 20:41
Getting SIMD load/store instructions through llvmcall
module TestSIMD5
typealias Uint64x2 NTuple{2, Uint64}
function ($)(x::Uint64x2, y::Uint64x2)
Base.llvmcall("""%3 = xor <2 x i64> %1, %0
ret <2 x i64> %3""",
Uint64x2, (Uint64x2, Uint64x2), x, y)
end
unsafe_aligned_load(p::Ptr{Uint64}, i::Int) = unsafe_aligned_load(ptradd(p, (i-1)*sizeof(Uint64)*2))
@toivoh
toivoh / TestSLP.jl
Last active August 29, 2015 14:08
Trying out the SLP vectorizer with Julia
module TestSLP
function rmw!{T}(dest::Ptr{T}, src::Ptr{T})
s1 = unsafe_load(src, 1)
s2 = unsafe_load(src, 2)
d1 = unsafe_load(dest, 1)
d2 = unsafe_load(dest, 2)
d1 $= s1
d2 $= s2
unsafe_store!(dest, d1, 1)
@toivoh
toivoh / bigfunction_parts.jl
Created November 2, 2016 07:38
Julia JIT compiler scaling benchmark
function code_big_function(n::Int)
code = [:( $(Symbol("x$k")) = $(Symbol("x$(k-1)")) + 1 ) for k=1:n]
quote
let
function f(x0)
$(code...)
return $(Symbol("x$n"))
end
end
end