1 # Copyright 2021-2023 Free Software Foundation, Inc. 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. 22 if {![dwarf2_support]} { 23 return 0 24 } 25 26 standard_testfile main.c -dw.S 27 28 # Make some DWARF for the test. 29 # 0x4049 is the equivalent of 3.141 for bfloat16. 30 # 0x4248 is the equivalent of 3.1406 for IEEE half float. 31 set asm_file [standard_output_file $srcfile2] 32 Dwarf::assemble $asm_file { 33 global srcdir subdir srcfile 34 35 cu {} { 36 DW_TAG_compile_unit { 37 {DW_AT_language @DW_LANG_C} 38 {DW_AT_name $srcfile} 39 {DW_AT_comp_dir /tmp} 40 } { 41 declare_labels bf16_type fp16_type \ 42 bf16_var fp16_var 43 44 bf16_type: DW_TAG_base_type { 45 {DW_AT_name __bf16} 46 {encoding @DW_ATE_float} 47 {DW_AT_byte_size 2 DW_FORM_sdata} 48 } 49 50 fp16_type: DW_TAG_base_type { 51 {DW_AT_name __fp16} 52 {encoding @DW_ATE_float} 53 {DW_AT_byte_size 2 DW_FORM_sdata} 54 } 55 56 bf16_var: DW_TAG_variable { 57 {DW_AT_name "bf16_1"} 58 {DW_AT_type :${bf16_type}} 59 {DW_AT_const_value 0x4049 DW_FORM_sdata} 60 } 61 62 fp16_var: DW_TAG_variable { 63 {DW_AT_name "fp16_1"} 64 {DW_AT_type :${fp16_type}} 65 {DW_AT_const_value 0x4248 DW_FORM_sdata} 66 } 67 } 68 } 69 } 70 71 if { [prepare_for_testing "failed to prepare" ${testfile} \ 72 [list $srcfile $asm_file] {nodebug}] } { 73 return -1 74 } 75 76 if ![runto_main] { 77 return -1 78 } 79 80 # Make sure we can print both types correctly. 81 gdb_test "print bf16_1" " = 3.141" 82 gdb_test "print fp16_1" " = 3.1406" 83