Skip to content

Commit 60860d3

Browse files
authored
Use functions instead of the intrinsics (#617)
1 parent 18e1ed1 commit 60860d3

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/fastmath.jl

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
import Base.FastMath
2-
import Core.Intrinsics:
3-
sqrt_llvm,
4-
neg_float_fast,
5-
add_float_fast,
6-
sub_float_fast,
7-
mul_float_fast,
8-
div_float_fast,
9-
rem_float_fast,
10-
eq_float_fast,
11-
ne_float_fast,
12-
lt_float_fast,
13-
le_float_fast
142

153
import Base.FastMath: @fastmath,
164
FloatTypes,
@@ -40,27 +28,27 @@ import Base.FastMath: @fastmath,
4028
angle_fast,
4129
fast_op
4230

43-
sub_fast(x::Quantity{T}) where {T <: FloatTypes} = typeof(x)(neg_float_fast(x.val))
31+
sub_fast(x::Quantity{T}) where {T <: FloatTypes} = typeof(x)(sub_fast(x.val))
4432

4533
add_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
46-
Quantity{T,D,U}(add_float_fast(x.val, y.val))
34+
Quantity{T,D,U}(add_fast(x.val, y.val))
4735

4836
sub_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
49-
Quantity{T,D,U}(sub_float_fast(x.val, y.val))
37+
Quantity{T,D,U}(sub_fast(x.val, y.val))
5038

5139
function mul_fast(x::Quantity{T}, y::Quantity{T}) where {T <: FloatTypes}
5240
D = dimension(x) * dimension(y)
5341
U = typeof(unit(x) * unit(y))
54-
Quantity{T,D,U}(mul_float_fast(x.val, y.val))
42+
Quantity{T,D,U}(mul_fast(x.val, y.val))
5543
end
5644
function div_fast(x::Quantity{T}, y::Quantity{T}) where {T <: FloatTypes}
5745
D = dimension(x) / dimension(y)
5846
U = typeof(unit(x) / unit(y))
59-
Quantity{T,D,U}(div_float_fast(x.val, y.val))
47+
Quantity{T,D,U}(div_fast(x.val, y.val))
6048
end
6149

6250
rem_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
63-
Quantity{T,D,U}(rem_float_fast(x.val, y.val))
51+
Quantity{T,D,U}(rem_fast(x.val, y.val))
6452

6553
add_fast(x::Quantity{T}, y::Quantity{T}, z::Quantity{T}, t::Quantity{T}...) where {T <: FloatTypes} =
6654
add_fast(add_fast(add_fast(x, y), z), t...)
@@ -73,13 +61,13 @@ mul_fast(x::Quantity{T}, y::Quantity{T}, z::Quantity{T}, t::Quantity{T}...) wher
7361
end
7462

7563
eq_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
76-
eq_float_fast(x.val,y.val)
64+
eq_fast(x.val,y.val)
7765
ne_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
78-
ne_float_fast(x.val,y.val)
66+
ne_fast(x.val,y.val)
7967
lt_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
80-
lt_float_fast(x.val,y.val)
68+
lt_fast(x.val,y.val)
8169
le_fast(x::Quantity{T,D,U}, y::Quantity{T,D,U}) where {T <: FloatTypes,D,U} =
82-
le_float_fast(x.val,y.val)
70+
le_fast(x.val,y.val)
8371

8472
@fastmath begin
8573
abs_fast(x::Quantity{T}) where {T <: ComplexTypes} = hypot(real(x), imag(x))
@@ -163,7 +151,7 @@ pow_fast(x::Quantity, y::Integer) = x^y
163151
pow_fast(x::Quantity, y::Rational) = x^y
164152

165153
sqrt_fast(x::Quantity{T}) where {T <: FloatTypes} =
166-
Quantity(sqrt_llvm(x.val), sqrt(unit(x)))
154+
Quantity(sqrt_fast(x.val), sqrt(unit(x)))
167155

168156
for f in (:cos, :sin, :tan)
169157
f_fast = fast_op[f]

0 commit comments

Comments
 (0)