Skip to content

Commit b12cd7a

Browse files
committed
Updates for increased use of static offsets.
1 parent c1b3842 commit b12cd7a

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

src/LoopVectorization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using VectorizationBase: REGISTER_SIZE, extract_data, num_vector_load_expr,
1111
Static, Zero, StaticUnitRange, StaticLowerUnitRange, StaticUpperUnitRange, unwrap, maybestaticrange,
1212
AbstractColumnMajorStridedPointer, AbstractRowMajorStridedPointer, AbstractSparseStridedPointer, AbstractStaticStridedPointer,
1313
PackedStridedPointer, SparseStridedPointer, RowMajorStridedPointer, StaticStridedPointer, StaticStridedStruct,
14-
maybestaticfirst, maybestaticlast, scalar_less, scalar_greater, noalias!, gesp, gepbyte, pointerforcomparison, NativeTypes
14+
maybestaticfirst, maybestaticlast, scalar_less, scalar_greater, noalias!, gesp, gepbyte, pointerforcomparison, NativeTypes, staticmul, staticmuladd
1515
using SIMDPirates: VECTOR_SYMBOLS, evadd, evsub, evmul, evfdiv, vrange,
1616
reduced_add, reduced_prod, reduce_to_add, reduced_max, reduced_min, vsum, vprod, vmaximum, vminimum,
1717
sizeequivalentfloat, sizeequivalentint, vadd!, vsub!, vmul!, vfdiv!, vfmadd!, vfnmadd!, vfmsub!, vfnmsub!,

src/loopstartstopmanager.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ function pointermax(ls::LoopSet, ar::ArrayReferenceMeta, n::Int, sub::Int, isvec
197197
end
198198
@show ar, loopsym
199199
end
200+
# @inline function assume_a_greater_than_b_ret_a(a::Ptr, b::VectorizationBase.AbstractStridedPointer)
201+
# SIMDPirates.assume(pointer(b) < a)
202+
# a
203+
# end
204+
# @inline assume_a_greater_than_b_ret_a(a, b) = a
200205
function defpointermax(ls::LoopSet, ar::ArrayReferenceMeta, n::Int, sub::Int, isvectorized::Bool)::Expr
206+
# Expr(:(=), maxsym(vptr(ar), sub), Expr(:call, lv(:assume_a_greater_than_b_ret_a), pointermax(ls, ar, n, sub, isvectorized), vptr(ar)))
201207
Expr(:(=), maxsym(vptr(ar), sub), pointermax(ls, ar, n, sub, isvectorized))
202208
end
203209

src/lower_memory_common.jl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ function symbolind(ind::Symbol, op::Operation, td::UnrollArgs)
1919
Expr(:call, lv(:staticm1), ex)
2020
end
2121

22-
22+
staticexpr(x::Integer) = Expr(:call, Expr(:curly, lv(:Static), convert(Int, x)))
23+
staticexpr(x) = Expr(:call, lv(:Static), x)
24+
maybestatic(x::Integer) = staticexpr(x)
25+
maybestatic(x) = x
2326
_MMind(ind) = Expr(:call, lv(:_MM), VECTORWIDTHSYMBOL, ind)
24-
_MMind(ind::Integer) = Expr(:call, lv(:_MM), VECTORWIDTHSYMBOL, convert(Int, ind))
27+
_MMind(ind::Integer) = Expr(:call, lv(:_MM), VECTORWIDTHSYMBOL, staticexpr(ind))
2528
function addoffset!(ret::Expr, ex, offset::Integer, _mm::Bool = false)
2629
if iszero(offset)
2730
if _mm
@@ -31,20 +34,15 @@ function addoffset!(ret::Expr, ex, offset::Integer, _mm::Bool = false)
3134
return
3235
end
3336
elseif _mm
34-
ind = _MMind(Expr(:call, lv(:vadd), ex, convert(Int, offset)))
37+
ind = _MMind(Expr(:call, lv(:vadd), ex, staticexpr(offset)))
3538
else
36-
ind = Expr(:call, lv(:vadd), ex, convert(Int, offset))
39+
ind = Expr(:call, lv(:vadd), ex, staticexpr(offset))
3740
end
3841
push!(ret.args, ind)
3942
nothing
4043
end
4144
function addoffset!(ret::Expr, offset::Int, _mm::Bool = false)
42-
ex = Expr(:call, Expr(:curly, lv(:Static), offset))
43-
if _mm
44-
push!(ret.args, _MMind(ex))
45-
else
46-
push!(ret.args, ex)
47-
end
45+
push!(ret.args, _mm ? _MMind(offset) : staticexpr(offset))
4846
nothing
4947
end
5048

@@ -83,9 +81,9 @@ end
8381
function add_vectorized_offset!(ret::Expr, ind, offset, incr)
8482
if isone(incr)
8583
if iszero(offset)
86-
push!(ret.args, _MMind(Expr(:call, lv(:valadd), VECTORWIDTHSYMBOL, ind)))
84+
push!(ret.args, _MMind(Expr(:call, lv(:valadd), VECTORWIDTHSYMBOL, maybestatic(ind))))
8785
else
88-
push!(ret.args, _MMind(Expr(:call, lv(:vadd), ind, Expr(:call, lv(:valadd), VECTORWIDTHSYMBOL, convert(Int, offset)))))
86+
push!(ret.args, _MMind(Expr(:call, lv(:vadd), ind, Expr(:call, lv(:valadd), VECTORWIDTHSYMBOL, staticexpr(offset)))))
8987
end
9088
elseif iszero(incr)
9189
if iszero(offset)
@@ -94,28 +92,28 @@ function add_vectorized_offset!(ret::Expr, ind, offset, incr)
9492
addoffset!(ret, ind, offset, true)
9593
end
9694
elseif iszero(offset)
97-
push!(ret.args, _MMind(Expr(:call, lv(:valmuladd), VECTORWIDTHSYMBOL, incr, ind)))
95+
push!(ret.args, _MMind(Expr(:call, lv(:staticmuladd), VECTORWIDTHSYMBOL, maybestatic(incr), maybestatic(ind))))
9896
else
99-
push!(ret.args, _MMind(Expr(:call, lv(:vadd), ind, Expr(:call, lv(:valmuladd), VECTORWIDTHSYMBOL, incr, convert(Int, offset)))))
97+
push!(ret.args, _MMind(Expr(:call, lv(:vadd), ind, Expr(:call, lv(:staticmuladd), VECTORWIDTHSYMBOL, maybestatic(incr), staticexpr(offset)))))
10098
end
10199
end
102100
function add_vectorized_offset_unrolled!(ret::Expr, offset, incr)
103101
if isone(incr)
104102
if iszero(offset)
105-
push!(ret.args, _MMind(Expr(:call, lv(:unwrap), VECTORWIDTHSYMBOL)))
103+
push!(ret.args, _MMind(Expr(:call, lv(:Static), VECTORWIDTHSYMBOL)))
106104
else
107-
push!(ret.args, _MMind(Expr(:call, lv(:valadd), VECTORWIDTHSYMBOL, convert(Int, offset))))
105+
push!(ret.args, _MMind(Expr(:call, lv(:valadd), VECTORWIDTHSYMBOL, staticexpr(offset))))
108106
end
109107
elseif iszero(incr)
110108
if iszero(offset)
111109
push!(ret.args, _MMind(Expr(:call, lv(:Zero))))
112110
else
113-
push!(ret.args, _MMind(convert(Int, offset)))
111+
push!(ret.args, _MMind(staticexpr(offset)))
114112
end
115113
elseif iszero(offset)
116-
push!(ret.args, _MMind(Expr(:call, lv(:valmul), VECTORWIDTHSYMBOL, incr)))
114+
push!(ret.args, _MMind(Expr(:call, lv(:staticmul), VECTORWIDTHSYMBOL, maybestatic(incr))))
117115
else
118-
push!(ret.args, _MMind(Expr(:call, lv(:valmuladd), VECTORWIDTHSYMBOL, incr, convert(Int, offset))))
116+
push!(ret.args, _MMind(Expr(:call, lv(:staticmuladd), VECTORWIDTHSYMBOL, maybestatic(incr), staticexpr(offset))))
119117
end
120118
end
121119
function add_vectorized_offset!(ret::Expr, ind, offset, incr, unrolled)

src/reconstruct_loopset.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ function add_mref!(
156156
) where {T,N,P}
157157
add_mref!(ls, ar, i, P, name)
158158
end
159+
function add_mref!(
160+
ls::LoopSet, ar::ArrayReferenceMeta, i::Int, ::Type{VectorizationBase.ZeroInitializedStridedPointer{T,P}}, name
161+
) where {T,P}
162+
add_mref!(ls, ar, i, P, name)
163+
end
159164
function add_mref!(
160165
ls::LoopSet, ar::ArrayReferenceMeta, i::Int, ::Type{S}, name
161166
) where {T, X <: Tuple, S <: AbstractStaticStridedPointer{T,X}}

0 commit comments

Comments
 (0)