Mercurial > repos > public > sbplib_julia
changeset 128:7c0b9bb7ab4d cell_based_test
Improve stencil application code to make it more friendly to compiler optimizations
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 14 Feb 2019 12:46:58 +0100 |
parents | 22642722a8ec |
children | 1aaeb46ba5f4 |
files | stencil.jl |
diffstat | 1 files changed, 5 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/stencil.jl Wed Feb 13 11:03:39 2019 +0100 +++ b/stencil.jl Thu Feb 14 12:46:58 2019 +0100 @@ -9,24 +9,22 @@ end # Provides index into the Stencil based on offset for the root element -function Base.getindex(s::Stencil, i::Int) +@inline function Base.getindex(s::Stencil, i::Int) @boundscheck if i < s.range[1] || s.range[2] < i return eltype(s.weights)(0) end - return s.weights[1 + i - s.range[1]] end -Base.@propagate_inbounds function apply(s::Stencil, v::AbstractVector, i::Int) +Base.@propagate_inbounds @inline function apply(s::Stencil{T,N}, v::AbstractVector, i::Int) where {T,N} w = zero(eltype(v)) - for j ∈ s.range[1]:s.range[2] - @inbounds weight = s[j] - w += weight*v[i+j] + @simd for k ∈ 1:N + w += s.weights[k]*v[i+ s.range[1] + k-1] end return w end -Base.@propagate_inbounds function apply_backwards(s::Stencil, v::AbstractVector, i::Int) +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]