Created
March 31, 2019 19:56
-
-
Save timholy/369c3fbf5d64ee09c3f9692e2db6c489 to your computer and use it in GitHub Desktop.
Test the impact of inlining on the interpreter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function summer(A) | |
s = zero(eltype(A)) | |
for a in A | |
s += a | |
end | |
return s | |
end | |
function summer_inlined(A) | |
TA = typeof(A) | |
T = eltype(TA) | |
s = Base.sitofp(T, 0) | |
i = 1 | |
@label itertop | |
iu = Base.bitcast(UInt, i) | |
IT = promote_type(typeof(iu), typeof(1)) | |
iuu = Base.bitcast(IT, iu) | |
u1 = Base.bitcast(IT, 1) | |
Base.not_sametype((iu, 1), (iuu, u1)) | |
j = Base.sub_int(iuu, u1) | |
len = Base.arraylen(A) | |
if Base.and_int(Base.sle_int(0, len), Base.ult_int(j, Base.bitcast(IT, len))) | |
apre = @inbounds Core.arrayref(true, A, i) | |
ipre = Base.add_int(i, 1) | |
iterresult = (apre, ipre) | |
else | |
iterresult = nothing | |
end | |
itercmp = iterresult === nothing | |
if Base.not_int(itercmp) | |
a = getfield(iterresult, 1) | |
i = getfield(iterresult, 2) | |
s = Base.add_float(s, a) | |
@goto itertop | |
end | |
return s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment