Skip to content

Commit 9a13542

Browse files
committed
Automated definitions
1 parent 7bdd49b commit 9a13542

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/device/intrinsics/math.jl

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,17 @@
22

33
using Base: FastMath
44
using Base.Math: throw_complex_domainerror
5+
import Core: Float16, Float32
56

67
# TODO:
78
# - wrap all intrinsics from include/metal/metal_math
89
# - add support for vector types
910
# - consider emitting LLVM intrinsics and lowering those in the back-end
1011

1112
### Constants
12-
# π
13-
const M_PI_F = Float32(reinterpret(Float64, 0x400921FB60000000))
14-
const M_PI_H = reinterpret(Float16, 0x4248)
15-
@eval begin
16-
@device_override Core.Float32(::typeof(π), ::RoundingMode) = $M_PI_F
17-
@device_override Core.Float32(::typeof(π), ::RoundingMode{:Down}) = $(prevfloat(M_PI_F))
18-
@device_override Core.Float16(::typeof(π), ::RoundingMode{:Up}) = $(nextfloat(M_PI_H))
19-
@device_override Core.Float16(::typeof(π), ::RoundingMode) = $M_PI_H
20-
end
21-
22-
#
23-
const M_E_F = Float32(reinterpret(Float64, 0x4005BF0A80000000))
24-
const M_E_H = reinterpret(Float16, 0x4170)
25-
@eval begin
26-
@device_override Core.Float32(::typeof(ℯ), ::RoundingMode{:Up}) = $(nextfloat(M_E_F))
27-
@device_override Core.Float32(::typeof(ℯ), ::RoundingMode) = $M_E_F
28-
@device_override Core.Float16(::typeof(ℯ), ::RoundingMode) = $M_E_H
29-
@device_override Core.Float16(::typeof(ℯ), ::RoundingMode{:Down}) = $(prevfloat(M_E_H))
13+
# π and ℯ
14+
for T in (:Float16,:Float32), R in (RoundUp, RoundDown), irr in (π, ℯ)
15+
@eval @device_override $T(::typeof($irr), ::typeof($R)) = $@eval($T($irr,$R))
3016
end
3117

3218
### Common Intrinsics

0 commit comments

Comments
 (0)