Mercurial > repos > public > sbplib_julia
changeset 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 | 155bbecf18bb |
children | 6b6d921e8f05 c6aaf061c0a9 |
files | stencil.jl |
diffstat | 1 files changed, 6 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/stencil.jl Thu Feb 21 11:40:48 2019 +0100 +++ b/stencil.jl Thu Feb 21 14:11:08 2019 +0100 @@ -17,19 +17,17 @@ end Base.@propagate_inbounds @inline function apply(s::Stencil{T,N}, v::AbstractVector, i::Int) where {T,N} - w = s.weights[1]*v[i+ s.range[1]] + w = s.weights[1]*v[i + s.range[1]] @simd for k ∈ 2:N - w += s.weights[k]*v[i+ s.range[1] + k-1] + w += s.weights[k]*v[i + s.range[1] + k-1] end return w end -# TODO: Fix loop unrolling here as well. Then we can also remove Base.getindex(::Stencil) -Base.@propagate_inbounds @inline function apply_backwards(s::Stencil, v::AbstractVector, i::Int) - w = zero(eltype(v)) - for j ∈ s.range[2]:-1:s.range[1] - @inbounds weight = s[j] - w += weight*v[i-j] +Base.@propagate_inbounds @inline function apply_backwards(s::Stencil{T,N}, v::AbstractVector, i::Int) where {T,N} + w = s.weights[N]*v[i - s.range[2]] + @simd for k ∈ N-1:-1:1 + w += s.weights[k]*v[i - s.range[1] - k + 1] end return w end