Skip to content

Commit 4d17c2f

Browse files
committed
change Windows calling convention
1 parent f2bad23 commit 4d17c2f

File tree

2 files changed

+50
-47
lines changed

2 files changed

+50
-47
lines changed

src/Quadmath.jl

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,44 @@ elseif is_windows()
2929
const libquadmath = "libquadmath-0.dll"
3030
end
3131

32-
# we use this slightly cumbersome definition to ensure that the value is passed
33-
# on the xmm registers, matching the x86_64 ABI for __float128.
34-
typealias Cfloat128 NTuple{2,VecElement{Float64}}
3532

36-
immutable Float128 <: AbstractFloat
37-
data::Cfloat128
38-
end
39-
Float128(x::Number) = convert(Float128, x)
33+
@static if is_unix()
34+
# we use this slightly cumbersome definition to ensure that the value is passed
35+
# on the xmm registers, matching the x86_64 ABI for __float128.
36+
typealias Cfloat128 NTuple{2,VecElement{Float64}}
4037

41-
typealias Complex256 Complex{Float128}
38+
immutable Float128 <: AbstractFloat
39+
data::Cfloat128
40+
end
41+
Float128(x::Number) = convert(Float128, x)
4242

43-
Base.cconvert(::Type{Cfloat128}, x::Float128) = x.data
43+
typealias Complex256 Complex{Float128}
4444

45+
Base.cconvert(::Type{Cfloat128}, x::Float128) = x.data
4546

46-
# reinterpret
47-
function reinterpret(::Type{UInt128}, x::Float128)
48-
hi = reinterpret(UInt64, x.data[2].value)
49-
lo = reinterpret(UInt64, x.data[1].value)
50-
UInt128(hi) << 64 | lo
51-
end
52-
function reinterpret(::Type{Float128}, x::UInt128)
53-
fhi = reinterpret(Float64, (x >> 64) % UInt64)
54-
flo = reinterpret(Float64, x % UInt64)
55-
Float128((VecElement(flo), VecElement(fhi)))
56-
end
57-
reinterpret(::Type{Unsigned}, x::Float128) = reinterpret(UInt128, x)
5847

59-
reinterpret(::Type{Int128}, x::Float128) =
60-
reinterpret(Int128, reinterpret(UInt128, x))
61-
reinterpret(::Type{Float128}, x::Int128) =
62-
reinterpret(Float128, reinterpret(UInt128, x))
48+
# reinterpret
49+
function reinterpret(::Type{UInt128}, x::Float128)
50+
hi = reinterpret(UInt64, x.data[2].value)
51+
lo = reinterpret(UInt64, x.data[1].value)
52+
UInt128(hi) << 64 | lo
53+
end
54+
function reinterpret(::Type{Float128}, x::UInt128)
55+
fhi = reinterpret(Float64, (x >> 64) % UInt64)
56+
flo = reinterpret(Float64, x % UInt64)
57+
Float128((VecElement(flo), VecElement(fhi)))
58+
end
59+
reinterpret(::Type{Unsigned}, x::Float128) = reinterpret(UInt128, x)
6360

61+
reinterpret(::Type{Int128}, x::Float128) =
62+
reinterpret(Int128, reinterpret(UInt128, x))
63+
reinterpret(::Type{Float128}, x::Int128) =
64+
reinterpret(Float128, reinterpret(UInt128, x))
65+
66+
elseif is_windows()
67+
bitstype 128 Float128
68+
typealias Cfloat128 Float128
69+
end
6470

6571
sign_mask(::Type{Float128}) = 0x8000_0000_0000_0000_0000_0000_0000_0000
6672
exponent_mask(::Type{Float128}) = 0x7fff_0000_0000_0000_0000_0000_0000_0000
@@ -78,23 +84,18 @@ convert(::Type{Float128}, x::Float64) =
7884
convert(::Type{Float64}, x::Float128) =
7985
ccall((:__trunctfdf2, quadoplib), Cdouble, (Cfloat128,), x)
8086

81-
## Cint (Int32)
82-
convert(::Type{Cint}, x::Float128) =
83-
ccall((:__fixtfsi, quadoplib), Cint, (Cfloat128,), x)
84-
convert(::Type{Float128}, x::Cint) =
85-
Float128(ccall((:__floatsitf, quadoplib), Cfloat128, (Cint,), x))
86-
87-
## Cuint (UInt32)
88-
convert(::Type{Float128}, x::Cuint) =
89-
Float128(ccall((:__floatunsitf, quadoplib), Cfloat128, (Cuint,), x))
90-
91-
## Clong (Int64 on unix)
92-
if !is_windows()
93-
convert(::Type{Clong}, x::Float128) =
94-
ccall((:__fixtfdi, quadoplib), Clong, (Cfloat128,), x)
95-
convert(::Type{Float128}, x::Clong) =
96-
Float128(ccall((:__floatditf, quadoplib), Cfloat128, (Clong,), x))
97-
end
87+
convert(::Type{Int32}, x::Float128) =
88+
ccall((:__fixtfsi, quadoplib), Int32, (Cfloat128,), x)
89+
convert(::Type{Float128}, x::Int32) =
90+
Float128(ccall((:__floatsitf, quadoplib), Cfloat128, (Int32,), x))
91+
92+
convert(::Type{Float128}, x::UInt32) =
93+
Float128(ccall((:__floatunsitf, quadoplib), Cfloat128, (UInt32,), x))
94+
95+
convert(::Type{Int64}, x::Float128) =
96+
ccall((:__fixtfdi, quadoplib), Int64, (Cfloat128,), x)
97+
convert(::Type{Float128}, x::Int64) =
98+
Float128(ccall((:__floatditf, quadoplib), Cfloat128, (Int64,), x))
9899

99100

100101
# comparison

test/runtests.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using Base.Test
22
using Quadmath
33

4-
@test Float128(1.0) + Float128(2.0) == Float128(3.0)
5-
@test Float128(1.0) + Float128(2.0) <= Float128(3.0)
6-
@test Float128(1.0) + Float128(2.0) != Float128(4.0)
7-
@test Float128(1.0) + Float128(2.0) < Float128(4.0)
8-
@test Float64(Float128(1.0) + Float128(2.0)) === 3.0
4+
for T in (Float64, Int32, Int64)
5+
@test Float128(T(1)) + Float128(T(2)) == Float128(T(3))
6+
@test Float128(T(1)) + Float128(T(2)) <= Float128(T(3))
7+
@test Float128(T(1)) + Float128(T(2)) != Float128(T(4))
8+
@test Float128(T(1)) + Float128(T(2)) < Float128(T(4))
9+
@test T(Float128(T(1)) + Float128(T(2))) === T(3)
10+
end
911

1012
@test Base.exponent_one(Float128) == reinterpret(UInt128, Float128(1.0))

0 commit comments

Comments
 (0)