Skip to content

Commit 44c12bc

Browse files
committed
Support multiple return values into variables and stores, resolve #41.
1 parent 1665bce commit 44c12bc

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed

src/LoopVectorization.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ If you want good performance, DO NOT use a 32-bit build of Julia if you don't ha
4545
"""
4646
const REGISTER_COUNT = Sys.ARCH === :i686 ? 8 : VectorizationBase.REGISTER_COUNT
4747

48+
include("getconstindexes.jl")
4849
include("vectorizationbase_extensions.jl")
4950
include("predicates.jl")
5051
include("map.jl")

src/costs.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ const COST = Dict{Symbol,InstructionCost}(
233233
:adjoint => InstructionCost(0,0.0,0.0,0),
234234
:conj => InstructionCost(0,0.0,0.0,0),
235235
:transpose => InstructionCost(0,0.0,0.0,0),
236+
:first => InstructionCost(0,0.0,0.0,0),
237+
:second => InstructionCost(0,0.0,0.0,0),
238+
:third => InstructionCost(0,0.0,0.0,0),
239+
:fourth => InstructionCost(0,0.0,0.0,0),
240+
:fifth => InstructionCost(0,0.0,0.0,0),
241+
:sixth => InstructionCost(0,0.0,0.0,0),
242+
:seventh => InstructionCost(0,0.0,0.0,0),
243+
:eigth => InstructionCost(0,0.0,0.0,0),
244+
:ninth => InstructionCost(0,0.0,0.0,0),
236245
:prefetch => InstructionCost(0,0.0,0.0,0),
237246
:prefetch0 => InstructionCost(0,0.0,0.0,0),
238247
:prefetch1 => InstructionCost(0,0.0,0.0,0),

src/graphs.jl

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -669,16 +669,39 @@ function Base.push!(ls::LoopSet, ex::Expr, elementbytes::Int, position::Int)
669669
add_constant!(ls, RHS, ls.loopsymbols[1:position], LHS, elementbytes)
670670
end
671671
elseif LHS isa Expr
672-
@assert LHS.head === :ref
673-
if RHS isa Symbol
674-
add_store_ref!(ls, RHS, LHS, elementbytes)
675-
elseif RHS isa Expr
676-
# need to check if LHS appears in RHS
677-
# assign RHS to lrhs
678-
array, rawindices = ref_from_expr!(ls, LHS)
679-
prepare_rhs_for_storage!(ls, RHS, array, rawindices, elementbytes, position)
672+
if LHS.head === :ref
673+
if RHS isa Symbol
674+
add_store_ref!(ls, RHS, LHS, elementbytes)
675+
elseif RHS isa Expr
676+
# need to check if LHS appears in RHS
677+
# assign RHS to lrhs
678+
array, rawindices = ref_from_expr!(ls, LHS)
679+
prepare_rhs_for_storage!(ls, RHS, array, rawindices, elementbytes, position)
680+
else
681+
add_store_ref!(ls, RHS, LHS, elementbytes)
682+
end
683+
elseif LHS.head === :tuple
684+
@assert length(LHS.args) 9 "Functions returning more than 9 values aren't currently supported."
685+
lhstemp = gensym(:lhstuple)
686+
vparents = Operation[maybe_const_compute!(ls, add_operation!(ls, lhstemp, RHS, elementbytes, position), elementbytes, position)]
687+
for i eachindex(LHS.args)
688+
f = (:first,:second,:third,:fourth,:fifth,:sixth,:seventh,:eigth,:ninth)[i]
689+
lhsi = LHS.args[i]
690+
if lhsi isa Symbol
691+
add_compute!(ls, lhsi, f, vparents, elementbytes)
692+
elseif lhsi isa Expr && lhsi.head === :ref
693+
tempunpacksym = gensym(:tempunpack)
694+
add_compute!(ls, tempunpacksym, f, vparents, elementbytes)
695+
add_store_ref!(ls, tempunpacksym, lhsi, elementbytes)
696+
else
697+
println(lhsi)
698+
throw("Unpacking the above expression in the left hand side was not understood/supported.")
699+
end
700+
end
701+
first(vparents)
680702
else
681-
add_store_ref!(ls, RHS, LHS, elementbytes)
703+
println(LHS)
704+
throw("LHS not understood; only `:ref`s and `:tuple`s are currently supported.")
682705
end
683706
else
684707
println(LHS)

test/special.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,37 @@
303303
end
304304
ent
305305
end
306+
307+
function vsincos(x)
308+
y = Matrix{eltype(x)}(undef, length(x), 2)
309+
for i = eachindex(x)
310+
y[i,1], y[i,2] = sincos(x[i])
311+
end
312+
return y
313+
end
314+
function vsincosavx(x)
315+
y = Matrix{eltype(x)}(undef, length(x), 2)
316+
@avx for i = eachindex(x)
317+
y[i,1], y[i,2] = sincos(x[i])
318+
end
319+
return y
320+
end
321+
function sincosdot(x)
322+
a = zero(eltype(x))
323+
for i eachindex(x)
324+
s, c = sincos(x[i])
325+
a += s * c
326+
end
327+
a
328+
end
329+
function sincosdotavx(x)
330+
a = zero(eltype(x))
331+
@avx for i eachindex(x)
332+
s, c = sincos(x[i])
333+
a += s * c
334+
end
335+
a
336+
end
306337

307338
for T (Float32, Float64)
308339
@show T, @__LINE__
@@ -320,6 +351,9 @@
320351
@test s myvexp_avx(a)
321352
@test b1 @avx exp.(a)
322353

354+
@test vsincos(a) vsincosavx(a)
355+
@test sincosdot(a) sincosdotavx(a)
356+
323357
A = rand(T, 73, 73);
324358
ld = logdet(UpperTriangular(A))
325359
@test ld trianglelogdetavx(A)

0 commit comments

Comments
 (0)