From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29196 invoked by alias); 10 Aug 2010 09:25:55 -0000 Received: (qmail 29054 invoked by uid 22791); 10 Aug 2010 09:25:52 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mtagate5.uk.ibm.com (HELO mtagate5.uk.ibm.com) (194.196.100.165) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Aug 2010 09:25:46 +0000 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate5.uk.ibm.com (8.13.1/8.13.1) with ESMTP id o7A9Ph54003042 for ; Tue, 10 Aug 2010 09:25:43 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o7A9OQfB1749204 for ; Tue, 10 Aug 2010 10:24:26 +0100 Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o7A9OQof025271 for ; Tue, 10 Aug 2010 10:24:26 +0100 Received: from leonard.localnet (dyn-9-152-224-27.boeblingen.de.ibm.com [9.152.224.27]) by d06av02.portsmouth.uk.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o7A9ON8j025160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 10 Aug 2010 10:24:26 +0100 From: Ken Werner Subject: [patch] GNU vector binop support Date: Tue, 10 Aug 2010 09:25:00 -0000 User-Agent: KMail/1.13.2 (Linux/2.6.32-24-generic-pae; KDE/4.4.2; i686; ; ) MIME-Version: 1.0 To: gdb-patches@sourceware.org Content-Type: Multipart/Mixed; boundary="Boundary-00=_GrRYMSsut/Uq0WT" Message-Id: <201008101124.22450.ken@linux.vnet.ibm.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-08/txt/msg00120.txt.bz2 --Boundary-00=_GrRYMSsut/Uq0WT Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-length: 513 Hi, This patch implements some binary operations for GNU vectors by traversing through the vector and calling scalar_binop (the former value_binop) element wise. The following operators have been verified: - add (+) - subtract (-) - multiply (*) - divide (/) - modulo* (%) - bitwise and* (&) - bitwise or* (|) - bitwise exclusive or* (^) - left-shift* (<<) - right-shift* (>>) *) For integer vector types only. Tested on i686-*-linux-gnu, no regressions. OK to apply? Regards Ken Werner --Boundary-00=_GrRYMSsut/Uq0WT Content-Type: text/x-patch; charset="UTF-8"; name="vec_binop.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vec_binop.patch" Content-length: 10234 ChangeLog: 2010-08-10 Ken Werner * gdb/valarith.c (vector_binop): New function. (scalar_binop): Likewise. (value_binop): Call scalar_binop or vector_binop depending on the types. * gdb/eval.c (ptrmath_type_p): Return 0 in case of TYPE_VECTOR. (evaluate_subexp_with_coercion): Add vector check to not convert vectors to pointers. * gdb/value.c (coerce_array): Add vector check to not coerce vectors. testsuite/ChangeLog: 2010-08-10 Ken Werner * gdb.base/Makefile.in (EXECUTABLES): Add gnu_vector. * gdb.base/gnu_vector.c: New File. * gdb.base/gnu_vector.exp: Likewise. Index: eval.c =================================================================== RCS file: /cvs/src/src/gdb/eval.c,v retrieving revision 1.138 diff -p -u -r1.138 eval.c --- eval.c 21 Jul 2010 14:59:05 -0000 1.138 +++ eval.c 10 Aug 2010 09:16:45 -0000 @@ -736,7 +736,7 @@ ptrmath_type_p (const struct language_de return 1; case TYPE_CODE_ARRAY: - return lang->c_style_arrays; + return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays; default: return 0; @@ -2956,6 +2956,7 @@ evaluate_subexp_with_coercion (struct ex var = exp->elts[pc + 2].symbol; type = check_typedef (SYMBOL_TYPE (var)); if (TYPE_CODE (type) == TYPE_CODE_ARRAY + && !TYPE_VECTOR (type) && CAST_IS_CONVERSION (exp->language_defn)) { (*pos) += 4; Index: valarith.c =================================================================== RCS file: /cvs/src/src/gdb/valarith.c,v retrieving revision 1.85 diff -p -u -r1.85 valarith.c --- valarith.c 7 Jun 2010 16:11:31 -0000 1.85 +++ valarith.c 10 Aug 2010 09:16:45 -0000 @@ -930,7 +930,7 @@ value_args_as_decimal (struct value *arg use value_ptradd, value_ptrsub or value_ptrdiff for those operations. */ struct value * -value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) +scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) { struct value *val; struct type *type1, *type2, *result_type; @@ -1379,6 +1379,68 @@ value_binop (struct value *arg1, struct return val; } + +/* Performs a binary operation on two vector operands by calling scalar_binop + for each pair of vector components. */ + +struct value * +vector_binop (struct value *val1, struct value *val2, enum exp_opcode op) +{ + struct value *val, *tmp, *mark; + struct type *type1, *type2, *eltype1, *eltype2, *result_type; + int t1_is_vec, t2_is_vec, elsize, n, i; + + type1 = check_typedef (value_type (val1)); + type2 = check_typedef (value_type (val2)); + + t1_is_vec = (TYPE_CODE (type1) == TYPE_CODE_ARRAY + && TYPE_VECTOR (type1)) ? 1 : 0; + t2_is_vec = (TYPE_CODE (type2) == TYPE_CODE_ARRAY + && TYPE_VECTOR (type2)) ? 1 : 0; + + if (!t1_is_vec || !t2_is_vec) + error (_("Vector operations are only supported among vectors")); + + eltype1 = check_typedef (TYPE_TARGET_TYPE (type1)); + eltype2 = check_typedef (TYPE_TARGET_TYPE (type2)); + + if (TYPE_CODE (eltype1) != TYPE_CODE (eltype2)) + error (_("The vectors have different types")); + + elsize = TYPE_LENGTH (eltype1); + n = TYPE_LENGTH (type1) / elsize; + //TODO: should we use the original value instead? + //val = allocate_value (value_type (val1)); + val = allocate_value (type1); + + mark = value_mark (); + for (i = 0; i < n; i++) + { + tmp = value_binop (value_subscript (val1, i), + value_subscript (val2, i), op); + memcpy (value_contents_writeable (val) + i * elsize, + value_contents_all (tmp), + elsize); + } + value_free_to_mark (mark); + + return val; +} + +/* Perform a binary operation on two operands. */ + +struct value * +value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) +{ + struct type *type1 = check_typedef (value_type (arg1)); + struct type *type2 = check_typedef (value_type (arg2)); + + if ((TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1)) + || (TYPE_CODE (type2) == TYPE_CODE_ARRAY && TYPE_VECTOR (type2))) + return vector_binop (arg1, arg2, op); + else + return scalar_binop (arg1, arg2, op); +} /* Simulate the C operator ! -- return 1 if ARG1 contains zero. */ Index: value.c =================================================================== RCS file: /cvs/src/src/gdb/value.c,v retrieving revision 1.108 diff -p -u -r1.108 value.c --- value.c 7 Jul 2010 16:15:18 -0000 1.108 +++ value.c 10 Aug 2010 09:16:45 -0000 @@ -2407,7 +2407,7 @@ coerce_array (struct value *arg) switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: - if (current_language->c_style_arrays) + if (!TYPE_VECTOR (type) && current_language->c_style_arrays) arg = value_coerce_array (arg); break; case TYPE_CODE_FUNC: Index: testsuite/gdb.base/Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/Makefile.in,v retrieving revision 1.6 diff -p -u -r1.6 Makefile.in --- testsuite/gdb.base/Makefile.in 23 Apr 2010 12:08:07 -0000 1.6 +++ testsuite/gdb.base/Makefile.in 10 Aug 2010 09:16:48 -0000 @@ -13,7 +13,7 @@ EXECUTABLES = all-types annota1 bitfield solib solib_sl so-impl-ld so-indr-cl \ step-line step-test structs structs2 \ twice-tmp varargs vforked-prog watchpoint whatis catch-syscall \ - pr10179 + pr10179 gnu_vector MISCELLANEOUS = coremmap.data ../foobar.baz \ shr1.sl shr2.sl solib_sl.sl solib1.sl solib2.sl Index: testsuite/gdb.base/gnu_vector.c =================================================================== RCS file: testsuite/gdb.base/gnu_vector.c diff -N testsuite/gdb.base/gnu_vector.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.base/gnu_vector.c 10 Aug 2010 09:16:48 -0000 @@ -0,0 +1,29 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 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 3 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, see . + + Contributed by Ken Werner */ + +int __attribute__ ((vector_size (4 * sizeof(int)))) i4a = {2, 4, 8, 16}; +int __attribute__ ((vector_size (4 * sizeof(int)))) i4b = {1, 2, 8, 4}; +float __attribute__ ((vector_size (4 * sizeof(float)))) f4a = {2, 4, 8, 16}; +float __attribute__ ((vector_size (4 * sizeof(float)))) f4b = {1, 2, 8, 4}; + +int +main () +{ + return 0; +} Index: testsuite/gdb.base/gnu_vector.exp =================================================================== RCS file: testsuite/gdb.base/gnu_vector.exp diff -N testsuite/gdb.base/gnu_vector.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.base/gnu_vector.exp 10 Aug 2010 09:16:48 -0000 @@ -0,0 +1,78 @@ +# Copyright 2010 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 3 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, see . */ +# +# Contributed by Ken Werner . +# +# Tests GDBs support for GNU vectors. +# http://gcc.gnu.org/onlinedocs/gcc/Vector-Extensions.html + +if $tracelevel { + strace $tracelevel +} + +set testfile "gnu_vector" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested "Couldn't compile ${srcfile}" + return -1 +} + +if [get_compiler_info ${binfile}] { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load $binfile + +if [runto main] { + # Check if our compiler is a GCC that suppports the vector extension + if { ! [test_compiler_info gcc-4-*] } { + setup_xfail "*-*-*" + fail "This compiler can not handle GNU vectors" + continue + } + + # Test binary operators on integer vector types + gdb_test "print i4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" + gdb_test "print i4b" "\\\$$decimal = \\{1, 2, 8, 4\\}" + # Arithmetic operators + gdb_test "print i4a + i4b" "\\\$$decimal = \\{3, 6, 16, 20\\}" + gdb_test "print i4a - i4b" "\\\$$decimal = \\{1, 2, 0, 12\\}" + gdb_test "print i4a * i4b" "\\\$$decimal = \\{2, 8, 64, 64\\}" + gdb_test "print i4a / i4b" "\\\$$decimal = \\{2, 2, 1, 4\\}" + gdb_test "print i4a % i4b" "\\\$$decimal = \\{0, 0, 0, 0\\}" + # Bitwise operators + gdb_test "print i4a & i4b" "\\\$$decimal = \\{0, 0, 8, 0\\}" + gdb_test "print i4a | i4b" "\\\$$decimal = \\{3, 6, 8, 20\\}" + gdb_test "print i4a ^ i4b" "\\\$$decimal = \\{3, 6, 0, 20\\}" + # Shift operators + gdb_test "print i4a << i4b" "\\\$$decimal = \\{4, 16, 2048, 256\\}" + gdb_test "print i4a >> i4b" "\\\$$decimal = \\{1, 1, 0, 1\\}" + + # Test binary operators on floating point vector types + gdb_test "print f4a" "\\\$$decimal = \\{2, 4, 8, 16\\}" + gdb_test "print f4b" "\\\$$decimal = \\{1, 2, 8, 4\\}" + # Arithmetic operators + gdb_test "print f4a + f4b" "\\\$$decimal = \\{3, 6, 16, 20\\}" + gdb_test "print f4a - f4b" "\\\$$decimal = \\{1, 2, 0, 12\\}" + gdb_test "print f4a * f4b" "\\\$$decimal = \\{2, 8, 64, 64\\}" + gdb_test "print f4a / f4b" "\\\$$decimal = \\{2, 2, 1, 4\\}" +} + +return 0 --Boundary-00=_GrRYMSsut/Uq0WT--