https://sourceware.org/bugzilla/show_bug.cgi?id=31685
Bug ID: 31685 Summary: Issues when casting _Float16 to __bf16 Product: binutils Version: 2.42 Status: UNCONFIRMED Severity: normal Priority: P2 Component: gas Assignee: unassigned at sourceware dot org Reporter: mat.mcroci at gmail dot com Target Milestone: --- When compiling the following code (assuming it's in a file called test.cpp) #include <stdlib.h> #include <cstdint> #include <array> #include <iostream> #define SIZE 8 typedef _Float16 T; //typedef volatile float T; void fp16tobf16(_Float16 * f) { __bf16 * b = reinterpret_cast<__bf16*>(f); for(int i=0; i<SIZE; i++){ T temp = f[i]; b[i] = (__bf16) temp; } } with: g++ -c -S -march=sapphirerapids -O2 -std=c++23 -o test.s test.cpp using gcc 13.2.0 compiled with binutils 2.42 using spack on a Sapphire Rapids machine, the assembler does not do any casting and simply returns. You can also check this behaviour on godbolt. When using -O1 or -O0, the assembler generates the command __extendhfbf2 which I assume correctly does the casting. However, when compiling the following very similar code (assuming it's in a file called test2.cpp) #include <stdlib.h> #include <cstdint> #include <array> #include <iostream> #define SIZE 8 typedef _Float16 T; //typedef volatile float T; void fp16tobf16(_Float16 * f) { __bf16 * b = reinterpret_cast<__bf16*>(f); for(int i=0; i<SIZE; i++){ T temp = f[i]; b[i] = (__bf16) temp; } } int main(){ std::array<_Float16, SIZE> a{}; std::fill(a.begin(), a.end(), (_Float16) 1.7653432432424324); fp16tobf16(a.data()); __bf16 * b = reinterpret_cast<__bf16*>(a.data()); std::cout << "\n"; for(int i=0; i<SIZE; i++) std::cout << ((double) b[i]) << "\n"; return 0; } with: g++ -march=sapphirerapids -O0 -std=c++23 -o test2.run test2.cpp The binutils ld triggers the error: binutils-2.42-xfrnc4ulsgaca6jysot5cb7reykux4t6/bin/ld: /tmp/ccJJ5ihK.o: in function `fp16tobf16(_Float16*)': main_fp16_to_bf16.cpp:15:(.text+0x39): undefined reference to `__extendhfbf2' -- You are receiving this mail because: You are on the CC list for the bug.