10 ms·
In Julia you can do `@fastmath ...`, which is basically just a find-and-replace of math operations and does not propagate into functions called in that code blo
by stabbles 5y ago
In Julia you can do `@fastmath ...`, which is basically just a find-and-replace of math operations and does not propagate into functions called in that code block, even when they are ultimately inlined. So what it does is:
julia> @macroexpand @fastmath x + y
:(Base.FastMath.add_fast(x, y))
And maybe that's a good thing, because the scope of @fastmath is as limited as it gets.
- celrod 5y agoYeah, I really like that Julia and LLVM allow applying it on a per-operation basis. Because most of LLVM's backends don't allow for the same level of granularity, they do end up propagating some information more than I would like. For example, marking an operation as fast lets LLVM assume that it does not result in NaNs, letting nan checks get compiled away even though they themselves are not marked fast: julia> add_isnan(a,b) = isnan(@fastmath(a+b)) add_isnan (generic function with 1 method) julia> @code_llvm debuginfo=:none add_isnan(1.2,2.3) define i8 @julia_add_isnan_597(double %0, double %1) #0 { top: ret i8 0 } meaning it remains more dangerous to use than it IMO should be. For this reason, LoopVectorization.jl does not apply "nonans".