From 57680a243bff8a2196f342acca83f00b1b7571e2 Mon Sep 17 00:00:00 2001 From: Elena Zannoni Date: Tue, 14 May 2002 22:02:52 +0000 Subject: [PATCH] 2002-05-14 Elena Zannoni * gdb.arch/altivec-abi.c: New file. * gdb.arch/altivec-abi.exp: New file. * gdb.arch/altivec-regs.c: New file. * gdb.arch/altivec-regs.exp: New file. --- gdb/testsuite/gdb.arch/altivec-abi.c | 141 +++++++++++++++ gdb/testsuite/gdb.arch/altivec-abi.exp | 113 ++++++++++++ gdb/testsuite/gdb.arch/altivec-regs.c | 41 +++++ gdb/testsuite/gdb.arch/altivec-regs.exp | 220 ++++++++++++++++++++++++ 4 files changed, 515 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/altivec-abi.c create mode 100644 gdb/testsuite/gdb.arch/altivec-abi.exp create mode 100644 gdb/testsuite/gdb.arch/altivec-regs.c create mode 100644 gdb/testsuite/gdb.arch/altivec-regs.exp diff --git a/gdb/testsuite/gdb.arch/altivec-abi.c b/gdb/testsuite/gdb.arch/altivec-abi.c new file mode 100644 index 00000000000..f68ec255642 --- /dev/null +++ b/gdb/testsuite/gdb.arch/altivec-abi.c @@ -0,0 +1,141 @@ +#include + +vector short vshort = {111, 222, 333, 444, 555, 666, 777, 888}; +vector unsigned short vushort = {100, 200, 300, 400, 500, 600, 700, 800}; +vector int vint = {-10, -20, -30, -40}; +vector unsigned int vuint = {1111, 2222, 3333, 4444}; +vector char vchar = {'a','b','c','d','e','f','g','h','i','l','m','n','o','p','q','r'}; +vector unsigned char vuchar = {'A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R'}; +vector float vfloat = {1.25, 3.75, 5.5, 1.25}; + +vector short vshort_d = {0,0,0,0,0,0,0,0}; +vector unsigned short vushort_d = {0,0,0,0,0,0,0,0}; +vector int vint_d = {0,0,0,0}; +vector unsigned int vuint_d = {0,0,0,0}; +vector char vchar_d = {'z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z'}; +vector unsigned char vuchar_d = {'Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z'}; +vector float vfloat_d = {1.0, 1.0, 1.0, 1.0}; + +struct test_vec_struct +{ + vector signed short vshort1; + vector signed short vshort2; + vector signed short vshort3; + vector signed short vshort4; +}; + +static vector signed short test4[4] = +{ + (vector signed short) {1, 2, 3, 4, 5, 6, 7, 8}, + (vector signed short) {11, 12, 13, 14, 15, 16, 17, 18}, + (vector signed short) {21, 22, 23, 24, 25, 26, 27, 28}, + (vector signed short) {31, 32, 33, 34, 35, 36, 37, 38} +}; + +void +struct_of_vector_func (struct test_vec_struct vector_struct) +{ + vector_struct.vshort1 = vec_add (vector_struct.vshort1, vector_struct.vshort2); + vector_struct.vshort3 = vec_add (vector_struct.vshort3, vector_struct.vshort4); +} + +void +array_of_vector_func (vector signed short *matrix) +{ + matrix[0] = vec_add (matrix[0], matrix[1]); + matrix[2] = vec_add (matrix[2], matrix[3]); +} + +vector int +vec_func (vector short vshort_f, /* goes in v2 */ + vector unsigned short vushort_f, /* goes in v3 */ + vector int vint_f, /* goes in v4 */ + vector unsigned int vuint_f, /* goes in v5 */ + vector char vchar_f, /* goes in v6 */ + vector unsigned char vuchar_f, /* goes in v7 */ + vector float vfloat_f, /* goes in v8 */ + vector short x_f, /* goes in v9 */ + vector int y_f, /* goes in v10 */ + vector char a_f, /* goes in v11 */ + vector float b_f, /* goes in v12 */ + vector float c_f, /* goes in v13 */ + vector int intv_on_stack_f) +{ + + vector int vint_res; + vector unsigned int vuint_res; + vector short vshort_res; + vector unsigned short vushort_res; + vector char vchar_res; + vector float vfloat_res; + vector unsigned char vuchar_res; + + vint_res = vec_add (vint_f, intv_on_stack_f); + vint_res = vec_add (vint_f, y_f); + vuint_res = vec_add (vuint_f, ((vector unsigned int) {5,6,7,8})); + vshort_res = vec_add (vshort_f, x_f); + vushort_res = vec_add (vushort_f, + ((vector unsigned short) {1,2,3,4,5,6,7,8})); + vchar_res = vec_add (vchar_f, a_f); + vfloat_res = vec_add (vfloat_f, b_f); + vfloat_res = vec_add (c_f, ((vector float) {1.1,1.1,1.1,1.1})); + vuchar_res = vec_add (vuchar_f, + ((vector unsigned char) {'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a'})); + + return vint_res; +} + +void marker(void) {}; + +int +main (void) +{ + vector int result = {-1,-1,-1,-1}; + vector short x = {1,2,3,4,5,6,7,8}; + vector int y = {12, 22, 32, 42}; + vector int intv_on_stack = {12, 34, 56, 78}; + vector char a = {'v','e','c','t','o','r',' ','o','f',' ','c','h','a','r','s','.' }; + vector float b = {5.5, 4.5, 3.75, 2.25}; + vector float c = {1.25, 3.5, 5.5, 7.75}; + + vector short x_d = {0,0,0,0,0,0,0,0}; + vector int y_d = {0,0,0,0}; + vector int intv_on_stack_d = {0,0,0,0}; + vector char a_d = {'q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q'}; + vector float b_d = {5.0, 5.0, 5.0, 5.0}; + vector float c_d = {3.0, 3.0, 3.0, 3.0}; + + int var_int = 44; + short var_short = 3; + struct test_vec_struct vect_struct; + + vect_struct.vshort1 = (vector signed short){1, 2, 3, 4, 5, 6, 7, 8}; + vect_struct.vshort2 = (vector signed short){11, 12, 13, 14, 15, 16, 17, 18}; + vect_struct.vshort3 = (vector signed short){21, 22, 23, 24, 25, 26, 27, 28}; + vect_struct.vshort4 = (vector signed short){31, 32, 33, 34, 35, 36, 37, 38}; + + marker (); +#if 0 + /* This line is useful for cutting and pasting from the gdb command line. */ +vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack) +#endif + result = vec_func (vshort, /* goes in v2 */ + vushort, /* goes in v3 */ + vint, /* goes in v4 */ + vuint, /* goes in v5 */ + vchar, /* goes in v6 */ + vuchar, /* goes in v7 */ + vfloat, /* goes in v8 */ + x, /* goes in v9 */ + y, /* goes in v10 */ + a, /* goes in v11 */ + b, /* goes in v12 */ + c, /* goes in v13 */ + intv_on_stack); + + struct_of_vector_func (vect_struct); + array_of_vector_func (test4); + + return 0; +} + diff --git a/gdb/testsuite/gdb.arch/altivec-abi.exp b/gdb/testsuite/gdb.arch/altivec-abi.exp new file mode 100644 index 00000000000..8a9f29dd813 --- /dev/null +++ b/gdb/testsuite/gdb.arch/altivec-abi.exp @@ -0,0 +1,113 @@ +# Copyright (C) 2002 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Please email any bugs, comments, and/or additions to this file to: +# bug-gdb@prep.ai.mit.edu +# + +# Tests for Powerpc AltiVec ABI + + +if $tracelevel then { + strace $tracelevel +} + +# +# This file uses altivec.c for input. +# + +set prms_id 0 +set bug_id 0 + +if ![istarget "powerpc-*altivec"] then { + verbose "Skipping altivec abi tests." + return +} + +set testfile "altivec" +set binfile ${objdir}/${subdir}/${testfile} + +set src1 ${srcdir}/${subdir}/${testfile}.c + +if { [gdb_compile ${src1} ${binfile} executable {debug additional_flags=-w}] != "" } { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." +} + +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# +# Run to `main' where we begin our tests. +# + +if ![runto_main] then { + gdb_suppress_tests +} + +gdb_test "b marker" "Breakpoint 2 at.*file.*altivec.c, line \[0-9\]+." "break marker" +gdb_test "continue" "Breakpoint 2.*marker.*altivec.c.*" "continue to marker" +gdb_test "finish" "Run till exit from .0.*in marker.*at.*altivec.c.*main \\(\\) at.*altivec.c.*result = vec_func \\(vshort,.*goes in v2.*" "back to main (1)" + +# now all the arguments of vec_fun are initialized + +set pattern "vec_func .vshort_f=.111, 222, 333, 444, 555, 666, 777, 888., vushort_f=.100, 200, 300, 400, 500, 600, 700, 800., vint_f=.-10, -20, -30, -40., vuint_f=.1111, 2222, 3333, 4444., vchar_f=.abcdefghilmnopqr., vuchar_f=.ABCDEFGHILMNOPQR., vfloat_f=.1.25, 3.75, 5.5, 1.25., x_f=.1, 2, 3, 4, 5, 6, 7, 8., y_f=.12, 22, 32, 42., a_f=.vector of chars.., b_f=.5.5, 4.5, 3.75, 2.25., c_f=.1.25, 3.5, 5.5, 7.75., intv_on_stack_f=.12, 34, 56, 78.." + +set pattern1 $pattern +append pattern1 " at.*altivec.c.*vint_res = vec_add.*vint_f, intv_on_stack_f.;" + +# Now let's call the function. This function has > 12 args, +# the last one will go on the stack. +gdb_test "p vec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack)" \ +".\[0-9\]+ = .2, 2, 2, 2." "call inferior function with vectors (1) " + +# Let's call the function again with dummy arguments. This is to clean +# up the contents of the vector registers before the next call. +gdb_test "p vec_func(vshort_d,vushort_d,vint_d,vuint_d,vchar_d,vuchar_d,vfloat_d,x_d,y_d,a_d,b_d,c_d,intv_on_stack_d)" \ +".\[0-9\]+ = .0, 0, 0, 0." "call inferior function with vectors (2) " + +# Let's step into the function, to see if the args are printed correctly. +gdb_test "step" \ + $pattern1 \ + "step into vec_fun" + +set pattern2 $pattern +append pattern2 " at.*altivec.c.*in main.*result = vec_func .vshort,.*goes in v2.*Value returned is.*= .2, 2, 2, 2." + +# Let's see if the result is returned correctly. +gdb_test "finish" \ + "Run till exit from .0.*$pattern2" \ + "vector value returned correctly" + +# can we print the args correctly for this function? +gdb_test "break struct_of_vector_func" "" "" + +set pattern "struct_of_vector_func .vector_struct=.vshort1 = .1, 2, 3, 4, 5, 6, 7, 8., vshort2 = .11, 12, 13, 14, 15, 16, 17, 18., vshort3 = .21, 22, 23, 24, 25, 26, 27, 28., vshort4 = .31, 32, 33, 34, 35, 36, 37, 38... at.*altivec.c.*" + +gdb_test "continue" \ + "Breakpoint 3, $pattern.*vector_struct.vshort1 = vec_add .vector_struct.vshort1, vector_struct.vshort2.;" \ + "continue to struct_of_vector_func" + +gdb_test "finish" \ + "Run till exit from .0 $pattern\[ \r\n\]+main.*altivec.c.*array_of_vector_func.*" \ + "back to main (2)" + +gdb_test "step" "" "step into array_of_vector_func" +gdb_test "p matrix\[0\]" ".*= .1, 2, 3, 4, 5, 6, 7, 8." "print first vector" +gdb_test "p matrix\[1\]" ".*= .11, 12, 13, 14, 15, 16, 17, 18." "print second vector" +gdb_test "p matrix\[2\]" ".*= .21, 22, 23, 24, 25, 26, 27, 28." "print third vector" +gdb_test "p matrix\[3\]" ".*= .31, 32, 33, 34, 35, 36, 37, 38." "print fourth vector" + diff --git a/gdb/testsuite/gdb.arch/altivec-regs.c b/gdb/testsuite/gdb.arch/altivec-regs.c new file mode 100644 index 00000000000..4d4fe3f5dbb --- /dev/null +++ b/gdb/testsuite/gdb.arch/altivec-regs.c @@ -0,0 +1,41 @@ +#include +#include + +vector unsigned int +vector_fun (vector unsigned int a, vector unsigned int b) +{ + vector unsigned int c; + a = ((vector unsigned int) vec_splat_u8(2)); + b = ((vector unsigned int) vec_splat_u8(3)); + + c = vec_add (a, b); + return c; +} + +int +main () +{ + vector unsigned int y; + vector unsigned int x; + vector unsigned int z; + int a; + + /* This line may look unnecessary but we do need it, because we want to + have a line to do a next over (so that gdb refetches the registers) + and we don't want the code to change any vector registers. + The splat operations below modify the VRs,i + so we don't want to execute them yet. */ + a = 9; + x = ((vector unsigned int) vec_splat_u8 (-2)); + y = ((vector unsigned int) vec_splat_u8 (1)); + + z = vector_fun (x, y); + x = vec_sld (x,y,2); + + x = vec_add (x, ((vector unsigned int){5,6,7,8})); + z = (vector unsigned int) vec_splat_u8 ( -2); + y = vec_add (x, z); + z = (vector unsigned int) vec_cmpeq (x,y); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/altivec-regs.exp b/gdb/testsuite/gdb.arch/altivec-regs.exp new file mode 100644 index 00000000000..80433bff155 --- /dev/null +++ b/gdb/testsuite/gdb.arch/altivec-regs.exp @@ -0,0 +1,220 @@ +# Copyright (C) 2002 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Please email any bugs, comments, and/or additions to this file to: +# bug-gdb@prep.ai.mit.edu +# + +# Tests for Powerpc AltiVec register setting and fetching + +if $tracelevel then { + strace $tracelevel +} + +# +# Test the use of registers, especially AltiVec registers, for Powerpc. +# This file uses altivec-regs.c for input. +# + +set prms_id 0 +set bug_id 0 + +if ![istarget "powerpc-*altivec"] then { + verbose "Skipping altivec register tests." + return +} + +set testfile "altivec-regs" +set binfile ${objdir}/${subdir}/${testfile} +set src1 ${srcdir}/${subdir}/${testfile}.c + +if { [gdb_compile ${src1} ${binfile} executable {debug additional_flags=-w}] != "" } { + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." +} + +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +# +# Run to `main' where we begin our tests. +# + +if ![runto_main] then { + gdb_suppress_tests +} + +# set all the registers integer portions to 1 +for {set i 0} {$i < 32} {incr i 1} { + for {set j 0} {$j < 4} {incr j 1} { + gdb_test "set \$vr$i.v4_int32\[$j\] = 1" "" "set reg vr$i.v4si.f\[$j\]" + } +} + +gdb_test "set \$vscr = 1" "" "" +gdb_test "set \$vrsave = 1" "" "" + +# Now execute some target code, so that GDB's register cache is flushed. + +gdb_test "next" "" "" + +send_gdb "show endian\n" +gdb_expect { + -re "(The target endianness is set automatically .currently )(big|little)( endian.*)$gdb_prompt $" { + pass "endianness" + set endianness $expect_out(2,string) + } + -re ".*$gdb_prompt $" { + fail "couldn't get endianness" + } + timeout { fail "(timeout) endianness" } +} + +# And then read the AltiVec registers back, to see that +# a) the register write above worked, and +# b) the register read (below) also works. + +if {$endianness == "big"} { +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.." +} else { +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.." +} + +for {set i 0} {$i < 32} {incr i 1} { + gdb_test "info reg vr$i" "vr$i.*$vector_register" "info reg vr$i" +} + +gdb_test "info reg vrsave" "vrsave.*0x1" "info reg vrsave" +gdb_test "info reg vscr" "vscr.*0x1" "info reg vscr" + +# Now redo the same tests, but using the print command. +# Note: in LE case, the char array is printed WITHOUT the last character. +# Gdb treats the terminating null char in the array like the terminating +# null char in a string and doesn't print it. This is not a failure, but +# the way gdb works. + +if {$endianness == "big"} { + 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.001.0.0.0.001.0.0.0.001.0.0.0.001.." +} else { + 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 = ..001.0.0.0.001.0.0.0.001.0.0.0.001.0.0.." +} + +for {set i 0} {$i < 32} {incr i 1} { + gdb_test "print \$vr$i" ".* = $decimal_vector" "print vr$i" +} + +gdb_test "print \$vrsave" ".* = 1" "print vrsave" +gdb_test "print \$vscr" ".* = 1" "print vscr" + +for {set i 0} {$i < 32} {incr i 1} { + set pattern$i ".*vr$i.*" + append pattern$i $vector_register +} + +send_gdb "info powerpc altivec\n" +gdb_expect_list "info powerpc altivec" ".*$gdb_prompt $" { +[$pattern0] +[$pattern1] +[$pattern2] +[$pattern3] +[$pattern4] +[$pattern5] +[$pattern6] +[$pattern7] +[$pattern8] +[$pattern9] +[$pattern10] +[$pattern11] +[$pattern12] +[$pattern13] +[$pattern14] +[$pattern15] +[$pattern16] +[$pattern17] +[$pattern18] +[$pattern19] +[$pattern20] +[$pattern21] +[$pattern22] +[$pattern23] +[$pattern24] +[$pattern25] +[$pattern26] +[$pattern27] +[$pattern28] +[$pattern29] +[$pattern30] +[$pattern31] +"\[ \t\n\r\]+vscr\[ \t\]+0x1" +"\[ \t\n\r\]+vrsave\[ \t\]+0x1" +} + +gdb_test "break vector_fun" \ + "Breakpoint 2 at.*altivec-regs.c, line \[0-9\]+\\." \ + "Set breakpoint at vector_fun" + +# Actually it is nuch easier to see these results printed in hex. +gdb_test "set output-radix 16" \ + "Output radix now set to decimal 16, hex 10, octal 20." \ + "Set output radix to hex" + +gdb_test "continue" \ + "Breakpoint 2, vector_fun .a=.0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe., b=.0x1010101, 0x1010101, 0x1010101, 0x1010101.*altivec-regs.c.*vec_splat_u8.2..;" \ + "continue to vector_fun" + +# Do a next over the assignment to vector 'a'. +gdb_test "next" ".*b = \\(\\(vector unsigned int\\) vec_splat_u8\\(3\\)\\);" \ + "next (1)" + +# Do a next over the assignment to vector 'b'. +gdb_test "next" "c = vec_add \\(a, b\\);" \ + "next (2)" + +# Now 'a' should be '0x02020202...' and 'b' should be '0x03030303...' +gdb_test "print/x a" \ + ".*= .0x2020202, 0x2020202, 0x2020202, 0x2020202." \ + "print vector parameter a" + +gdb_test "print/x b" \ + ".*= .0x3030303, 0x3030303, 0x3030303, 0x3030303." \ + "print vector parameter b" + +# If we do an 'up' now, and print 'x' and 'y' we should see the values they +# have in main, not the values they have in vector_fun. +gdb_test "up" ".1.*main \\(\\) at.*altivec-regs.c.*z = vector_fun \\(x, y\\);" \ + "up to main" + +gdb_test "print/x x" \ + ".*= .0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe." \ + "print vector x" + +gdb_test "print/x y" \ + ".*= .0x1010101, 0x1010101, 0x1010101, 0x1010101." \ + "print vector y" + +# now go back to vector_func and do a finish, to see if we can print the return +# value correctly. + +gdb_test "down" \ + ".0 vector_fun \\(a=.0x2020202, 0x2020202, 0x2020202, 0x2020202., b=.0x3030303, 0x3030303, 0x3030303, 0x3030303.\\) at.*altivec-regs.c.*c = vec_add \\(a, b\\);" \ + "down to vector_fun" + +gdb_test "finish" \ + "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." \ + "finish returned correct value" + + + -- 2.30.2