From patchwork Wed May 13 15:33:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 6699 Received: (qmail 50690 invoked by alias); 13 May 2015 15:33:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 50674 invoked by uid 89); 13 May 2015 15:33:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: e06smtp16.uk.ibm.com Received: from e06smtp16.uk.ibm.com (HELO e06smtp16.uk.ibm.com) (195.75.94.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 13 May 2015 15:33:26 +0000 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 13 May 2015 16:33:23 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 13 May 2015 16:33:21 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 6B1C517D8059 for ; Wed, 13 May 2015 16:34:09 +0100 (BST) Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t4DFXKwi8978886 for ; Wed, 13 May 2015 15:33:20 GMT Received: from d06av12.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t4DFXKqd004419 for ; Wed, 13 May 2015 09:33:20 -0600 Received: from br87z6lw.de.ibm.com (dyn-9-152-212-115.boeblingen.de.ibm.com [9.152.212.115]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t4DFXJd9004384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO); Wed, 13 May 2015 09:33:19 -0600 From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Sergio Durigan Junior Subject: [PATCH] Add vector ABI tests to gnu_vector.exp Date: Wed, 13 May 2015 17:33:17 +0200 Message-ID: <87617wa3wi.fsf@br87z6lw.de.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15051315-0025-0000-0000-0000051D8172 X-IsSubscribed: yes So far the gnu_vector test was limited to "static" aspects of GDB's vector support, like evaluating vector-valued expressions. This patch enriches the test and adds checks for GDB's vector ABI support as well. The new checks particularly verify inferior function calls with vector arguments and GDB's handling of vector return values. The test now attempts to compile for the target's "native" architecture, such that a hardware vector ABI is used if available. Since GDB has no vector ABI support for x86 and x86_64 targets, most of the new checks are XFAILed there. gdb/testsuite/ChangeLog: * gdb.base/gnu_vector.c: Include stdarg.h and stdio.h. (VECTOR): New macro. Use it... (int4, uint4, char4, float4, int2, longlong2, float2, double2): ...for these typedefs. (int8, char1, int1, double1): New typedefs. (struct just_int2, struct two_int2): New structures. (add_some_intvecs, add_many_charvecs, add_various_floatvecs, (add_structvecs, add_singlevecs): New functions. (main): Call add_some_intvecs twice. * gdb.base/gnu_vector.exp: Drop GCC version check; just attempt the compile and exit upon failure. Try compiling for the "native" architecture. Test inferior function calls with vector arguments and vector return value handling with "finish" and "return". --- gdb/testsuite/gdb.base/gnu_vector.c | 105 +++++++++++++++++++++++++++++---- gdb/testsuite/gdb.base/gnu_vector.exp | 52 ++++++++++++---- 2 files changed, 136 insertions(+), 21 deletions(-) diff --git a/gdb/testsuite/gdb.base/gnu_vector.c b/gdb/testsuite/gdb.base/gnu_vector.c index 4ad07dd..4e505d1 100644 --- a/gdb/testsuite/gdb.base/gnu_vector.c +++ b/gdb/testsuite/gdb.base/gnu_vector.c @@ -17,15 +17,27 @@ Contributed by Ken Werner */ -typedef int __attribute__ ((vector_size (4 * sizeof(int)))) int4; -typedef unsigned int __attribute__ ((vector_size (4 * sizeof(unsigned int)))) uint4; -typedef char __attribute__ ((vector_size (4 * sizeof(char)))) char4; -typedef float __attribute__ ((vector_size (4 * sizeof(float)))) float4; +#include +#include -typedef int __attribute__ ((vector_size (2 * sizeof(int)))) int2; -typedef long long __attribute__ ((vector_size (2 * sizeof(long long)))) longlong2; -typedef float __attribute__ ((vector_size (2 * sizeof(float)))) float2; -typedef double __attribute__ ((vector_size (2 * sizeof(double)))) double2; +#define VECTOR(n, type) \ + type __attribute__ ((vector_size (n * sizeof(type)))) + +typedef VECTOR (8, int) int8; + +typedef VECTOR (4, int) int4; +typedef VECTOR (4, unsigned int) uint4; +typedef VECTOR (4, char) char4; +typedef VECTOR (4, float) float4; + +typedef VECTOR (2, int) int2; +typedef VECTOR (2, long long) longlong2; +typedef VECTOR (2, float) float2; +typedef VECTOR (2, double) double2; + +typedef VECTOR (1, char) char1; +typedef VECTOR (1, int) int1; +typedef VECTOR (1, double) double1; int ia = 2; int ib = 1; @@ -46,18 +58,91 @@ double2 d2 = {1, 2}; union { int i; - char cv __attribute__ ((vector_size (sizeof (int)))); + VECTOR (sizeof(int), char) cv; } union_with_vector_1; struct { int i; - char cv __attribute__ ((vector_size (sizeof (int)))); + VECTOR (sizeof(int), char) cv; float4 f4; } struct_with_vector_1; +struct just_int2 +{ + int2 i; +}; + +struct two_int2 +{ + int2 i, j; +}; + + +/* Simple vector-valued function with a few 16-byte vector + arguments. */ + +int4 +add_some_intvecs (int4 a, int4 b, int4 c) +{ + return a + b + c; +} + +/* Many small vector arguments, 4 bytes each. */ + +char4 +add_many_charvecs (char4 a, char4 b, char4 c, char4 d, char4 e, + char4 f, char4 g, char4 h, char4 i, char4 j) +{ + return (a + b + c + d + e + f + g + h + i + j); +} + +/* Varargs: One fixed and N-1 variable vector arguments. */ + +float4 +add_various_floatvecs (int n, float4 a, ...) +{ + int i; + va_list argp; + + va_start (argp, a); + for (i = 1; i < n; i++) + a += va_arg (argp, float4); + va_end (argp); + + return a; +} + +/* Struct-wrapped vectors (might be passed as if not wrapped). */ + +struct just_int2 +add_structvecs (int2 a, struct just_int2 b, struct two_int2 c) +{ + struct just_int2 res; + + res.i = a + b.i + c.i + c.j; + return res; +} + +/* Single-element vectors (might be treated like scalars). */ + +double1 +add_singlevecs (char1 a, int1 b, double1 c) +{ + return (double1) {a[0] + b[0] + c[0]}; +} + + int main () { + int4 res; + + res = add_some_intvecs (i4a, i4a + i4b, i4b); + printf ("%d %d %d %d\n", res[0], res[1], res[2], res[3]); + + res = add_some_intvecs (i4a, i4a + i4b, i4b); + printf ("%d %d %d %d\n", res[0], res[1], res[2], res[3]); + return 0; } diff --git a/gdb/testsuite/gdb.base/gnu_vector.exp b/gdb/testsuite/gdb.base/gnu_vector.exp index 352fec0..9fe3a27 100644 --- a/gdb/testsuite/gdb.base/gnu_vector.exp +++ b/gdb/testsuite/gdb.base/gnu_vector.exp @@ -20,20 +20,19 @@ standard_testfile .c -if [get_compiler_info] { +# If supported by the compiler, "-mcpu=native" or "-march=native" +# should enable the highest available vector ABI. Try both, then try +# without a CPU option. If all variants fail, assume that the +# compiler can not handle GNU vectors. + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable {debug quiet additional_flags=-mcpu=native}] != "" + && [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable {debug quiet additional_flags=-march=native}] != "" + && [gdb_compile "${srcdir}/${subdir}/${srcfile}" ${binfile} executable {debug quiet}] != ""} { + untested "compiler can't handle the vector_size attribute?" return -1 } -# 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" - return 0 -} - -if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug}] } { - return -1 -} +clean_restart ${binfile} if { ![runto main] } { fail "runto main" @@ -175,3 +174,34 @@ gdb_test "ptype float4" "type = float __attribute__ \\(\\(vector_size\\(4\\)\\)\ gdb_test "ptype union_with_vector_1" "type = union {\r\n\[\t \]+int i;\r\n\[\t \]+char cv __attribute__ \\(\\(vector_size\\(4\\)\\)\\);\r\n}" gdb_test "ptype struct_with_vector_1" "type = struct {\r\n\[\t \]+int i;\r\n\[\t \]+char cv __attribute__ \\(\\(vector_size\\(4\\)\\)\\);\r\n\[\t \]+float4 f4;\r\n}" + +# Test inferior function calls with vector arguments and/or vector +# return values. +setup_xfail "i?86-*-*" "x86_64-*-*" +gdb_test "print add_some_intvecs(i4a, i4b, 3 * i4a)" "= \\{17, 34, 72, 132\\}" \ + "call add_some_intvecs" +setup_xfail "i?86-*-*" "x86_64-*-*" +gdb_test "print add_many_charvecs(c4, c4, c4, c4, c4, c4, c4, c4, c4, c4)" \ + "= \\{10, 20, 30, 40\\}" "call add_many_charvecs" +setup_xfail "i?86-*-*" "x86_64-*-*" +gdb_test "print add_various_floatvecs(2, f4a, f4b)" "= \\{3, 6, 16, 20\\}" \ + "call add_various_floatvecs" +setup_xfail "i?86-*-*" "x86_64-*-*" +gdb_test "print add_structvecs(i2, (struct just_int2)\{2*i2\}, (struct two_int2)\{3*i2, 4*i2\})" \ + "= \\{i = \\{10, 20\\}\\}" "call add_structvecs" +gdb_test "print add_singlevecs((char1) \{6\}, (int1) \{12\}, (double1) \{24\})" "= \\{42\\}" \ + "call add_singlevecs" + +# Test vector return value handling with "finish" and "return". +gdb_breakpoint "add_some_intvecs" +gdb_continue "add_some_intvecs" +setup_xfail "i?86-*-*" "x86_64-*-*" +gdb_test "finish" "Value returned is .* = \\{10, 20, 48, 72\\}" \ + "finish shows vector return value" +gdb_continue "add_some_intvecs" +gdb_test "return (int4) \{4, 2, 7, 6\}" \ + "#0 .* main .*" \ + "set vector return value" \ + "Make add_some_intvecs return now. .y or n.*" "y" +setup_xfail "i?86-*-*" "x86_64-*-*" +gdb_test "continue" "4 2 7 6\r\n.*" "verify vector return value"