From ff360153dd70491c6ec7812a486c860c54a3f55c Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Sat, 11 Jun 2022 17:26:34 -0400 Subject: [PATCH] Define aliases to FP16 crt in the OJIT --- src/jitlayers.cpp | 18 ++++++++++++++++-- src/jitlayers.h | 1 + test/intrinsics.jl | 24 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 50316c258d3a0..009b969201164 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -1107,12 +1107,26 @@ JuliaOJIT::JuliaOJIT() } JD.addToLinkOrder(GlobalJD, orc::JITDylibLookupFlags::MatchExportedSymbolsOnly); + + orc::SymbolAliasMap jl_crt = { + { mangle("__gnu_h2f_ieee"), { mangle("julia__gnu_h2f_ieee"), JITSymbolFlags::Exported } }, + { mangle("__extendhfsf2"), { mangle("julia__gnu_h2f_ieee"), JITSymbolFlags::Exported } }, + { mangle("__gnu_f2h_ieee"), { mangle("julia__gnu_f2h_ieee"), JITSymbolFlags::Exported } }, + { mangle("__truncsfhf2"), { mangle("julia__gnu_f2h_ieee"), JITSymbolFlags::Exported } }, + { mangle("__truncdfhf2"), { mangle("julia__truncdfhf2"), JITSymbolFlags::Exported } } + }; + cantFail(GlobalJD.define(orc::symbolAliases(jl_crt))); } -void JuliaOJIT::addGlobalMapping(StringRef Name, uint64_t Addr) +orc::SymbolStringPtr JuliaOJIT::mangle(StringRef Name) { std::string MangleName = getMangledName(Name); - cantFail(JD.define(orc::absoluteSymbols({{ES.intern(MangleName), JITEvaluatedSymbol::fromPointer((void*)Addr)}}))); + return ES.intern(MangleName); +} + +void JuliaOJIT::addGlobalMapping(StringRef Name, uint64_t Addr) +{ + cantFail(JD.define(orc::absoluteSymbols({{mangle(Name), JITEvaluatedSymbol::fromPointer((void*)Addr)}}))); } void JuliaOJIT::addModule(orc::ThreadSafeModule TSM) diff --git a/src/jitlayers.h b/src/jitlayers.h index ee3d0c14b3751..c4a89f882beaa 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -369,6 +369,7 @@ class JuliaOJIT { void RegisterJITEventListener(JITEventListener *L); #endif + orc::SymbolStringPtr mangle(StringRef Name); void addGlobalMapping(StringRef Name, uint64_t Addr); void addModule(orc::ThreadSafeModule M); diff --git a/test/intrinsics.jl b/test/intrinsics.jl index 48c5bed6abb36..10d3a5fedc867 100644 --- a/test/intrinsics.jl +++ b/test/intrinsics.jl @@ -169,6 +169,30 @@ end @test_intrinsic Core.Intrinsics.fptoui UInt Float16(3.3) UInt(3) end +if Sys.ARCH == :aarch64 + # On AArch64 we are following the `_Float16` ABI. Buthe these functions expect `Int16`. + # TODO: SHould we have `Chalf == Int16` and `Cfloat16 == Float16`? + extendhfsf2(x::Float16) = ccall("extern __extendhfsf2", llvmcall, Float32, (Int16,), reinterpret(Int16, x)) + gnu_h2f_ieee(x::Float16) = ccall("extern __gnu_h2f_ieee", llvmcall, Float32, (Int16,), reinterpret(Int16, x)) + truncsfhf2(x::Float32) = reinterpret(Float16, ccall("extern __truncsfhf2", llvmcall, Int16, (Float32,), x)) + gnu_f2h_ieee(x::Float32) = reinterpret(Float16, ccall("extern __gnu_f2h_ieee", llvmcall, Int16, (Float32,), x)) + truncdfhf2(x::Float64) = reinterpret(Float16, ccall("extern __truncdfhf2", llvmcall, Int16, (Float64,), x)) +else + extendhfsf2(x::Float16) = ccall("extern __extendhfsf2", llvmcall, Float32, (Float16,), x) + gnu_h2f_ieee(x::Float16) = ccall("extern __gnu_h2f_ieee", llvmcall, Float32, (Float16,), x) + truncsfhf2(x::Float32) = ccall("extern __truncsfhf2", llvmcall, Float16, (Float32,), x) + gnu_f2h_ieee(x::Float32) = ccall("extern __gnu_f2h_ieee", llvmcall, Float16, (Float32,), x) + truncdfhf2(x::Float64) = ccall("extern __truncdfhf2", llvmcall, Float16, (Float64,), x) +end + +@testset "Float16 intrinsics (crt)" begin + @test extendhfsf2(Float16(3.3)) == 3.3007812f0 + @test gnu_h2f_ieee(Float16(3.3)) == 3.3007812f0 + @test truncsfhf2(3.3f0) == Float16(3.3) + @test gnu_f2h_ieee(3.3f0) == Float16(3.3) + @test truncdfhf2(3.3) == Float16(3.3) +end + using Base.Experimental: @force_compile @test_throws ConcurrencyViolationError("invalid atomic ordering") (@force_compile; Core.Intrinsics.atomic_fence(:u)) === nothing @test_throws ConcurrencyViolationError("invalid atomic ordering") (@force_compile; Core.Intrinsics.atomic_fence(Symbol("u", "x"))) === nothing