Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-bfloat16.exp
blobd98f83054ef6e20b5c5d8fb884e2c7dd261e6d38
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.
19 load_lib dwarf.exp
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
33     cu {} {
34         DW_TAG_compile_unit {
35                 {DW_AT_language @DW_LANG_C}
36                 {DW_AT_name     $srcfile}
37                 {DW_AT_comp_dir /tmp}
38         } {
39             declare_labels bf16_type fp16_type \
40                 bf16_var fp16_var
42             bf16_type: DW_TAG_base_type {
43                 {DW_AT_name __bf16}
44                 {encoding @DW_ATE_float}
45                 {DW_AT_byte_size 2 DW_FORM_sdata}
46             }
48             fp16_type: DW_TAG_base_type {
49                 {DW_AT_name __fp16}
50                 {encoding @DW_ATE_float}
51                 {DW_AT_byte_size 2 DW_FORM_sdata}
52             }
54             bf16_var: DW_TAG_variable {
55                 {DW_AT_name "bf16_1"}
56                 {DW_AT_type :${bf16_type}}
57                 {DW_AT_const_value 0x4049 DW_FORM_sdata}
58             }
60             fp16_var: DW_TAG_variable {
61                 {DW_AT_name "fp16_1"}
62                 {DW_AT_type :${fp16_type}}
63                 {DW_AT_const_value 0x4248 DW_FORM_sdata}
64             }
65         }
66     }
69 if { [prepare_for_testing "failed to prepare" ${testfile} \
70           [list $srcfile $asm_file] {nodebug}] } {
71     return -1
74 if ![runto_main] {
75     return -1
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".
86 set bytes {0x48 0x42}
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" \
99     "print float16 value"
100 gdb_test "x/hf \$s" "$hex <storage>:\[ \t\]*3\\.1406" \
101     "examine float16 value"