xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/gnu_vector.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* This testcase is part of GDB, the GNU debugger.
2 
3    Copyright 2010-2016 Free Software Foundation, Inc.
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 
20 #include <stdarg.h>
21 
22 #define VECTOR(n, type)					\
23   type __attribute__ ((vector_size (n * sizeof(type))))
24 
25 typedef VECTOR (8, int) int8;
26 
27 typedef VECTOR (4, int) int4;
28 typedef VECTOR (4, unsigned int) uint4;
29 typedef VECTOR (4, char) char4;
30 typedef VECTOR (4, float) float4;
31 
32 typedef VECTOR (2, int) int2;
33 typedef VECTOR (2, long long) longlong2;
34 typedef VECTOR (2, float) float2;
35 typedef VECTOR (2, double) double2;
36 
37 typedef VECTOR (1, char) char1;
38 typedef VECTOR (1, int) int1;
39 typedef VECTOR (1, double) double1;
40 
41 int ia = 2;
42 int ib = 1;
43 float fa = 2;
44 float fb = 1;
45 long long lla __attribute__ ((mode(DI))) = 0x0000000100000001ll;
46 char4 c4 = {1, 2, 3, 4};
47 int4 i4a = {2, 4, 8, 16};
48 int4 i4b = {1, 2, 8, 4};
49 float4 f4a = {2, 4, 8, 16};
50 float4 f4b = {1, 2, 8, 4};
51 uint4 ui4 = {2, 4, 8, 16};
52 int2 i2 = {1, 2};
53 longlong2 ll2 = {1, 2};
54 float2 f2 = {1, 2};
55 double2 d2 = {1, 2};
56 
57 union
58 {
59   int i;
60   VECTOR (sizeof(int), char) cv;
61 } union_with_vector_1;
62 
63 struct
64 {
65   int i;
66   VECTOR (sizeof(int), char) cv;
67   float4 f4;
68 } struct_with_vector_1;
69 
70 struct just_int2
71 {
72   int2 i;
73 };
74 
75 struct two_int2
76 {
77   int2 i, j;
78 };
79 
80 
81 /* Simple vector-valued function with a few 16-byte vector
82    arguments.  */
83 
84 int4
85 add_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 
92 char4
93 add_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 
101 float4
102 add_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 
117 struct just_int2
118 add_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 
128 double1
129 add_singlevecs (char1 a, int1 b, double1 c)
130 {
131   return (double1) {a[0] + b[0] + c[0]};
132 }
133 
134 
135 int
136 main ()
137 {
138   int4 res;
139 
140   res = add_some_intvecs (i4a, i4a + i4b, i4b);
141 
142   res = add_some_intvecs (i4a, i4a + i4b, i4b);
143 
144   add_some_intvecs (i4a, i4a + i4b, i4b);
145 
146   return 0;
147 }
148