Skip to content

Commit

Permalink
Support Float16
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed May 2, 2024
1 parent 8466837 commit c2433cf
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SIMD"
uuid = "fdea26ae-647d-5447-a871-4b548cad5224"
authors = ["Erik Schnetter <schnetter@gmail.com>", "Kristoffer Carlsson <kristoffer.carlsson@juliahub.com>"]
version = "3.4.7"
version = "3.5.0"

[deps]
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Expand Down
2 changes: 1 addition & 1 deletion src/LLVM_intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const d = Dict{DataType, String}(
UInt64 => "i64",
UInt128 => "i128",

#Float16 => "half",
Float16 => "half",
Float32 => "float",
Float64 => "double",
)
Expand Down
2 changes: 1 addition & 1 deletion src/SIMD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const BIntTypes = Union{IntTypes, Bool}
const UIntTypes = Union{UInt8, UInt16, UInt32, UInt64}
const IntegerTypes = Union{IntTypes, UIntTypes}
const BIntegerTypes = Union{IntegerTypes, Bool}
const FloatingTypes = Union{Float32, Float64} # Float16 support is non-native in Julia and gets passed as an i16
const FloatingTypes = Union{Float16, Float32, Float64}
const ScalarTypes = Union{IntegerTypes, FloatingTypes}
const VecTypes = Union{ScalarTypes, Ptr, Bool}
include("LLVM_intrinsics.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/simdvec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Base.abs(v::Vec{N, T}) where {N, T} = Vec(vifelse(v < zero(T), -v, v))
Base.:!(v1::Vec{N,Bool}) where {N} = ~v1
Base.inv(v::Vec{N, T}) where {N, T<:FloatingTypes} = one(T) / v

_unsigned(::Type{Float16}) = UInt16
_unsigned(::Type{Float32}) = UInt32
_unsigned(::Type{Float64}) = UInt64
function Base.issubnormal(x::Vec{N, T}) where {N, T<:FloatingTypes}
Expand Down Expand Up @@ -300,6 +301,7 @@ end
vifelse(signbit(v2), -v1, v1)
@inline Base.copysign(v1::Vec{N,T}, v2::Vec{N,T}) where {N,T<:IntTypes} =
vifelse(signbit(v2), -abs(v1), abs(v1))
_signed(::Type{Float16}) = Int16
_signed(::Type{Float32}) = Int32
_signed(::Type{Float64}) = Int64
@inline Base.signbit(x::Vec{N, T}) where {N, T <:FloatingTypes} =
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ llvm_ir(f, args) = sprint(code_llvm, f, Base.typesof(args...))

@testset "Vector shuffles" begin

for T in (Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float32,Float64)
for T in (Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float16,Float32,Float64)
a = Vec{4,T}((1,2,3,4))
b = Vec{4,T}((5,6,7,8))
@test shufflevector(a, b, Val((2,3,4,5))) === Vec{4,T}((3,4,5,6))
Expand All @@ -905,7 +905,7 @@ llvm_ir(f, args) = sprint(code_llvm, f, Base.typesof(args...))
@test shufflevector(a, b, Val((2,3,4,5))) === Vec{4,Bool}((true,false,false,false))
end

for T in (Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float32,Float64)
for T in (Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float16,Float32,Float64)
a = Vec{4,T}((1,2,3,4))
b = Vec{4,T}((5,6,7,8))
@test shufflevector(a, b, Val((2,3,4,5))) === Vec{4,T}((3,4,5,6))
Expand Down

0 comments on commit c2433cf

Please sign in to comment.