11# Math Functions
22
33# TODO : vector types
4- const generic_types = [Float32,Float64]
4+ const generic_types = [Float16, Float32, Float64]
55const generic_types_float = [Float32]
66const generic_types_double = [Float64]
77
@@ -33,7 +33,7 @@ for gentype in generic_types
3333
3434@device_override Base. cos (x:: $gentype ) = @builtin_ccall (" cos" , $ gentype, ($ gentype,), x)
3535@device_override Base. cosh (x:: $gentype ) = @builtin_ccall (" cosh" , $ gentype, ($ gentype,), x)
36- @device_function cospi (x:: $gentype ) = @builtin_ccall (" cospi" , $ gentype, ($ gentype,), x)
36+ @device_override Base . cospi (x:: $gentype ) = @builtin_ccall (" cospi" , $ gentype, ($ gentype,), x)
3737
3838@device_override SpecialFunctions. erfc (x:: $gentype ) = @builtin_ccall (" erfc" , $ gentype, ($ gentype,), x)
3939@device_override SpecialFunctions. erf (x:: $gentype ) = @builtin_ccall (" erf" , $ gentype, ($ gentype,), x)
@@ -59,7 +59,10 @@ for gentype in generic_types
5959# @device_override Base.mod(x::$gentype, y::$gentype) = @builtin_ccall("fmod", $gentype, ($gentype, $gentype), x, y)
6060# fract(x::$gentype, $gentype *iptr) = @builtin_ccall("fract", $gentype, ($gentype, $gentype *), x, iptr)
6161
62- @device_override Base. hypot (x:: $gentype , y:: $gentype ) = @builtin_ccall (" hypot" , $ gentype, ($ gentype, $ gentype), x, y)
62+ # TODO : remove once https://github.com/pocl/pocl/issues/2034 is addressed
63+ if $ gentype != Float16
64+ @device_override Base. hypot (x:: $gentype , y:: $gentype ) = @builtin_ccall (" hypot" , $ gentype, ($ gentype, $ gentype), x, y)
65+ end
6366
6467@device_override SpecialFunctions. loggamma (x:: $gentype ) = @builtin_ccall (" lgamma" , $ gentype, ($ gentype,), x)
6568
@@ -81,8 +84,6 @@ for gentype in generic_types
8184@device_override Base.:(^ )(x:: $gentype , y:: $gentype ) = @builtin_ccall (" pow" , $ gentype, ($ gentype, $ gentype), x, y)
8285@device_function powr (x:: $gentype , y:: $gentype ) = @builtin_ccall (" powr" , $ gentype, ($ gentype, $ gentype), x, y)
8386
84- @device_override Base. rem (x:: $gentype , y:: $gentype ) = @builtin_ccall (" remainder" , $ gentype, ($ gentype, $ gentype), x, y)
85-
8687@device_function rint (x:: $gentype ) = @builtin_ccall (" rint" , $ gentype, ($ gentype,), x)
8788
8889@device_override Base. round (x:: $gentype ) = @builtin_ccall (" round" , $ gentype, ($ gentype,), x)
@@ -100,13 +101,13 @@ for gentype in generic_types
100101 return sinval, cosval[]
101102end
102103@device_override Base. sinh (x:: $gentype ) = @builtin_ccall (" sinh" , $ gentype, ($ gentype,), x)
103- @device_function sinpi (x:: $gentype ) = @builtin_ccall (" sinpi" , $ gentype, ($ gentype,), x)
104+ @device_override Base . sinpi (x:: $gentype ) = @builtin_ccall (" sinpi" , $ gentype, ($ gentype,), x)
104105
105106@device_override Base. sqrt (x:: $gentype ) = @builtin_ccall (" sqrt" , $ gentype, ($ gentype,), x)
106107
107108@device_override Base. tan (x:: $gentype ) = @builtin_ccall (" tan" , $ gentype, ($ gentype,), x)
108109@device_override Base. tanh (x:: $gentype ) = @builtin_ccall (" tanh" , $ gentype, ($ gentype,), x)
109- @device_function tanpi (x:: $gentype ) = @builtin_ccall (" tanpi" , $ gentype, ($ gentype,), x)
110+ @device_override Base . tanpi (x:: $gentype ) = @builtin_ccall (" tanpi" , $ gentype, ($ gentype,), x)
110111
111112@device_override SpecialFunctions. gamma (x:: $gentype ) = @builtin_ccall (" tgamma" , $ gentype, ($ gentype,), x)
112113
@@ -151,11 +152,13 @@ end
151152# frexp(x::Float64{n}, Int32{n} *exp) = @builtin_ccall("frexp", Float64{n}, (Float64{n}, Int32{n} *), x, exp)
152153# frexp(x::Float64, Int32 *exp) = @builtin_ccall("frexp", Float64, (Float64, Int32 *), x, exp)
153154
155+ @device_function ilogb (x:: Float16 ) = @builtin_ccall (" ilogb" , Int32, (Float16,), x)
154156# ilogb(x::Float32{n}) = @builtin_ccall("ilogb", Int32{n}, (Float32{n},), x)
155157@device_function ilogb (x:: Float32 ) = @builtin_ccall (" ilogb" , Int32, (Float32,), x)
156158# ilogb(x::Float64{n}) = @builtin_ccall("ilogb", Int32{n}, (Float64{n},), x)
157159@device_function ilogb (x:: Float64 ) = @builtin_ccall (" ilogb" , Int32, (Float64,), x)
158160
161+ @device_override Base. ldexp (x:: Float16 , k:: Int32 ) = @builtin_ccall (" ldexp" , Float16, (Float16, Int32), x, k)
159162# ldexp(x::Float32{n}, k::Int32{n}) = @builtin_ccall("ldexp", Float32{n}, (Float32{n}, Int32{n}), x, k)
160163# ldexp(x::Float32{n}, k::Int32) = @builtin_ccall("ldexp", Float32{n}, (Float32{n}, Int32), x, k)
161164@device_override Base. ldexp (x:: Float32 , k:: Int32 ) = @builtin_ccall (" ldexp" , Float32, (Float32, Int32), x, k)
@@ -168,11 +171,13 @@ end
168171# lgamma_r(x::Float64{n}, Int32{n} *signp) = @builtin_ccall("lgamma_r", Float64{n}, (Float64{n}, Int32{n} *), x, signp)
169172# Float64 lgamma_r(x::Float64, Int32 *signp) = @builtin_ccall("lgamma_r", Float64, (Float64, Int32 *), x, signp)
170173
174+ @device_function nan (nancode:: UInt16 ) = @builtin_ccall (" nan" , Float16, (UInt16,), nancode)
171175# nan(nancode::uintn) = @builtin_ccall("nan", Float32{n}, (uintn,), nancode)
172176@device_function nan (nancode:: UInt32 ) = @builtin_ccall (" nan" , Float32, (UInt32,), nancode)
173177# nan(nancode::UInt64{n}) = @builtin_ccall("nan", Float64{n}, (UInt64{n},), nancode)
174178@device_function nan (nancode:: UInt64 ) = @builtin_ccall (" nan" , Float64, (UInt64,), nancode)
175179
180+ @device_override Base.:(^ )(x:: Float16 , y:: Int32 ) = @builtin_ccall (" pown" , Float16, (Float16, Int32), x, y)
176181# pown(x::Float32{n}, y::Int32{n}) = @builtin_ccall("pown", Float32{n}, (Float32{n}, Int32{n}), x, y)
177182@device_override Base.:(^ )(x:: Float32 , y:: Int32 ) = @builtin_ccall (" pown" , Float32, (Float32, Int32), x, y)
178183# pown(x::Float64{n}, y::Int32{n}) = @builtin_ccall("pown", Float64{n}, (Float64{n}, Int32{n}), x, y)
@@ -183,10 +188,11 @@ end
183188# remquo(x::Float64{n}, y::Float64{n}, Int32{n} *quo) = @builtin_ccall("remquo", Float64{n}, (Float64{n}, Float64{n}, Int32{n} *), x, y, quo)
184189# remquo(x::Float64, y::Float64, Int32 *quo) = @builtin_ccall("remquo", Float64, (Float64, Float64, Int32 *), x, y, quo)
185190
191+ @device_function rootn (x:: Float16 , y:: Int32 ) = @builtin_ccall (" rootn" , Float16, (Float16, Int32), x, y)
186192# rootn(x::Float32{n}, y::Int32{n}) = @builtin_ccall("rootn", Float32{n}, (Float32{n}, Int32{n}), x, y)
187193@device_function rootn (x:: Float32 , y:: Int32 ) = @builtin_ccall (" rootn" , Float32, (Float32, Int32), x, y)
188194# rootn(x::Float64{n}, y::Int32{n}) = @builtin_ccall("rootn", Float64{n}, (Float64{n}, Int32{n}), x, y)
189- # rootn(x::Float64, y::Int32) = @builtin_ccall("rootn", Float64{n} , (Float64, Int32), x, y)
195+ @device_function rootn (x:: Float64 , y:: Int32 ) = @builtin_ccall (" rootn" , Float64, (Float64, Int32), x, y)
190196
191197
192198# TODO : half and native
0 commit comments