1 # Copyright (C) 2002-2003, 2005, 2007-2012 Free Software Foundation,
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Tests for Powerpc AltiVec register setting and fetching
25 # Test the use of registers, especially AltiVec registers, for Powerpc.
26 # This file uses altivec-regs.c for input.
30 if {![istarget "powerpc*"] || [skip_altivec_tests]} then {
31 verbose "Skipping altivec register tests."
35 set testfile "altivec-regs"
36 set binfile ${objdir}/${subdir}/${testfile}
37 set srcfile ${testfile}.c
39 set compile_flags {debug nowarnings}
40 if [get_compiler_info $binfile] {
41 warning "get_compiler failed"
45 if [test_compiler_info gcc*] {
46 set compile_flags "$compile_flags additional_flags=-maltivec additional_flags=-mabi=altivec"
47 } elseif [test_compiler_info xlc*] {
48 set compile_flags "$compile_flags additional_flags=-qaltivec"
50 warning "unknown compiler"
54 if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile} executable $compile_flags] != "" } {
55 untested altivec-regs.exp
60 gdb_reinitialize_dir $srcdir/$subdir
64 # Run to `main' where we begin our tests.
67 if ![runto_main] then {
71 gdb_test "set print frame-arguments all"
73 # set all the registers integer portions to 1
74 for {set i 0} {$i < 32} {incr i 1} {
75 for {set j 0} {$j < 4} {incr j 1} {
76 gdb_test "set \$vr$i.v4_int32\[$j\] = 1" "" "set reg vr$i.v4si.f\[$j\]"
80 gdb_test "set \$vscr = 1" "" ""
81 gdb_test "set \$vrsave = 1" "" ""
83 # Now execute some target code, so that GDB's register cache is flushed.
87 send_gdb "show endian\n"
90 -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" {
92 set endianness $expect_out(2,string)
94 -re ".*$gdb_prompt $" {
95 fail "couldn't get endianness"
97 timeout { fail "(timeout) endianness" }
100 # And then read the AltiVec registers back, to see that
101 # a) the register write above worked, and
102 # b) the register read (below) also works.
104 if {$endianness == "big"} {
105 set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., 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.."
107 set vector_register ".uint128 = 0x00000001000000010000000100000001, v4_float = .0x0, 0x0, 0x0, 0x0., 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.."
110 for {set i 0} {$i < 32} {incr i 1} {
111 gdb_test "info reg vr$i" "vr$i.*$vector_register" "info reg vr$i"
114 gdb_test "info reg vrsave" "vrsave.*0x1\t1" "info reg vrsave"
115 gdb_test "info reg vscr" "vscr.*0x1\t1" "info reg vscr"
117 # Now redo the same tests, but using the print command.
118 # Note: in LE case, the char array is printed WITHOUT the last character.
119 # Gdb treats the terminating null char in the array like the terminating
120 # null char in a string and doesn't print it. This is not a failure, but
123 if {$endianness == "big"} {
124 set decimal_vector ".uint128 = 0x00000001000000010000000100000001, 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.."
126 set decimal_vector ".uint128 = 0x00000001000000010000000100000001, 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.."
129 for {set i 0} {$i < 32} {incr i 1} {
130 gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i"
133 gdb_test "print \$vrsave" ".* = 1" "print vrsave"
134 gdb_test "print \$vscr" ".* = 1" "print vscr"
136 for {set i 0} {$i < 32} {incr i 1} {
137 set pattern$i ".*vr$i.*"
138 append pattern$i $vector_register
141 send_gdb "info vector\n"
142 gdb_expect_list "info vector" ".*$gdb_prompt $" {
175 "\[ \t\n\r\]+vscr\[ \t\]+0x1"
176 "\[ \t\n\r\]+vrsave\[ \t\]+0x1"
179 gdb_test "break vector_fun" \
180 "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \
181 "Set breakpoint at vector_fun"
183 # Actually it is nuch easier to see these results printed in hex.
184 gdb_test "set output-radix 16" \
185 "Output radix now set to decimal 16, hex 10, octal 20." \
186 "Set output radix to hex"
188 gdb_test "continue" \
189 "Breakpoint 2, vector_fun .a=.0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe., b=.0x1010101, 0x1010101, 0x1010101, 0x1010101.*altivec-regs.c.*vec_splat_u8.2..;" \
190 "continue to vector_fun"
192 # Do a next over the assignment to vector 'a'.
193 gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \
196 # Do a next over the assignment to vector 'b'.
197 gdb_test "next" "c = vec_add \\(a, b\\);" \
200 # Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...'
201 gdb_test "print/x a" \
202 ".*= .0x2020202, 0x2020202, 0x2020202, 0x2020202." \
203 "print vector parameter a"
205 gdb_test "print/x b" \
206 ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \
207 "print vector parameter b"
209 # If we do an 'up' now, and print 'x' and 'y' we should see the values they
210 # have in main, not the values they have in vector_fun.
211 gdb_test "up" ".1.*main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);" \
214 gdb_test "print/x x" \
215 ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \
218 gdb_test "print/x y" \
219 ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \
222 # now go back to vector_func and do a finish, to see if we can print the return
226 ".0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \
230 "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." \
231 "finish returned correct value"