[RFA/TESTSUITE] New altivec.exp test

Elena Zannoni ezannoni@redhat.com
Fri May 3 12:43:00 GMT 2002


Here is the first of the AltiVec tests.  While we decide on where to
put it, I'd like to take care of any issues with this test.  I believe
that there is general consensus that a gdb.arch directory would serve
the purpose. If this is so, I'll create the directory when/if this test
gets the green light.

This test generates 14 new passes in a toolchain configured with
--target=powerpc-linux-gnualtivec (linux native on a G4 machine)
or --target=powerpc-eabialtivec (cross with the simulator).

Elena

2002-05-03  Elena Zannoni  <ezannoni@redhat.com>

	* gdb.arch/altivec.c: New file.
	* gdb.arch/altivec.exp: New file.

altivec.c
----------

#include <altivec.h>

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;
}



altivec.exp
-----------

# 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"



More information about the Gdb-patches mailing list