| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target vmx_hw } */ |
| 3 |
/* { dg-options "-maltivec" } */ |
| 4 |
|
| 5 |
/* This test should run the same on any target that supports altivec/vmx |
| 6 |
instructions. Unsigned Intentionally not specifying cpu in order to test |
| 7 |
all code generation paths. */ |
| 8 |
|
| 9 |
#include <altivec.h> |
| 10 |
|
| 11 |
extern void abort (void); |
| 12 |
|
| 13 |
#define CONST0 (0) |
| 14 |
#define CONST1 (1) |
| 15 |
#define CONST2 (2) |
| 16 |
#define CONST3 (3) |
| 17 |
|
| 18 |
/* Test that indices > length of vector are applied modulo the vector |
| 19 |
length. */ |
| 20 |
|
| 21 |
/* Test for vector residing in register. */ |
| 22 |
vector unsigned int s3 (vector unsigned int v, unsigned int x) |
| 23 |
{ |
| 24 |
return vec_insert (x, v, 3); |
| 25 |
} |
| 26 |
|
| 27 |
vector unsigned int s1 (vector unsigned int v, unsigned int x) |
| 28 |
{ |
| 29 |
return vec_insert (x, v, 1); |
| 30 |
} |
| 31 |
|
| 32 |
vector unsigned int s21 (vector unsigned int v, unsigned int x) |
| 33 |
{ |
| 34 |
return vec_insert (x, v, 21); |
| 35 |
} |
| 36 |
|
| 37 |
vector unsigned int s30 (vector unsigned int v, unsigned int x) |
| 38 |
{ |
| 39 |
return vec_insert (x, v, 30); |
| 40 |
} |
| 41 |
|
| 42 |
/* Test for vector residing in memory. */ |
| 43 |
vector unsigned int ms3 (vector unsigned int *vp, unsigned int x) |
| 44 |
{ |
| 45 |
return vec_insert (x, *vp, 3); |
| 46 |
} |
| 47 |
|
| 48 |
vector unsigned int ms1(vector unsigned int *vp, unsigned int x) |
| 49 |
{ |
| 50 |
return vec_insert (x, *vp, 1); |
| 51 |
} |
| 52 |
|
| 53 |
vector unsigned int ms21(vector unsigned int *vp, unsigned int x) |
| 54 |
{ |
| 55 |
return vec_insert (x, *vp, 21); |
| 56 |
} |
| 57 |
|
| 58 |
vector unsigned int ms30(vector unsigned int *vp, unsigned int x) |
| 59 |
{ |
| 60 |
return vec_insert (x, *vp, 30); |
| 61 |
} |
| 62 |
|
| 63 |
/* Test the same with variable indices. */ |
| 64 |
|
| 65 |
/* Test for variable selector and vector residing in register. */ |
| 66 |
__attribute__((noinline)) |
| 67 |
vector unsigned int ci (vector unsigned int v, int i, unsigned int x) |
| 68 |
{ |
| 69 |
return vec_insert (x, v, i); |
| 70 |
} |
| 71 |
|
| 72 |
/* Test for variable selector and vector residing in memory. */ |
| 73 |
__attribute__((noinline)) |
| 74 |
vector unsigned int mci(vector unsigned int *vp, int i, unsigned int x) |
| 75 |
{ |
| 76 |
return vec_insert (x, *vp, i); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
int main (int argc, unsigned char *argv[]) { |
| 81 |
vector unsigned int sv = { CONST0, CONST1, CONST2, CONST3 }; |
| 82 |
|
| 83 |
sv = s3 (sv, CONST2); |
| 84 |
if (sv [3] != CONST2) |
| 85 |
abort (); |
| 86 |
|
| 87 |
sv = s1 (sv, CONST2); |
| 88 |
if (sv [1] != CONST2) |
| 89 |
abort (); |
| 90 |
|
| 91 |
sv = s21 (sv, CONST3); |
| 92 |
if (sv [1] != CONST3) |
| 93 |
abort (); |
| 94 |
|
| 95 |
sv = s30 (sv, CONST1); |
| 96 |
if (sv [2] != CONST1) |
| 97 |
abort (); |
| 98 |
|
| 99 |
sv = ms3 (&sv, CONST0); |
| 100 |
if (sv [3] != CONST0) |
| 101 |
abort (); |
| 102 |
|
| 103 |
sv = ms1 (&sv, CONST0); |
| 104 |
if (sv [1] != CONST0) |
| 105 |
abort (); |
| 106 |
|
| 107 |
sv = ms21 (&sv, CONST1); |
| 108 |
if (sv [1] != CONST1) |
| 109 |
abort (); |
| 110 |
|
| 111 |
sv = ms30 (&sv, CONST0); |
| 112 |
if (sv [2] != CONST0) |
| 113 |
abort (); |
| 114 |
|
| 115 |
sv = ci (sv, 5, CONST3); |
| 116 |
if (sv [1] != CONST3) |
| 117 |
abort (); |
| 118 |
|
| 119 |
sv = ci (sv, 2, CONST0); |
| 120 |
if (sv [2] != CONST0) |
| 121 |
abort (); |
| 122 |
|
| 123 |
sv = ci (sv, 15, CONST1); |
| 124 |
if (sv [3] != CONST1) |
| 125 |
abort (); |
| 126 |
|
| 127 |
sv = ci (sv, 28, CONST3); |
| 128 |
if (sv [0] != CONST3) |
| 129 |
abort (); |
| 130 |
|
| 131 |
sv = mci (&sv, 5, CONST0); |
| 132 |
if (sv [1] != CONST0) |
| 133 |
abort (); |
| 134 |
|
| 135 |
sv = mci (&sv, 12, CONST2); |
| 136 |
if (sv [0] != CONST2) |
| 137 |
abort (); |
| 138 |
|
| 139 |
sv = mci (&sv, 25, CONST3); |
| 140 |
if (sv [1] != CONST3) |
| 141 |
abort (); |
| 142 |
|
| 143 |
sv = mci (&sv, 16, CONST1); |
| 144 |
if (sv [0] != CONST1) |
| 145 |
abort (); |
| 146 |
|
| 147 |
return 0; |
| 148 |
} |