Skip to content

Commit 54b291e

Browse files
committed
Improve test coverage
1 parent d1fd572 commit 54b291e

File tree

4 files changed

+72
-41
lines changed

4 files changed

+72
-41
lines changed

src/parse/memory_ops_common.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ function dottosym(x::Expr)::Symbol
66
xa2 isa QuoteNode ? Symbol(s1, "###extractarray###", xa2.value) : Symbol(s1, "###extractarray###", xa2)
77
end
88
function extract_array_symbol_from_ref!(ls::LoopSet, ex::Expr, offset1::Int)::Symbol
9-
ar = ex.args[1 + offset1]
10-
if isa(ar, Symbol)
11-
return ar
12-
elseif isa(ar, Expr) && (ar.head === :(.) || ar.head === :ref)
13-
s = dottosym(ar)
14-
pushprepreamble!(ls, Expr(:(=), s, ar))
15-
return s
16-
else
17-
throw("Indexing into the following expression was not recognized: $ar")
18-
end
9+
ar = ex.args[1 + offset1]
10+
if isa(ar, Symbol)
11+
return ar
12+
elseif isa(ar, Expr) && (ar.head === :(.) || ar.head === :ref)
13+
s = dottosym(ar)
14+
pushprepreamble!(ls, Expr(:(=), s, ar))
15+
return s
16+
else
17+
throw("Indexing into the following expression was not recognized: $ar")
18+
end
1919
end
2020

2121

@@ -27,12 +27,12 @@ ref_from_ref!(ls::LoopSet, ex::Expr) = ref_from_expr!(ls, ex, 0, 0)
2727
ref_from_getindex!(ls::LoopSet, ex::Expr) = ref_from_expr!(ls, ex, 1, 1)
2828
ref_from_setindex!(ls::LoopSet, ex::Expr) = ref_from_expr!(ls, ex, 1, 2)
2929
function ref_from_expr!(ls::LoopSet, ex::Expr)
30-
if ex.head === :ref
31-
ref_from_ref!(ls, ex)
32-
else#if ex.head === :call
33-
f = first(ex.args)::Symbol
34-
f === :getindex ? ref_from_getindex!(ls, ex) : ref_from_setindex!(ls, ex)
35-
end
30+
if ex.head === :ref
31+
ref_from_ref!(ls, ex)
32+
else#if ex.head === :call
33+
f = first(ex.args)::Symbol
34+
f === :getindex ? ref_from_getindex!(ls, ex) : ref_from_setindex!(ls, ex)
35+
end
3636
end
3737

3838
add_vptr!(ls::LoopSet, op::Operation) = add_vptr!(ls, op.ref)
@@ -91,20 +91,20 @@ function subset_vptr!(ls::LoopSet, vptr::Symbol, indnum::Int, ind, previndices,
9191
end
9292

9393
function gesp_const_offset!(ls::LoopSet, vptrarray, ninds, indices, loopedindex, mlt::Integer, sym)
94-
if isone(mlt)
95-
subset_vptr!(ls, vptrarray, ninds, sym, indices, loopedindex, false)
96-
else
97-
mltsym = Symbol(sym, "##multiplied##by##", mlt)
98-
pushprepreamble!(ls, Expr(:(=), mltsym, Expr(:call, :(*), mlt, sym))) # want same name for arrays to be given the same name if possible
99-
subset_vptr!(ls, vptrarray, ninds, mltsym, indices, loopedindex, false)
100-
end
94+
if isone(mlt)
95+
subset_vptr!(ls, vptrarray, ninds, sym, indices, loopedindex, false)
96+
else
97+
mltsym = Symbol(sym, "##multiplied##by##", mlt)
98+
pushprepreamble!(ls, Expr(:(=), mltsym, Expr(:call, :(*), mlt, sym))) # want same name for arrays to be given the same name if possible
99+
subset_vptr!(ls, vptrarray, ninds, mltsym, indices, loopedindex, false)
100+
end
101101
end
102102
function gesp_const_offsets!(ls::LoopSet, vptrarray, ninds, indices, loopedindex, mltsyms)
103-
length(mltsyms) > 1 && sort!(mltsyms, by = last) # if multiple have same combination of syms, make sure they match even if order is different
104-
for (mlt,sym) mltsyms
105-
vptrarray = gesp_const_offset!(ls, vptrarray, ninds, indices, loopedindex, mlt, sym)
106-
end
107-
vptrarray
103+
length(mltsyms) > 1 && sort!(mltsyms, by = last) # if multiple have same combination of syms, make sure they match even if order is different
104+
for (mlt,sym) mltsyms
105+
vptrarray = gesp_const_offset!(ls, vptrarray, ninds, indices, loopedindex, mlt, sym)
106+
end
107+
vptrarray
108108
end
109109

110110

@@ -296,7 +296,7 @@ function checkforoffset!(
296296
addconstindex!(indices, offsets, strides, loopedindex, offset)
297297
return vptrarray
298298
elseif length(mult_syms) == 1
299-
mlt, sym = only(mult_syms)
299+
mlt, sym = mult_syms[1]
300300
if sym ls.loopsymbols
301301
if byterepresentable(mlt)
302302
_addoffset!(indices, offsets, strides, loopedindex, loopdependencies, sym, offset, mlt)

src/vectorizationbase_compat/subsetview.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@
3232
StridedPointer{$T,$(N-1),$newC,$B,$newR}($gptr, $newstrd, $newoffsets)
3333
end
3434
end
35-
@generated function _gesp(sp::AbstractStridedPointer{T,N}, ::StaticInt{I}, i::Integer) where {I,N,T}
36-
t = Expr(:tuple)
37-
for j 1:I-1
38-
push!(t.args, staticexpr(0))
39-
end
40-
push!(t.args, :i)
35+
@generated function _gesp(sp, ::StaticInt{I}, i::Integer) where {I,N,T}
36+
t = Expr(:tuple)
37+
for j 1:I-1
38+
push!(t.args, staticexpr(0))
39+
end
40+
push!(t.args, :i)
41+
if I > 1
4142
for j I+1:N
42-
push!(t.args, staticexpr(0))
43-
end
44-
quote
45-
$(Expr(:meta,:inline))
46-
gesp(sp, $t)
43+
push!(t.args, staticexpr(0))
4744
end
45+
end
46+
quote
47+
$(Expr(:meta,:inline))
48+
gesp(sp, $t)
49+
end
4850
end
4951

5052

test/copy.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ using LoopVectorization, OffsetArrays, Test
170170
dest[2, i] = src[1, i]
171171
end
172172
end
173+
174+
function fill_with_3rd!(dest, src)
175+
p = 1
176+
@turbo for i eachindex(dest)
177+
dest[i] = src[3*p]
178+
end
179+
end
180+
function fill_with_r1c3!(dest, src::AbstractMatrix)
181+
p = 1
182+
@turbo for i eachindex(dest)
183+
dest[i] = src[p, 3*p]
184+
end
185+
end
173186

174187
for T (Float32, Float64, Int32, Int64)
175188
@show T, @__LINE__
@@ -201,7 +214,16 @@ using LoopVectorization, OffsetArrays, Test
201214
@test A1 == A2
202215
fill!(A2, 0); offset_copy_avx2!(A2, B);
203216
@test A1 == A2
204-
217+
fill_with_3rd!(A1, B)
218+
@test all(==(B[3]), A1)
219+
fill_with_3rd!(A1, eachindex(B))
220+
@test all(==(3), A1)
221+
222+
fill_with_r1c3!(A1, B)
223+
@test all(==(B[1,3]), A1)
224+
fill_with_r1c3!(A1, LinearIndices(B))
225+
@test all(==(LinearIndices(B)[1,3]), A1)
226+
205227
a = rand(R)
206228
myfillavx!(x, a);
207229
fill!(q2, a);

test/threading.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
using OffsetArrays, LinearAlgebra, LoopVectorization, Test
2+
3+
let nt = min(Threads.nthreads(), (Sys.CPU_THREADS)::Int) - 1
4+
if (LoopVectorization.num_cores() < 4) && (nt 4)
5+
@eval LoopVectorization.num_cores() = LoopVectorization.StaticInt{$nt}()
6+
end
7+
end
8+
29
function mydotavx(a, b)
310
s = zero(eltype(a))
411
@tturbo for i eachindex(a,b)

0 commit comments

Comments
 (0)