comparison stencil.jl @ 131:8569c637d923 cell_based_test

Enable compiler loop-unrolling in apply_backwards
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 21 Feb 2019 14:11:08 +0100
parents 1aaeb46ba5f4
children 6b6d921e8f05
comparison
equal deleted inserted replaced
130:155bbecf18bb 131:8569c637d923
15 end 15 end
16 return s.weights[1 + i - s.range[1]] 16 return s.weights[1 + i - s.range[1]]
17 end 17 end
18 18
19 Base.@propagate_inbounds @inline function apply(s::Stencil{T,N}, v::AbstractVector, i::Int) where {T,N} 19 Base.@propagate_inbounds @inline function apply(s::Stencil{T,N}, v::AbstractVector, i::Int) where {T,N}
20 w = s.weights[1]*v[i+ s.range[1]] 20 w = s.weights[1]*v[i + s.range[1]]
21 @simd for k ∈ 2:N 21 @simd for k ∈ 2:N
22 w += s.weights[k]*v[i+ s.range[1] + k-1] 22 w += s.weights[k]*v[i + s.range[1] + k-1]
23 end 23 end
24 return w 24 return w
25 end 25 end
26 26
27 # TODO: Fix loop unrolling here as well. Then we can also remove Base.getindex(::Stencil) 27 Base.@propagate_inbounds @inline function apply_backwards(s::Stencil{T,N}, v::AbstractVector, i::Int) where {T,N}
28 Base.@propagate_inbounds @inline function apply_backwards(s::Stencil, v::AbstractVector, i::Int) 28 w = s.weights[N]*v[i - s.range[2]]
29 w = zero(eltype(v)) 29 @simd for k ∈ N-1:-1:1
30 for j ∈ s.range[2]:-1:s.range[1] 30 w += s.weights[k]*v[i - s.range[1] - k + 1]
31 @inbounds weight = s[j]
32 w += weight*v[i-j]
33 end 31 end
34 return w 32 return w
35 end 33 end