Skip to content

Commit a75ea4e

Browse files
committed
hotfix broken convert of negative
1 parent bac51cc commit a75ea4e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/llvm_intrin/conversion.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,24 @@ if (Sys.ARCH === :x86_64) || (Sys.ARCH === :i686)
4747
end
4848
@inline function _vconvert(
4949
::Type{Vec{W,F}},
50-
v::AbstractSIMD{W,I},
50+
v::AbstractSIMD{W,UInt64},
5151
::False
52-
) where {W,F,I<:Union{Int64,UInt64}}
52+
) where {W,F}
5353
v32 = reinterpret_half(v)
5454
vl = extractlower(v32)
5555
vu = extractupper(v32)
56-
vfmadd_fast(
57-
F(4.294967296e9),
58-
_vconvert(Vec{W,F}, vl, True()),
59-
_vconvert(Vec{W,F}, vu % UInt32, True())
60-
)
56+
x = _vconvert(Vec{W,F}, vu % UInt32, True())
57+
vfmadd_fast(F(4.294967296e9), _vconvert(Vec{W,F}, vl, True()), x)
58+
end
59+
@inline function _vconvert(
60+
::Type{Vec{W,F}},
61+
v::AbstractSIMD{W,Int64},
62+
::False
63+
) where {W,F}
64+
neg = v < 0
65+
pos = ifelse(neg, -v, v)
66+
posf = _vconvert(Vec{W,F}, UInt64(pos), False())
67+
ifelse(neg, -posf, posf)
6168
end
6269
@inline function vconvert(
6370
::Type{Vec{W,F}},

0 commit comments

Comments
 (0)