1 # Copyright (C) 2002-2022 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/>.
17 # Tests for Powerpc AltiVec register setting and fetching
20 # Test the use of registers, especially AltiVec registers, for Powerpc.
21 # This file uses altivec-regs.c for input.
25 if {![istarget "powerpc*"] || [skip_altivec_tests]} {
26 verbose "Skipping altivec register tests."
32 set compile_flags {debug nowarnings}
33 if [test_compiler_info gcc*] {
34 set compile_flags "$compile_flags additional_flags=-maltivec additional_flags=-mabi=altivec"
35 } elseif [test_compiler_info xlc*] {
36 set compile_flags "$compile_flags additional_flags=-qaltivec"
38 warning "unknown compiler"
42 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
43 untested "failed to compile"
48 gdb_reinitialize_dir $srcdir/$subdir
52 # Run to `main' where we begin our tests.
59 gdb_test "set print frame-arguments all"
61 # set all the registers integer portions to 1
62 for {set i 0} {$i < 32} {incr i 1} {
63 for {set j 0} {$j < 4} {incr j 1} {
64 gdb_test "set \$vr$i.v4_int32\[$j\] = 1" "" "set reg vr$i.v4si.f\[$j\]"
68 gdb_test "set \$vscr = 1" "" ""
69 gdb_test "set \$vrsave = 1" "" ""
71 # Now execute some target code, so that GDB's register cache is flushed.
75 set endianness [get_endianness]
77 # And then read the AltiVec registers back, to see that
78 # a) the register write above worked, and
79 # b) the register read (below) also works.
81 if {$endianness == "big"} {
82 set vector_register ".uint128 = 0x1000000010000000100000001, v4_float = .0x1, 0x1, 0x1, 0x1., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1., v16_int8 = .0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1.."
84 set vector_register ".uint128 = 0x1000000010000000100000001, v4_float = .0x1, 0x1, 0x1, 0x1., v4_int32 = .0x1, 0x1, 0x1, 0x1., v8_int16 = .0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0., v16_int8 = .0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0.."
87 for {set i 0} {$i < 32} {incr i 1} {
88 gdb_test "info reg vr$i" "vr$i.*$vector_register" "info reg vr$i"
89 gdb_test "info reg v$i" "v$i.*$vector_register" "info reg v$i"
92 gdb_test "info reg vrsave" "vrsave.*0x1\[ \t\]+1" "info reg vrsave"
93 gdb_test "info reg vscr" "vscr.*0x1\[ \t\]+1" "info reg vscr"
95 # Now redo the same tests, but using the print command.
96 # Note: in LE case, the char array is printed WITHOUT the last character.
97 # Gdb treats the terminating null char in the array like the terminating
98 # null char in a string and doesn't print it. This is not a failure, but
101 if {$endianness == "big"} {
102 set decimal_vector ".uint128 = 79228162532711081671548469249, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .0, 1, 0, 1, 0, 1, 0, 1., v16_int8 = .0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1.."
104 set decimal_vector ".uint128 = 79228162532711081671548469249, v4_float = .1.*e-45, 1.*e-45, 1.*e-45, 1.*e-45., v4_int32 = .1, 1, 1, 1., v8_int16 = .1, 0, 1, 0, 1, 0, 1, 0., v16_int8 = .1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.."
107 for {set i 0} {$i < 32} {incr i 1} {
108 gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i"
109 gdb_test "print \$v$i" ".* = $decimal_vector" "print v$i"
112 gdb_test "print \$vrsave" ".* = 1" "print vrsave"
113 gdb_test "print \$vscr" ".* = 1" "print vscr"
115 for {set i 0} {$i < 32} {incr i 1} {
116 lappend pattern_list "vr$i\[ \t\]+$vector_register"
119 lappend pattern_list "vscr\[ \t\]+0x1"
120 lappend pattern_list "vrsave\[ \t\]+0x1"
122 send_gdb "info vector\n"
123 gdb_expect_list "info vector" ".*$gdb_prompt $" $pattern_list
125 gdb_test "break vector_fun" \
126 "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \
127 "set breakpoint at vector_fun"
129 # Actually it is nuch easier to see these results printed in hex.
130 gdb_test "set output-radix 16" \
131 "Output radix now set to decimal 16, hex 10, octal 20." \
132 "set output radix to hex"
134 gdb_test "continue" \
135 "Breakpoint 2, vector_fun .a=.0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe., b=.0x1010101, 0x1010101, 0x1010101, 0x1010101.*altivec-regs.c.*vec_splat_u8.2..;" \
136 "continue to vector_fun"
138 # Do a next over the assignment to vector 'a'.
139 gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \
142 # Do a next over the assignment to vector 'b'.
143 gdb_test "next" "c = vec_add \\(a, b\\);" \
146 # Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...'
147 gdb_test "print/x a" \
148 ".*= .0x2020202, 0x2020202, 0x2020202, 0x2020202." \
149 "print vector parameter a"
151 gdb_test "print/x b" \
152 ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \
153 "print vector parameter b"
155 # If we do an 'up' now, and print 'x' and 'y' we should see the values they
156 # have in main, not the values they have in vector_fun.
157 gdb_test "up" ".1.*main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);" \
160 gdb_test "print/x x" \
161 ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \
164 gdb_test "print/x y" \
165 ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \
168 # now go back to vector_func and do a finish, to see if we can print the return
172 ".0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \
176 "Run till exit from .0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*in main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);.*Value returned is.*= .0x5050505, 0x5050505, 0x5050505, 0x5050505." \
177 "finish returned correct value"