Last active
October 20, 2016 08:22
-
-
Save musm/8150451b04120ef27974d8270dedbf6f to your computer and use it in GitHub Desktop.
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
using BenchmarkTools | |
using Base: sign_mask, exponent_mask | |
typealias IEEEFloat Union{Float16,Float32,Float64} | |
_isinf{T<:IEEEFloat}(x::T) = (reinterpret(Unsigned, x) & ~sign_mask(T)) == exponent_mask(T) | |
_isfinite{T<:IEEEFloat}(x::T) = (reinterpret(Unsigned, x) & exponent_mask(T)) != exponent_mask(T) | |
_isnan{T<:IEEEFloat}(x::T) = (reinterpret(Unsigned, x) & ~sign_mask(T)) > exponent_mask(T) | |
julia> @benchmark isinf(2.0) | |
BenchmarkTools.Trial: | |
samples: 10000 | |
evals/sample: 1000 | |
time tolerance: 5.00% | |
memory tolerance: 1.00% | |
memory estimate: 0.00 bytes | |
allocs estimate: 0 | |
minimum time: 1.578 ns (0.00% GC) | |
median time: 1.579 ns (0.00% GC) | |
mean time: 1.723 ns (0.00% GC) | |
maximum time: 12.632 ns (0.00% GC) | |
julia> @benchmark _isinf(2.0) | |
BenchmarkTools.Trial: | |
samples: 10000 | |
evals/sample: 1000 | |
time tolerance: 5.00% | |
memory tolerance: 1.00% | |
memory estimate: 0.00 bytes | |
allocs estimate: 0 | |
minimum time: 1.578 ns (0.00% GC) | |
median time: 1.973 ns (0.00% GC) | |
mean time: 1.832 ns (0.00% GC) | |
maximum time: 115.269 ns (0.00% GC) | |
julia> @benchmark _isnan(2.0) | |
BenchmarkTools.Trial: | |
samples: 10000 | |
evals/sample: 1000 | |
time tolerance: 5.00% | |
memory tolerance: 1.00% | |
memory estimate: 0.00 bytes | |
allocs estimate: 0 | |
minimum time: 1.578 ns (0.00% GC) | |
median time: 1.579 ns (0.00% GC) | |
mean time: 1.790 ns (0.00% GC) | |
maximum time: 88.031 ns (0.00% GC) | |
julia> @benchmark isnan(2.0) | |
BenchmarkTools.Trial: | |
samples: 10000 | |
evals/sample: 1000 | |
time tolerance: 5.00% | |
memory tolerance: 1.00% | |
memory estimate: 0.00 bytes | |
allocs estimate: 0 | |
minimum time: 1.578 ns (0.00% GC) | |
median time: 1.973 ns (0.00% GC) | |
mean time: 1.841 ns (0.00% GC) | |
maximum time: 97.900 ns (0.00% GC) | |
julia> @benchmark isfinite(2.0) | |
BenchmarkTools.Trial: | |
samples: 10000 | |
evals/sample: 1000 | |
time tolerance: 5.00% | |
memory tolerance: 1.00% | |
memory estimate: 0.00 bytes | |
allocs estimate: 0 | |
minimum time: 1.578 ns (0.00% GC) | |
median time: 1.579 ns (0.00% GC) | |
mean time: 1.756 ns (0.00% GC) | |
maximum time: 54.082 ns (0.00% GC) | |
julia> @benchmark _isfinite(2.0) | |
BenchmarkTools.Trial: | |
samples: 10000 | |
evals/sample: 1000 | |
time tolerance: 5.00% | |
memory tolerance: 1.00% | |
memory estimate: 0.00 bytes | |
allocs estimate: 0 | |
minimum time: 1.578 ns (0.00% GC) | |
median time: 1.579 ns (0.00% GC) | |
mean time: 1.752 ns (0.00% GC) | |
maximum time: 53.687 ns (0.00% GC) | |
julia> versioninfo() | |
Julia Version 0.5.0 | |
Commit 3c9d753 (2016-09-19 18:14 UTC) | |
Platform Info: | |
System: NT (x86_64-w64-mingw32) | |
CPU: Intel(R) Core(TM) i7-4510U CPU @ 2.00GHz | |
WORD_SIZE: 64 | |
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell) | |
LAPACK: libopenblas64_ | |
LIBM: libopenlibm | |
LLVM: libLLVM-3.7.1 (ORCJIT, haswell) | |
julia> @code_llvm isnan(2.0) | |
; Function Attrs: uwtable | |
define i8 @jlsys_isnan_66420(double) #0 { | |
top: | |
%1 = fcmp uno double %0, 0.000000e+00 | |
%2 = zext i1 %1 to i8 | |
ret i8 %2 | |
} | |
julia> @code_llvm _isnan(2.0) | |
; Function Attrs: uwtable | |
define i8 @julia__isnan_72034(double) #0 { | |
top: | |
%1 = bitcast double %0 to i64 | |
%2 = and i64 %1, 9223372036854775807 | |
%3 = icmp ugt i64 %2, 9218868437227405312 | |
%4 = zext i1 %3 to i8 | |
ret i8 %4 | |
} | |
julia> @code_llvm isinf(2.0) | |
; Function Attrs: uwtable | |
define i8 @jlsys_isinf_67353(double) #0 { | |
top: | |
%1 = fcmp ord double %0, 0.000000e+00 | |
%2 = fsub double %0, %0 | |
%3 = fcmp une double %2, 0.000000e+00 | |
%4 = and i1 %1, %3 | |
%5 = zext i1 %4 to i8 | |
ret i8 %5 | |
} | |
julia> @code_llvm _isinf(2.0) | |
; Function Attrs: uwtable | |
define i8 @julia__isinf_72361(double) #0 { | |
top: | |
%1 = bitcast double %0 to i64 | |
%2 = and i64 %1, 9223372036854775807 | |
%3 = icmp eq i64 %2, 9218868437227405312 | |
%4 = zext i1 %3 to i8 | |
ret i8 %4 | |
} | |
julia> @code_llvm isfinite(2.0) | |
; Function Attrs: uwtable | |
define i8 @jlsys_isfinite_66257(double) #0 { | |
top: | |
%1 = fsub double %0, %0 | |
%2 = fcmp oeq double %1, 0.000000e+00 | |
%3 = zext i1 %2 to i8 | |
ret i8 %3 | |
} | |
julia> @code_llvm _isfinite(2.0) | |
; Function Attrs: uwtable | |
define i8 @julia__isfinite_72365(double) #0 { | |
top: | |
%1 = bitcast double %0 to i64 | |
%2 = and i64 %1, 9218868437227405312 | |
%3 = icmp ne i64 %2, 9218868437227405312 | |
%4 = zext i1 %3 to i8 | |
ret i8 %4 | |
} | |
# ON MY COMPUTER | |
julia> @code_native isinf(2.0) | |
.text | |
Filename: float.jl | |
pushq %rbp | |
movq %rsp, %rbp | |
Source line: 362 | |
vucomisd %xmm0, %xmm0 | |
setnp %cl | |
vsubsd %xmm0, %xmm0, %xmm0 | |
vxorps %xmm1, %xmm1, %xmm1 | |
vucomisd %xmm1, %xmm0 | |
setp %dl | |
setne %al | |
orb %dl, %al | |
andb %cl, %al | |
popq %rbp | |
retq | |
nopw %cs:(%rax,%rax) | |
julia> @code_native _isinf(2.0) | |
.text | |
Filename: REPL[4] | |
pushq %rbp | |
movq %rsp, %rbp | |
Source line: 1 | |
vmovq %xmm0, %rax | |
movb $63, %cl | |
bzhiq %rcx, %rax, %rax | |
movabsq $9218868437227405312, %rcx # imm = 0x7FF0000000000000 | |
cmpq %rcx, %rax | |
sete %al | |
popq %rbp | |
retq | |
nopw %cs:(%rax,%rax) | |
julia> @code_native isnan(2.0) | |
.text | |
Filename: float.jl | |
pushq %rbp | |
movq %rsp, %rbp | |
Source line: 355 | |
vucomisd %xmm0, %xmm0 | |
setp %al | |
popq %rbp | |
retq | |
nopl (%rax) | |
julia> @code_native _isnan(2.0) | |
.text | |
Filename: REPL[6] | |
pushq %rbp | |
movq %rsp, %rbp | |
Source line: 1 | |
vmovq %xmm0, %rax | |
movb $63, %cl | |
bzhiq %rcx, %rax, %rax | |
movabsq $9218868437227405312, %rcx # imm = 0x7FF0000000000000 | |
cmpq %rcx, %rax | |
seta %al | |
popq %rbp | |
retq | |
nopw %cs:(%rax,%rax) | |
julia> @code_native isfinite(2.0) | |
.text | |
Filename: float.jl | |
pushq %rbp | |
movq %rsp, %rbp | |
Source line: 358 | |
vsubsd %xmm0, %xmm0, %xmm0 | |
vxorps %xmm1, %xmm1, %xmm1 | |
vcmpeqsd %xmm1, %xmm0, %xmm0 | |
vmovq %xmm0, %rax | |
andl $1, %eax | |
popq %rbp | |
retq | |
nopl (%rax,%rax) | |
julia> @code_native _isfinite(2.0) | |
.text | |
Filename: REPL[5] | |
pushq %rbp | |
movq %rsp, %rbp | |
Source line: 1 | |
vmovq %xmm0, %rax | |
movabsq $9218868437227405312, %rcx # imm = 0x7FF0000000000000 | |
andq %rcx, %rax | |
cmpq %rcx, %rax | |
setne %al | |
popq %rbp | |
retq | |
nop | |
Author
musm
commented
Oct 20, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment