]>
Commit | Line | Data |
---|---|---|
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 | ||
26 | typedef VECTOR (8, int) int8; | |
27 | ||
28 | typedef VECTOR (4, int) int4; | |
29 | typedef VECTOR (4, unsigned int) uint4; | |
30 | typedef VECTOR (4, char) char4; | |
31 | typedef VECTOR (4, float) float4; | |
32 | ||
33 | typedef VECTOR (2, int) int2; | |
34 | typedef VECTOR (2, long long) longlong2; | |
35 | typedef VECTOR (2, float) float2; | |
36 | typedef VECTOR (2, double) double2; | |
37 | ||
38 | typedef VECTOR (1, char) char1; | |
39 | typedef VECTOR (1, int) int1; | |
40 | typedef VECTOR (1, double) double1; | |
3bdf2bbd KW |
41 | |
42 | int ia = 2; | |
43 | int ib = 1; | |
44 | float fa = 2; | |
45 | float fb = 1; | |
8954db33 | 46 | long long lla __attribute__ ((mode(DI))) = 0x0000000100000001ll; |
3bdf2bbd KW |
47 | char4 c4 = {1, 2, 3, 4}; |
48 | int4 i4a = {2, 4, 8, 16}; | |
49 | int4 i4b = {1, 2, 8, 4}; | |
50 | float4 f4a = {2, 4, 8, 16}; | |
51 | float4 f4b = {1, 2, 8, 4}; | |
52 | uint4 ui4 = {2, 4, 8, 16}; | |
53 | int2 i2 = {1, 2}; | |
54 | longlong2 ll2 = {1, 2}; | |
55 | float2 f2 = {1, 2}; | |
56 | double2 d2 = {1, 2}; | |
7346b668 | 57 | |
2f27adfe AB |
58 | union |
59 | { | |
60 | int i; | |
e6c693af | 61 | VECTOR (sizeof(int), char) cv; |
2f27adfe AB |
62 | } union_with_vector_1; |
63 | ||
64 | struct | |
65 | { | |
66 | int i; | |
e6c693af | 67 | VECTOR (sizeof(int), char) cv; |
2f27adfe AB |
68 | float4 f4; |
69 | } struct_with_vector_1; | |
70 | ||
e6c693af AA |
71 | struct just_int2 |
72 | { | |
73 | int2 i; | |
74 | }; | |
75 | ||
76 | struct two_int2 | |
77 | { | |
78 | int2 i, j; | |
79 | }; | |
80 | ||
81 | ||
82 | /* Simple vector-valued function with a few 16-byte vector | |
83 | arguments. */ | |
84 | ||
85 | int4 | |
86 | add_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 | ||
93 | char4 | |
94 | add_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 | ||
102 | float4 | |
103 | add_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 | ||
118 | struct just_int2 | |
119 | add_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 | ||
129 | double1 | |
130 | add_singlevecs (char1 a, int1 b, double1 c) | |
131 | { | |
132 | return (double1) {a[0] + b[0] + c[0]}; | |
133 | } | |
134 | ||
135 | ||
7346b668 KW |
136 | int |
137 | main () | |
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 | } |