| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target vsx_hw } */ |
| 3 |
/* { dg-options "-O2 -mvsx" } */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
#include <stddef.h> |
| 7 |
#include <altivec.h> |
| 8 |
|
| 9 |
#define ELEMENTS -1, 2, 0, -32768, 32767, 53, 1, 16000 |
| 10 |
#define SPLAT 0x0123 |
| 11 |
|
| 12 |
vector short sv = (vector short) { ELEMENTS }; |
| 13 |
vector short splat = (vector short) { SPLAT, SPLAT, SPLAT, SPLAT, |
| 14 |
SPLAT, SPLAT, SPLAT, SPLAT }; |
| 15 |
vector short sv_global, sp_global; |
| 16 |
static vector short sv_static, sp_static; |
| 17 |
static short expected[] = { ELEMENTS }; |
| 18 |
static short splat_expected = SPLAT; |
| 19 |
|
| 20 |
extern void check (vector short a) |
| 21 |
__attribute__((__noinline__)); |
| 22 |
|
| 23 |
extern void check_splat (vector short a) |
| 24 |
__attribute__((__noinline__)); |
| 25 |
|
| 26 |
extern vector short pack_reg (short a, short b, short c, short d, |
| 27 |
short e, short f, short g, short h) |
| 28 |
__attribute__((__noinline__)); |
| 29 |
|
| 30 |
extern vector short pack_from_ptr (short *p_a, short *p_b, |
| 31 |
short *p_c, short *p_d, |
| 32 |
short *p_e, short *p_f, |
| 33 |
short *p_g, short *p_h) |
| 34 |
__attribute__((__noinline__)); |
| 35 |
|
| 36 |
extern vector short pack_const (void) |
| 37 |
__attribute__((__noinline__)); |
| 38 |
|
| 39 |
extern void pack_ptr (vector short *p, |
| 40 |
short a, short b, short c, short d, |
| 41 |
short e, short f, short g, short h) |
| 42 |
__attribute__((__noinline__)); |
| 43 |
|
| 44 |
extern void pack_static (short a, short b, short c, short d, |
| 45 |
short e, short f, short g, short h) |
| 46 |
__attribute__((__noinline__)); |
| 47 |
|
| 48 |
extern void pack_global (short a, short b, short c, short d, |
| 49 |
short e, short f, short g, short h) |
| 50 |
__attribute__((__noinline__)); |
| 51 |
|
| 52 |
extern vector short splat_reg (short a) |
| 53 |
__attribute__((__noinline__)); |
| 54 |
|
| 55 |
extern vector short splat_from_ptr (short *p_a) |
| 56 |
__attribute__((__noinline__)); |
| 57 |
|
| 58 |
extern vector short splat_const (void) |
| 59 |
__attribute__((__noinline__)); |
| 60 |
|
| 61 |
extern void splat_ptr (vector short *p, short a) |
| 62 |
__attribute__((__noinline__)); |
| 63 |
|
| 64 |
extern void splat_static (short a) |
| 65 |
__attribute__((__noinline__)); |
| 66 |
|
| 67 |
extern void splat_global (short a) |
| 68 |
__attribute__((__noinline__)); |
| 69 |
|
| 70 |
void |
| 71 |
check (vector short a) |
| 72 |
{ |
| 73 |
size_t i; |
| 74 |
|
| 75 |
for (i = 0; i < 8; i++) |
| 76 |
if (vec_extract (a, i) != expected[i]) |
| 77 |
abort (); |
| 78 |
} |
| 79 |
|
| 80 |
void |
| 81 |
check_splat (vector short a) |
| 82 |
{ |
| 83 |
size_t i; |
| 84 |
|
| 85 |
for (i = 0; i < 8; i++) |
| 86 |
if (vec_extract (a, i) != SPLAT) |
| 87 |
abort (); |
| 88 |
} |
| 89 |
|
| 90 |
vector short |
| 91 |
pack_reg (short a, short b, short c, short d, |
| 92 |
short e, short f, short g, short h) |
| 93 |
{ |
| 94 |
return (vector short) { a, b, c, d, e, f, g, h }; |
| 95 |
} |
| 96 |
|
| 97 |
vector short |
| 98 |
pack_from_ptr (short *p_a, short *p_b, short *p_c, short *p_d, |
| 99 |
short *p_e, short *p_f, short *p_g, short *p_h) |
| 100 |
{ |
| 101 |
return (vector short) { *p_a, *p_b, *p_c, *p_d, |
| 102 |
*p_e, *p_f, *p_g, *p_h }; |
| 103 |
} |
| 104 |
|
| 105 |
vector short |
| 106 |
pack_const (void) |
| 107 |
{ |
| 108 |
return (vector short) { ELEMENTS }; |
| 109 |
} |
| 110 |
|
| 111 |
void |
| 112 |
pack_ptr (vector short *p, |
| 113 |
short a, short b, short c, short d, |
| 114 |
short e, short f, short g, short h) |
| 115 |
{ |
| 116 |
*p = (vector short) { a, b, c, d, e, f, g, h }; |
| 117 |
} |
| 118 |
|
| 119 |
void |
| 120 |
pack_static (short a, short b, short c, short d, |
| 121 |
short e, short f, short g, short h) |
| 122 |
{ |
| 123 |
sv_static = (vector short) { a, b, c, d, e, f, g, h }; |
| 124 |
} |
| 125 |
|
| 126 |
void |
| 127 |
pack_global (short a, short b, short c, short d, |
| 128 |
short e, short f, short g, short h) |
| 129 |
{ |
| 130 |
sv_global = (vector short) { a, b, c, d, e, f, g, h }; |
| 131 |
} |
| 132 |
|
| 133 |
vector short |
| 134 |
splat_reg (short a) |
| 135 |
{ |
| 136 |
return (vector short) { a, a, a, a, a, a, a, a }; |
| 137 |
} |
| 138 |
|
| 139 |
vector short |
| 140 |
splat_from_ptr (short *p_a) |
| 141 |
{ |
| 142 |
return (vector short) { *p_a, *p_a, *p_a, *p_a, |
| 143 |
*p_a, *p_a, *p_a, *p_a }; |
| 144 |
} |
| 145 |
|
| 146 |
vector short |
| 147 |
splat_const (void) |
| 148 |
{ |
| 149 |
return (vector short) { SPLAT, SPLAT, SPLAT, SPLAT, |
| 150 |
SPLAT, SPLAT, SPLAT, SPLAT }; |
| 151 |
} |
| 152 |
|
| 153 |
void |
| 154 |
splat_ptr (vector short *p, short a) |
| 155 |
{ |
| 156 |
*p = (vector short) { a, a, a, a, a, a, a, a }; |
| 157 |
} |
| 158 |
|
| 159 |
void |
| 160 |
splat_static (short a) |
| 161 |
{ |
| 162 |
sp_static = (vector short) { a, a, a, a, a, a, a, a }; |
| 163 |
} |
| 164 |
|
| 165 |
void |
| 166 |
splat_global (short a) |
| 167 |
{ |
| 168 |
sp_global = (vector short) { a, a, a, a, a, a, a, a }; |
| 169 |
} |
| 170 |
|
| 171 |
int main (void) |
| 172 |
{ |
| 173 |
vector short sv2, sv3; |
| 174 |
|
| 175 |
check (sv); |
| 176 |
|
| 177 |
check (pack_reg (ELEMENTS)); |
| 178 |
|
| 179 |
check (pack_from_ptr (&expected[0], &expected[1], &expected[2], |
| 180 |
&expected[3], &expected[4], &expected[5], |
| 181 |
&expected[6], &expected[7])); |
| 182 |
|
| 183 |
check (pack_const ()); |
| 184 |
|
| 185 |
pack_ptr (&sv2, ELEMENTS); |
| 186 |
check (sv2); |
| 187 |
|
| 188 |
pack_static (ELEMENTS); |
| 189 |
check (sv_static); |
| 190 |
|
| 191 |
pack_global (ELEMENTS); |
| 192 |
check (sv_global); |
| 193 |
|
| 194 |
check_splat (splat); |
| 195 |
|
| 196 |
check_splat (splat_reg (SPLAT)); |
| 197 |
|
| 198 |
check_splat (splat_from_ptr (&splat_expected)); |
| 199 |
|
| 200 |
check_splat (splat_const ()); |
| 201 |
|
| 202 |
splat_ptr (&sv2, SPLAT); |
| 203 |
check_splat (sv2); |
| 204 |
|
| 205 |
splat_static (SPLAT); |
| 206 |
check_splat (sp_static); |
| 207 |
|
| 208 |
splat_global (SPLAT); |
| 209 |
check_splat (sp_global); |
| 210 |
|
| 211 |
return 0; |
| 212 |
} |