]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/gnu_vector.c
Add vector ABI tests to gnu_vector.exp
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / gnu_vector.c
CommitLineData
7346b668
KW
1/* This testcase is part of GDB, the GNU debugger.
2
32d0add0 3 Copyright 2010-2015 Free Software Foundation, Inc.
7346b668
KW
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 Contributed by Ken Werner <ken.werner@de.ibm.com> */
19
e6c693af
AA
20#include <stdarg.h>
21#include <stdio.h>
3bdf2bbd 22
e6c693af
AA
23#define VECTOR(n, type) \
24 type __attribute__ ((vector_size (n * sizeof(type))))
25
26typedef VECTOR (8, int) int8;
27
28typedef VECTOR (4, int) int4;
29typedef VECTOR (4, unsigned int) uint4;
30typedef VECTOR (4, char) char4;
31typedef VECTOR (4, float) float4;
32
33typedef VECTOR (2, int) int2;
34typedef VECTOR (2, long long) longlong2;
35typedef VECTOR (2, float) float2;
36typedef VECTOR (2, double) double2;
37
38typedef VECTOR (1, char) char1;
39typedef VECTOR (1, int) int1;
40typedef VECTOR (1, double) double1;
3bdf2bbd
KW
41
42int ia = 2;
43int ib = 1;
44float fa = 2;
45float fb = 1;
8954db33 46long long lla __attribute__ ((mode(DI))) = 0x0000000100000001ll;
3bdf2bbd
KW
47char4 c4 = {1, 2, 3, 4};
48int4 i4a = {2, 4, 8, 16};
49int4 i4b = {1, 2, 8, 4};
50float4 f4a = {2, 4, 8, 16};
51float4 f4b = {1, 2, 8, 4};
52uint4 ui4 = {2, 4, 8, 16};
53int2 i2 = {1, 2};
54longlong2 ll2 = {1, 2};
55float2 f2 = {1, 2};
56double2 d2 = {1, 2};
7346b668 57
2f27adfe
AB
58union
59{
60 int i;
e6c693af 61 VECTOR (sizeof(int), char) cv;
2f27adfe
AB
62} union_with_vector_1;
63
64struct
65{
66 int i;
e6c693af 67 VECTOR (sizeof(int), char) cv;
2f27adfe
AB
68 float4 f4;
69} struct_with_vector_1;
70
e6c693af
AA
71struct just_int2
72{
73 int2 i;
74};
75
76struct two_int2
77{
78 int2 i, j;
79};
80
81
82/* Simple vector-valued function with a few 16-byte vector
83 arguments. */
84
85int4
86add_some_intvecs (int4 a, int4 b, int4 c)
87{
88 return a + b + c;
89}
90
91/* Many small vector arguments, 4 bytes each. */
92
93char4
94add_many_charvecs (char4 a, char4 b, char4 c, char4 d, char4 e,
95 char4 f, char4 g, char4 h, char4 i, char4 j)
96{
97 return (a + b + c + d + e + f + g + h + i + j);
98}
99
100/* Varargs: One fixed and N-1 variable vector arguments. */
101
102float4
103add_various_floatvecs (int n, float4 a, ...)
104{
105 int i;
106 va_list argp;
107
108 va_start (argp, a);
109 for (i = 1; i < n; i++)
110 a += va_arg (argp, float4);
111 va_end (argp);
112
113 return a;
114}
115
116/* Struct-wrapped vectors (might be passed as if not wrapped). */
117
118struct just_int2
119add_structvecs (int2 a, struct just_int2 b, struct two_int2 c)
120{
121 struct just_int2 res;
122
123 res.i = a + b.i + c.i + c.j;
124 return res;
125}
126
127/* Single-element vectors (might be treated like scalars). */
128
129double1
130add_singlevecs (char1 a, int1 b, double1 c)
131{
132 return (double1) {a[0] + b[0] + c[0]};
133}
134
135
7346b668
KW
136int
137main ()
138{
e6c693af
AA
139 int4 res;
140
141 res = add_some_intvecs (i4a, i4a + i4b, i4b);
142 printf ("%d %d %d %d\n", res[0], res[1], res[2], res[3]);
143
144 res = add_some_intvecs (i4a, i4a + i4b, i4b);
145 printf ("%d %d %d %d\n", res[0], res[1], res[2], res[3]);
146
7346b668
KW
147 return 0;
148}