Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float16 under asan, attempt #2 #7691

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions test/correctness/float16_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

#include <limits>

#ifdef __linux__
#if defined(__linux__) && defined(__clang__)
// If LLVM was built with an older GCC but Halide is built with Clang,
// we may be missing this symbol needed for float16 conversion.
// Just insert a weak definition here as a workaround.
extern "C" {
__attribute__((weak)) float __extendhfsf2(uint16_t a) {
return (float)Halide::float16_t::make_from_bits(a);

#if __clang_major__ >= 15 && defined(__x86_64__)

// In Clang 15 and later, this function is passed a uint16... but in the xmm0 register on x86-64.
// So we'll declare it as a float and just grab the upper 16 bits.
__attribute__((weak)) float __extendhfsf2(float actually_a_float16) {
uint16_t data;
memcpy(&data, &actually_a_float16, sizeof(data));
return (float)Halide::float16_t::make_from_bits(data);
}

#else

// We haven't tested this variant, so emit a warning if we ever compile for it.
#pragma message "This variant of __extendhfsf2 has not been tested."
__attribute__((weak)) float __extendhfsf2(uint16_t data) {
return Halide::float16_t::make_from_bits(data);
}

#endif

} // extern "C"
#endif

Expand Down