Home | History | Annotate | Line # | Download | only in gdb.arch
      1  1.1.1.2  christos # Copyright 2022-2024 Free Software Foundation, Inc.
      2      1.1  christos #
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16      1.1  christos # Check the formatting of the fcsr, fflags, and frm registers in the
     17      1.1  christos # output of the 'info registers' command.
     18      1.1  christos 
     19  1.1.1.2  christos require {istarget "riscv*-*-*"} allow_float_test
     20      1.1  christos 
     21      1.1  christos standard_testfile
     22      1.1  christos 
     23      1.1  christos if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
     24      1.1  christos     return -1
     25      1.1  christos }
     26      1.1  christos 
     27      1.1  christos if {![runto_main]} {
     28      1.1  christos    return 0
     29      1.1  christos }
     30      1.1  christos 
     31      1.1  christos # Merge FFLAGS_VALUE and FRM_VALUE into a single hexadecimal value
     32      1.1  christos # that can be written to the fcsr register.  The two arguments should
     33      1.1  christos # be the value of each of the two fields within the fcsr register.
     34      1.1  christos proc merge_fflags_and_frm { fflags_value frm_value } {
     35      1.1  christos     set fcsr_value 0x[format %x [expr $fflags_value | ($frm_value << 5)]]
     36      1.1  christos     return $fcsr_value
     37      1.1  christos }
     38      1.1  christos 
     39      1.1  christos # Use 'info registers' to check the current values of the fflags, frm,
     40      1.1  christos # and fcsr registers.  The value in fcsr should consist of the
     41      1.1  christos # FFLAGS_VALUE and FRM_VALUE, and the frm field of the fcsr register
     42      1.1  christos # should have the text FRM_STRING associated with it.
     43      1.1  christos proc check_fcsr { fflags_value frm_value frm_string } {
     44      1.1  christos     # Merge fflags and frm values into a single fcsr value.
     45      1.1  christos     set fcsr_value [merge_fflags_and_frm $fflags_value $frm_value]
     46      1.1  christos 
     47      1.1  christos     # Build up all the patterns we will need for this test.
     48      1.1  christos     set frm_str_re [string_to_regexp "$frm_string"]
     49      1.1  christos     set frm_val_re [format %d ${frm_value}]
     50      1.1  christos 
     51      1.1  christos     set nv [format %d [expr ($fflags_value >> 4) & 0x1]]
     52      1.1  christos     set dz [format %d [expr ($fflags_value >> 3) & 0x1]]
     53      1.1  christos     set of [format %d [expr ($fflags_value >> 2) & 0x1]]
     54      1.1  christos     set uf [format %d [expr ($fflags_value >> 1) & 0x1]]
     55      1.1  christos     set nx [format %d [expr ($fflags_value >> 0) & 0x1]]
     56      1.1  christos 
     57      1.1  christos     set fflags_pattern "NV:${nv} DZ:${dz} OF:${of} UF:${uf} NX:${nx}"
     58      1.1  christos     set frm_pattern "FRM:${frm_val_re} \\\[${frm_str_re}\\\]"
     59      1.1  christos     set fcsr_pattern "${fflags_pattern} ${frm_pattern}"
     60      1.1  christos 
     61      1.1  christos     # Now use 'info registers' to check the register values.
     62      1.1  christos     array set reg_counts {}
     63      1.1  christos     gdb_test_multiple "info registers \$fflags \$frm \$fcsr" "" {
     64      1.1  christos 	-re "^info registers\[^\r\n\]+\r\n" {
     65      1.1  christos 	    exp_continue
     66      1.1  christos 	}
     67      1.1  christos 
     68      1.1  christos 	-re "^(frm)\\s+${frm_value}\\s+${frm_pattern}\r\n" {
     69      1.1  christos 	    set reg_name $expect_out(1,string)
     70      1.1  christos 	    incr reg_counts($reg_name)
     71      1.1  christos 	    exp_continue
     72      1.1  christos 	}
     73      1.1  christos 
     74      1.1  christos 	-re "^(fflags)\\s+${fflags_value}\\s+${fflags_pattern}\r\n" {
     75      1.1  christos 	    set reg_name $expect_out(1,string)
     76      1.1  christos 	    incr reg_counts($reg_name)
     77      1.1  christos 	    exp_continue
     78      1.1  christos 	}
     79      1.1  christos 
     80      1.1  christos 	-re "^(fcsr)\\s+${fcsr_value}\\s+${fcsr_pattern}\r\n" {
     81      1.1  christos 	    set reg_name $expect_out(1,string)
     82      1.1  christos 	    incr reg_counts($reg_name)
     83      1.1  christos 	    exp_continue
     84      1.1  christos 	}
     85      1.1  christos 
     86      1.1  christos 	-re "^$::gdb_prompt $" {
     87      1.1  christos 	    pass $gdb_test_name
     88      1.1  christos 	}
     89      1.1  christos     }
     90      1.1  christos 
     91      1.1  christos     # Check that each register is seen only once.
     92      1.1  christos     foreach reg {fflags frm fcsr} {
     93      1.1  christos 	gdb_assert { $reg_counts($reg) == 1 } \
     94      1.1  christos 	    "check we saw $reg just once"
     95      1.1  christos     }
     96      1.1  christos }
     97      1.1  christos 
     98      1.1  christos # Set the fcsr register based on FFLAGS_VALUE and FRM_VALUE, then
     99      1.1  christos # check that the value is displayed correctly in the 'info registers'
    100      1.1  christos # output.  FRM_STRING should appear in the 'info registers' output
    101      1.1  christos # next to the frm field.
    102      1.1  christos proc test_fcsr { fflags_value frm_value frm_string } {
    103      1.1  christos     # Merge fflags and frm values into a single fcsr value.
    104      1.1  christos     set fcsr_value [merge_fflags_and_frm $fflags_value $frm_value]
    105      1.1  christos 
    106      1.1  christos     with_test_prefix "fcsr=${fcsr_value}" {
    107      1.1  christos 	# Set the fcsr value directly.
    108      1.1  christos 	gdb_test_no_output "set \$fcsr = ${fcsr_value}"
    109      1.1  christos 
    110      1.1  christos 	with_test_prefix "set through fcsr" {
    111      1.1  christos 	    check_fcsr $fflags_value $frm_value $frm_string
    112      1.1  christos 	}
    113      1.1  christos 
    114      1.1  christos 	# Reset fcsr register back to zero.
    115      1.1  christos 	gdb_test_no_output "set \$fcsr = 0x0" \
    116      1.1  christos 	    "reset fcsr back to 0x0"
    117      1.1  christos 	gdb_test "p/x \$fcsr" " = 0x0"
    118      1.1  christos 
    119      1.1  christos 	# Now set fcsr value through fflags and frm.
    120      1.1  christos 	gdb_test_no_output "set \$fflags = ${fflags_value}"
    121      1.1  christos 	gdb_test_no_output "set \$frm = ${frm_value}"
    122      1.1  christos 
    123      1.1  christos 	with_test_prefix "set through fflags and frm" {
    124      1.1  christos 	    check_fcsr $fflags_value $frm_value $frm_string
    125      1.1  christos 	}
    126      1.1  christos     }
    127      1.1  christos }
    128      1.1  christos 
    129      1.1  christos # Check each valid value of the fflags register.
    130      1.1  christos for { set i 0 } { $i < 32 } { incr i } {
    131      1.1  christos     test_fcsr 0x[format %x $i] 0x0 "RNE (round to nearest; ties to even)"
    132      1.1  christos }
    133      1.1  christos 
    134      1.1  christos # Check each valid value of the frm register.
    135      1.1  christos test_fcsr 0x0 0x1 "RTZ (Round towards zero)"
    136      1.1  christos test_fcsr 0x0 0x2 "RDN (Round down towards -INF)"
    137      1.1  christos test_fcsr 0x0 0x3 "RUP (Round up towards +INF)"
    138      1.1  christos test_fcsr 0x0 0x4 "RMM (Round to nearest; ties to max magnitude)"
    139      1.1  christos test_fcsr 0x0 0x5 "INVALID\[5\]"
    140      1.1  christos test_fcsr 0x0 0x6 "INVALID\[6\]"
    141      1.1  christos test_fcsr 0x0 0x7 "INVALID\[7\] (Dynamic rounding mode)"
    142