Skip to content

Commit 5d359b4

Browse files
authored
Merge pull request #141 from JuliaSIMD/noruntimesplat
avoid runtime splats
2 parents a096315 + 2ff483b commit 5d359b4

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Polyester"
22
uuid = "f517fe37-dbe3-4b94-8317-1923a5111588"
33
authors = ["Chris Elrod <elrodc@gmail.com> and contributors"]
4-
version = "0.7.11"
4+
version = "0.7.12"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/closure.jl

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@ extractargs!(arguments::Vector{Symbol}, defined::Dict{Symbol,Symbol}, sym, mod)
1515
# end
1616
# nothing
1717
# end
18+
19+
function _symbols(args)
20+
s = Vector{Symbol}(undef, length(args))
21+
for i in eachindex(args, s)
22+
s[i] = args[i]
23+
end
24+
return s
25+
end
26+
1827
function define_tup!(arguments::Vector{Symbol}, defined::Dict{Symbol,Symbol}, ex::Expr, mod)
1928
for (i, a) enumerate(ex.args)
2029
if a isa Symbol
2130
ex.args[i] = getgensym!(defined, a)
2231
elseif Meta.isexpr(a, :tuple)
23-
define_tup!(Symbol[a.args...], defined, a, mod)
32+
define_tup!(_symbols(a.args), defined, a, mod)
2433
elseif Meta.isexpr(a, :ref)
2534
extractargs!(arguments, defined, a, mod)
2635
elseif Meta.isexpr(a, :parameters)
27-
define_tup!(Symbol[a.args...], defined, a, mod)
36+
define_tup!(_symbols(a.args), defined, a, mod)
2837
else
2938
throw("Don't know how to handle:\n $a")
3039
end
@@ -171,7 +180,12 @@ function extractargs!(
171180
end
172181

173182
function symbolsubs(e::Expr, old::Symbol, new::Symbol)
174-
return Expr(e.head, (symbolsubs(a, old, new) for a in e.args)...)
183+
ex = Expr(e.head)
184+
resize!(ex.args, length(e.args))
185+
for i in eachindex(e.args, ex.args)
186+
ex.args[i] = symbolsubs(e.args[i], old, new)
187+
end
188+
return ex
175189
end
176190
function symbolsubs(e::Symbol, old::Symbol, new::Symbol)
177191
e == old ? new : e
@@ -365,7 +379,8 @@ function enclose(exorig::Expr, minbatchsize, per, threadlocal, reduction, stride
365379
# threadlocal stuff
366380
threadlocal_var_single = gensym(threadlocal_var)
367381
threadlocal_val, threadlocal_type = threadlocal
368-
q_single = threadlocal_val === Symbol("") ? exorig :
382+
q_single =
383+
threadlocal_val === Symbol("") ? exorig :
369384
symbolsubs(exorig, threadlocal_var, threadlocal_var_single)
370385
# threadlocal_type = getfield(mod, threadlocal_type)
371386
threadlocal_accum = Symbol("##THREADLOCAL##ACCUM##")
@@ -378,10 +393,11 @@ function enclose(exorig::Expr, minbatchsize, per, threadlocal, reduction, stride
378393
threadlocal_val === Symbol("") ? donothing :
379394
:($(esc(threadlocal_var)) = [single_thread_result])
380395
threadlocal_init =
381-
threadlocal_val === Symbol("") ? donothing : quote
382-
$(esc(threadlocal_accum)) =
383-
Vector{$threadlocal_type}(undef, max(1, $(threadtup.args[2])))
384-
end
396+
threadlocal_val === Symbol("") ? donothing :
397+
quote
398+
$(esc(threadlocal_accum)) =
399+
Vector{$threadlocal_type}(undef, max(1, $(threadtup.args[2])))
400+
end
385401
threadlocal_vect =
386402
threadlocal_val === Symbol("") ? donothing :
387403
:($(esc(threadlocal_var)) = multi_thread_result)
@@ -391,8 +407,7 @@ function enclose(exorig::Expr, minbatchsize, per, threadlocal, reduction, stride
391407
threadlocal_set =
392408
threadlocal_val === Symbol("") ? donothing :
393409
:($threadlocal_accum[var"##THREAD##"] = $threadlocal_var_gen)
394-
threadlocal_return =
395-
threadlocal_val === Symbol("") ? donothing : :($threadlocal_accum)
410+
threadlocal_return = threadlocal_val === Symbol("") ? donothing : :($threadlocal_accum)
396411
threadlocal_val !== Symbol("") && push!(q.args, threadlocal_init)
397412
# reduction stuff
398413
reduction_ops = Expr(:tuple)
@@ -650,7 +665,7 @@ macro batch(arg1, ex)
650665
threadlocal,
651666
reduction,
652667
stride,
653-
__module__
668+
__module__,
654669
)
655670
end
656671
macro batch(arg1, arg2, ex)
@@ -665,7 +680,7 @@ macro batch(arg1, arg2, ex)
665680
threadlocal,
666681
reduction,
667682
stride,
668-
__module__
683+
__module__,
669684
)
670685
end
671686
macro batch(arg1, arg2, arg3, ex)
@@ -682,7 +697,7 @@ macro batch(arg1, arg2, arg3, ex)
682697
threadlocal,
683698
reduction,
684699
stride,
685-
__module__
700+
__module__,
686701
)
687702
end
688703
macro batch(arg1, arg2, arg3, arg4, ex)
@@ -701,7 +716,7 @@ macro batch(arg1, arg2, arg3, arg4, ex)
701716
threadlocal,
702717
reduction,
703718
stride,
704-
__module__
719+
__module__,
705720
)
706721
end
707722
macro batch(arg1, arg2, arg3, arg4, arg5, ex)
@@ -722,6 +737,6 @@ macro batch(arg1, arg2, arg3, arg4, arg5, ex)
722737
threadlocal,
723738
reduction,
724739
stride,
725-
__module__
740+
__module__,
726741
)
727742
end

0 commit comments

Comments
 (0)