Skip to content

Instantly share code, notes, and snippets.

@ArchRobison
Created May 22, 2014 22:32
Show Gist options
  • Select an option

  • Save ArchRobison/477eb33a6bac0aa17218 to your computer and use it in GitHub Desktop.

Select an option

Save ArchRobison/477eb33a6bac0aa17218 to your computer and use it in GitHub Desktop.
::::::::::::::
test1.jl
::::::::::::::
# Example from early discussion.
# Has constant lower bound, expression as upper bound, and no reductions.
function test1( a, x, y )
@simd for i=1:length(x)
@inbounds y[i] = y[i]+a*x[i]
end
end
F1d = Array{Float32,1}
type1 = (Float32,F1d,F1d)
code_llvm(test1,type1)
::::::::::::::
test2.jl
::::::::::::::
# Example from documentation
function test2( x, y )
s = zero(eltype(x))
@simd for i=1:length(x)
@inbounds s += x[i]*y[i]
end
s
end
F1d = Array{Float32,1}
type2 = (F1d,F1d)
code_llvm(test2,type2)
::::::::::::::
test3.jl
::::::::::::::
# Seismic duck example. Uses range variables.
function test3( irange, jrange, U, Vx, Vy, A, B )
for j in jrange
@simd for i in irange
@inbounds begin
u = U[i,j]
Vx[i,j] += (A[i,j+1]+A[i,j])*(U[i,j+1]-u)
Vy[i,j] += (A[i+1,j]+A[i,j])*(U[i+1,j]-u)
U [i,j] = u + B[i,j]*((Vx[i,j]-Vx[i,j-1]) + (Vy[i,j]-Vy[i-1,j]))
end
end
end
end
F2d = Array{Float32,2}
type3 = (typeof(1:32),typeof(1:32),F2d,F2d,F2d,F2d,F2d)
code_llvm(test3,type3)
::::::::::::::
test4.jl
::::::::::::::
# Example from issue #6903
function test4( x, istart, iend )
s = zero(eltype(x))
@simd for i = istart:iend
@inbounds s += x[i]
end
s
end
F1d = Array{Float32,1}
type4 = (F1d,Int,Int)
code_llvm(test4,type4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment