From c217561014e43bb95b0cdf36a204a85d01bca3c6 Mon Sep 17 00:00:00 2001 From: Peter Hawkins Date: Mon, 27 Jan 2025 09:59:26 -0800 Subject: [PATCH] PR #21903: [XLA:CPU] Add __truncsfhf2 and __extendhfsf2 runtime symbols. Imported from GitHub PR https://github.com/openxla/xla/pull/21903 These appear to be used by LLVM on x86 Macs. Copybara import of the project: -- f80212d25799ab089ba8c3cec6fd63bad9114d9b by Peter Hawkins : [XLA:CPU] Add __truncsfhf2 and __extendhfsf2 runtime symbols. These appear to be used by LLVM on x86 Macs. Merging this change closes #21903 COPYBARA_INTEGRATE_REVIEW=https://github.com/openxla/xla/pull/21903 from hawkinsp:syms f80212d25799ab089ba8c3cec6fd63bad9114d9b PiperOrigin-RevId: 720209384 --- xla/service/cpu/runtime_symbol_generator.cc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/xla/service/cpu/runtime_symbol_generator.cc b/xla/service/cpu/runtime_symbol_generator.cc index f0a0742a2e299..c022e26bb7624 100644 --- a/xla/service/cpu/runtime_symbol_generator.cc +++ b/xla/service/cpu/runtime_symbol_generator.cc @@ -115,11 +115,21 @@ RuntimeSymbolGenerator::ResolveRuntimeSymbol(llvm::StringRef name) { extern "C" void __chkstk(size_t); #endif +extern "C" { // Provided by compiler-rt and MLIR. // Converts an F32 value to a BF16. -extern "C" uint16_t __truncsfbf2(float); +uint16_t __truncsfbf2(float); // Converts an F64 value to a BF16. -extern "C" uint16_t __truncdfbf2(double); +uint16_t __truncdfbf2(double); + +#ifdef __APPLE__ +// Converts an F32 value to a F16. +uint16_t __truncsfhf2(float); + +float __extendhfsf2(uint16_t a); +#endif // __APPLE__ + +} // extern "C" #define REGISTER_CPU_RUNTIME_SYMBOL(base_name) \ do { \ @@ -216,6 +226,13 @@ static bool RegisterKnownJITSymbols() { "Host"); registry->Register("__truncsfbf2", reinterpret_cast(__truncsfbf2), "Host"); + +#ifdef __APPLE__ + registry->Register("__truncsfhf2", reinterpret_cast(__truncsfhf2), + "Host"); + registry->Register("__extendhfsf2", reinterpret_cast(__extendhfsf2), + "Host"); +#endif // __APPLE__ registry->Register("__powisf2", reinterpret_cast(__powisf2), "Host"); registry->Register("__powidf2", reinterpret_cast(__powidf2), "Host");