Skip to content

Commit

Permalink
add test for llvm intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Oct 4, 2016
1 parent 2c78042 commit e78a328
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/llvmcall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,37 @@ function confuse_declname_parsing()
end
confuse_declname_parsing()

# Test support for llvm intrinsics.
llvm_convert(::Type{Float32}, val::Float16) =
llvmcall(("""declare float @llvm.convert.from.fp16.f32(i16)""",
"""%2 = call float @llvm.convert.from.fp16.f32(i16 %0)
ret float %2"""),
Float32, Tuple{Int16}, reinterpret(Int16, val))

llvm_convert(::Type{Float64}, val::Float16) =
llvmcall(("""declare double @llvm.convert.from.fp16.f64(i16)""",
"""%2 = call double @llvm.convert.from.fp16.f64(i16 %0)
ret double %2"""),
Float64, Tuple{Int16}, reinterpret(Int16, val))

llvm_convert(::Type{Float16}, val::Float32) =
reinterpret(Float16,
llvmcall(("""declare i16 @llvm.convert.to.fp16.f32(float)""",
"""%2 = call i16 @llvm.convert.to.fp16.f32(float %0)
ret i16 %2"""),
Int16, Tuple{Float32}, val))

llvm_convert(::Type{Float16}, val::Float64) =
reinterpret(Float16,
llvmcall(("""declare i16 @llvm.convert.to.fp16.f64(double)""",
"""%2 = call i16 @llvm.convert.to.fp16.f64(double %0)
ret i16 %2"""),
Int16, Tuple{Float64}, val))

@test llvm_convert(Float32, Float16(1.0)) === 1.0f0
@test llvm_convert(Float64, Float16(3.0)) === 3.0
@test llvm_convert(Float16, 1.0f0) === Float16(1.0)
@test llvm_convert(Float16, 3.0) === Float16(3.0)

module ObjLoadTest
using Base: Test, llvmcall, @ccallable
Expand Down

0 comments on commit e78a328

Please sign in to comment.