]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/gnu_vector.c
Update copyright year range in all GDB files
[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
e2882c85 3 Copyright 2010-2018 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 20#include <stdarg.h>
3bdf2bbd 21
e6c693af
AA
22#define VECTOR(n, type) \
23 type __attribute__ ((vector_size (n * sizeof(type))))
24
25typedef VECTOR (8, int) int8;
26
27typedef VECTOR (4, int) int4;
28typedef VECTOR (4, unsigned int) uint4;
29typedef VECTOR (4, char) char4;
30typedef VECTOR (4, float) float4;
31
32typedef VECTOR (2, int) int2;
33typedef VECTOR (2, long long) longlong2;
34typedef VECTOR (2, float) float2;
35typedef VECTOR (2, double) double2;
36
37typedef VECTOR (1, char) char1;
38typedef VECTOR (1, int) int1;
39typedef VECTOR (1, double) double1;
3bdf2bbd
KW
40
41int ia = 2;
42int ib = 1;
43float fa = 2;
44float fb = 1;
8954db33 45long long lla __attribute__ ((mode(DI))) = 0x0000000100000001ll;
3bdf2bbd
KW
46char4 c4 = {1, 2, 3, 4};
47int4 i4a = {2, 4, 8, 16};
48int4 i4b = {1, 2, 8, 4};
49float4 f4a = {2, 4, 8, 16};
50float4 f4b = {1, 2, 8, 4};
51uint4 ui4 = {2, 4, 8, 16};
52int2 i2 = {1, 2};
53longlong2 ll2 = {1, 2};
54float2 f2 = {1, 2};
55double2 d2 = {1, 2};
7346b668 56
2f27adfe
AB
57union
58{
59 int i;
e6c693af 60 VECTOR (sizeof(int), char) cv;
2f27adfe
AB
61} union_with_vector_1;
62
63struct
64{
65 int i;
e6c693af 66 VECTOR (sizeof(int), char) cv;
2f27adfe
AB
67 float4 f4;
68} struct_with_vector_1;
69
e6c693af
AA
70struct just_int2
71{
72 int2 i;
73};
74
75struct two_int2
76{
77 int2 i, j;
78};
79
80
81/* Simple vector-valued function with a few 16-byte vector
82 arguments. */
83
84int4
85add_some_intvecs (int4 a, int4 b, int4 c)
86{
87 return a + b + c;
88}
89
90/* Many small vector arguments, 4 bytes each. */
91
92char4
93add_many_charvecs (char4 a, char4 b, char4 c, char4 d, char4 e,
94 char4 f, char4 g, char4 h, char4 i, char4 j)
95{
96 return (a + b + c + d + e + f + g + h + i + j);
97}
98
99/* Varargs: One fixed and N-1 variable vector arguments. */
100
101float4
102add_various_floatvecs (int n, float4 a, ...)
103{
104 int i;
105 va_list argp;
106
107 va_start (argp, a);
108 for (i = 1; i < n; i++)
109 a += va_arg (argp, float4);
110 va_end (argp);
111
112 return a;
113}
114
115/* Struct-wrapped vectors (might be passed as if not wrapped). */
116
117struct just_int2
118add_structvecs (int2 a, struct just_int2 b, struct two_int2 c)
119{
120 struct just_int2 res;
121
122 res.i = a + b.i + c.i + c.j;
123 return res;
124}
125
126/* Single-element vectors (might be treated like scalars). */
127
128double1
129add_singlevecs (char1 a, int1 b, double1 c)
130{
131 return (double1) {a[0] + b[0] + c[0]};
132}
133
134
7346b668
KW
135int
136main ()
137{
e6c693af
AA
138 int4 res;
139
140 res = add_some_intvecs (i4a, i4a + i4b, i4b);
e6c693af
AA
141
142 res = add_some_intvecs (i4a, i4a + i4b, i4b);
77ae9c19
YQ
143
144 add_some_intvecs (i4a, i4a + i4b, i4b);
e6c693af 145
7346b668
KW
146 return 0;
147}