Skip to content

Commit

Permalink
handle inbounds and insert julia.simdloop to every loop
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Feb 25, 2025
1 parent f41cab4 commit 1453a50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
14 changes: 1 addition & 13 deletions src/Trixi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,7 @@ if _PREFERENCE_LOOPVECTORIZATION
using LoopVectorization: LoopVectorization, @turbo, indices
else
using LoopVectorization: LoopVectorization, indices
macro turbo(exprs...)
body = nothing
for expr in exprs
if expr.head == :for
body = expr
end
end
@assert body !== nothing
# TODO: We should insert !loopinfo !julia.ivdep !julia.simd
# but SimdLoop.compile doesn't deal with nested for loops.
# esc(Base.SimdLoop.compile(body, Symbol("julia.ivdep")))
return esc(body)
end
include("auxiliary/mock_turbo.jl")
end

using StaticArrayInterface: static_length # used by LoopVectorization
Expand Down
28 changes: 28 additions & 0 deletions src/auxiliary/mock_turbo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
macro turbo(exprs...)
body = nothing
for expr in exprs
if Meta.isexpr(expr, :for)
body = expr
end
end
@assert body !== nothing

function insert_loopinfo!(expr)
recurse = Meta.isexpr(expr, :for) || Meta.isexpr(expr, :block) ||
Meta.isexpr(expr, :let)
if recurse
foreach(insert_loopinfo!, expr.args)
end
if Meta.isexpr(expr, :for)
# TODO: Should we insert LLVM loopinfo or `julia.ivdep`?
push!(expr.args, Expr(:loopinfo, Symbol("julia.simdloop")))
end
end
insert_loopinfo!(body)

body = Expr(:block,
Expr(:inbounds, true),
body,
Expr(:inbounds, :pop))
return esc(body)
end

0 comments on commit 1453a50

Please sign in to comment.