Created
June 21, 2021 00:15
-
-
Save Keno/d0c2df947f67be543036238a0caeb1c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@compiler_plugin FastSinPlugin | |
#= | |
Some sort of implementation of FastSinPlugin where | |
sin(x::Float64) is replaced by fast_sin(x::Float64). | |
N.B.: If the function being called is not `sin`, this | |
needs to recurse. | |
N.B.: This needs to handle the non-inferred case | |
N.B.: This should be done in the optimizer and may assume | |
that inference results are not invalidated. A separate plugin | |
should be able to replace method tables and simply return the | |
method for sin(::Float64) by the method for fast_sin(::Float64), | |
but that's a separate case | |
N.B.: This may share inference caches with regular inference, | |
but may not share optimized code caches. | |
=# | |
let counter = 0 | |
global fast_sin, counter | |
fast_sin(x::Float64) = (counter += 1; sin(x::Float64)) | |
get_fast_sin_counter() = counter | |
reset_counter() = (counter = 0) | |
end | |
get_sin() = sin | |
function my_func(x) | |
reset_counter() | |
sin(x) | |
@test get_fast_sin_counter() == 1 | |
get_sin()(x) | |
@test get_fast_sin_counter() == 2 | |
get_sin()(Base.inferencebarrier(x)) | |
@test get_fast_sin_counter() == 3 | |
end | |
with(FastSinPlugin) do | |
my_func(1.0) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment