1 # Copyright 2021-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This test checks if GDB can identify bfloat16 and IEEE half float types and
17 # print them correctly.
21 # This test can only be run on targets which support DWARF-2 and use gas.
22 require dwarf2_support
24 standard_testfile .c -dw.S
26 # Make some DWARF for the test.
27 # 0x4049 is the equivalent of 3.141 for bfloat16.
28 # 0x4248 is the equivalent of 3.1406 for IEEE half float.
29 set asm_file [standard_output_file $srcfile2]
30 Dwarf::assemble $asm_file {
31 global srcdir subdir srcfile
35 {DW_AT_language @DW_LANG_C}
39 declare_labels bf16_type fp16_type \
42 bf16_type: DW_TAG_base_type {
44 {encoding @DW_ATE_float}
45 {DW_AT_byte_size 2 DW_FORM_sdata}
48 fp16_type: DW_TAG_base_type {
50 {encoding @DW_ATE_float}
51 {DW_AT_byte_size 2 DW_FORM_sdata}
54 bf16_var: DW_TAG_variable {
56 {DW_AT_type :${bf16_type}}
57 {DW_AT_const_value 0x4049 DW_FORM_sdata}
60 fp16_var: DW_TAG_variable {
62 {DW_AT_type :${fp16_type}}
63 {DW_AT_const_value 0x4248 DW_FORM_sdata}
69 if { [prepare_for_testing "failed to prepare" ${testfile} \
70 [list $srcfile $asm_file] {nodebug}] } {
78 # Make sure we can print both types correctly.
79 gdb_test "print bf16_1" " = 3.141"
80 gdb_test "print fp16_1" " = 3.1406"
83 # Test that 'x/hf' correctly handles "half float".
87 set endian [get_endianness]
88 if {$endian == "big"} {
89 set bytes [lreverse $bytes]
92 gdb_test_no_output "set var \$s = (unsigned char *) &storage" \
93 "set convenience variable"
94 gdb_test "print/x \$s\[0\] = [lindex $bytes 0]" \
95 " = $hex" "set first element"
96 gdb_test "print/x \$s\[1\] = [lindex $bytes 1]" \
97 " = $hex" "set second element"
98 gdb_test "print *(__fp16 *) \$s" " = 3\\.1406" \
100 gdb_test "x/hf \$s" "$hex <storage>:\[ \t\]*3\\.1406" \
101 "examine float16 value"