]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2021-2024 Free Software Foundation, Inc. |
1b6b755e LM |
2 | |
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. | |
7 | # | |
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. | |
12 | # | |
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/>. | |
15 | # | |
16 | # This test checks if GDB can identify bfloat16 and IEEE half float types and | |
17 | # print them correctly. | |
18 | # | |
19 | load_lib dwarf.exp | |
20 | ||
21 | # This test can only be run on targets which support DWARF-2 and use gas. | |
ce8d533e | 22 | require dwarf2_support |
1b6b755e | 23 | |
70728e1d | 24 | standard_testfile .c -dw.S |
1b6b755e LM |
25 | |
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 | |
32 | ||
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 | |
41 | ||
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 | } | |
47 | ||
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 | } | |
53 | ||
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 | } | |
59 | ||
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 | } | |
67 | } | |
68 | ||
69 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
70 | [list $srcfile $asm_file] {nodebug}] } { | |
71 | return -1 | |
72 | } | |
73 | ||
74 | if ![runto_main] { | |
75 | return -1 | |
76 | } | |
77 | ||
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" | |
70728e1d TT |
81 | |
82 | # | |
83 | # Test that 'x/hf' correctly handles "half float". | |
84 | # | |
85 | ||
86 | set bytes {0x48 0x42} | |
87 | set endian [get_endianness] | |
88 | if {$endian == "big"} { | |
89 | set bytes [lreverse $bytes] | |
90 | } | |
91 | ||
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" |