From b0709800418eb296f048274d7492205401b7e98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= Date: Sat, 22 Jun 2019 18:25:45 +0200 Subject: [PATCH] Detect intrinsic FP functions (instead of higher-level ones) --- src/overdub.jl | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/overdub.jl b/src/overdub.jl index 849b0d9..51635cd 100644 --- a/src/overdub.jl +++ b/src/overdub.jl @@ -2,25 +2,37 @@ using Cassette Cassette.@context CounterCtx; -ops = [ - (:add32, +, Float32, Float32), - (:sub32, -, Float32, Float32), - (:mul32, *, Float32, Float32), - (:div32, /, Float32, Float32), - (:add64, +, Float64, Float64), - (:sub64, -, Float64, Float64), - (:mul64, *, Float64, Float64), - (:div64, /, Float64, Float64), -] +const ops = ( + (:add32, Core.Intrinsics.add_float, Float32), + (:sub32, Core.Intrinsics.sub_float, Float32), + (:mul32, Core.Intrinsics.mul_float, Float32), + (:div32, Core.Intrinsics.div_float, Float32), + (:add64, Core.Intrinsics.add_float, Float64), + (:sub64, Core.Intrinsics.sub_float, Float64), + (:mul64, Core.Intrinsics.mul_float, Float64), + (:div64, Core.Intrinsics.div_float, Float64), +) @eval mutable struct Counter $((:($(op[1]) ::Int) for op in ops)...) Counter() = new($((0 for _ in 1:length(ops))...)) end -for (name, op, typ1, typ2) in ops - @eval function Cassette.prehook(ctx::CounterCtx, op::typeof($op), a::$typ1, b::$typ2) - ctx.metadata.$name +=1 +for typ1 in (Float32, Float64) + @eval function Cassette.prehook(ctx::CounterCtx, + op::Core.IntrinsicFunction, + ::$typ1, + ::$typ1) + $(Expr(:block, + (map(ops) do (name, op, typ2) + typ1 == typ2 || return :nothing + quote + if op == $op + ctx.metadata.$name += 1 + return + end + end + end)...)) end end