| 1 |
/* { dg-do run { target { power10_hw } } } */ |
| 2 |
/* { dg-do link { target { ! power10_hw } } } */ |
| 3 |
/* { dg-require-effective-target power10_ok } */ |
| 4 |
/* { dg-options "-mdejagnu-cpu=power10 -save-temps -O2" } */ |
| 5 |
#include <altivec.h> |
| 6 |
|
| 7 |
#define DEBUG 0 |
| 8 |
|
| 9 |
#if DEBUG |
| 10 |
#include <stdio.h> |
| 11 |
#endif |
| 12 |
|
| 13 |
extern void abort (void); |
| 14 |
|
| 15 |
volatile vector double vresult_d_undefined; |
| 16 |
|
| 17 |
int |
| 18 |
main (int argc, char *argv []) |
| 19 |
{ |
| 20 |
int i; |
| 21 |
vector int vsrc_a_int; |
| 22 |
vector int vresult_int; |
| 23 |
vector int expected_vresult_int; |
| 24 |
int src_a_int = 13; |
| 25 |
|
| 26 |
vector unsigned int vsrc_a_uint; |
| 27 |
vector unsigned int vresult_uint; |
| 28 |
vector unsigned int expected_vresult_uint; |
| 29 |
unsigned int src_a_uint = 7; |
| 30 |
|
| 31 |
vector float vresult_f; |
| 32 |
vector float expected_vresult_f; |
| 33 |
vector float vsrc_a_f; |
| 34 |
float src_a_f = 23.0; |
| 35 |
|
| 36 |
vector double vsrc_a_d; |
| 37 |
vector double vresult_d; |
| 38 |
vector double expected_vresult_d; |
| 39 |
|
| 40 |
/* Vector splati word */ |
| 41 |
vresult_int = (vector signed int) { 1, 2, 3, 4 }; |
| 42 |
expected_vresult_int = (vector signed int) { -13, -13, -13, -13 }; |
| 43 |
|
| 44 |
vresult_int = vec_splati ( -13 ); |
| 45 |
|
| 46 |
if (!vec_all_eq (vresult_int, expected_vresult_int)) { |
| 47 |
#if DEBUG |
| 48 |
printf("ERROR, vec_splati (src_a_int)\n"); |
| 49 |
for(i = 0; i < 4; i++) |
| 50 |
printf(" vresult_int[%d] = %d, expected_vresult_int[%d] = %d\n", |
| 51 |
i, vresult_int[i], i, expected_vresult_int[i]); |
| 52 |
#else |
| 53 |
abort(); |
| 54 |
#endif |
| 55 |
} |
| 56 |
|
| 57 |
vresult_f = (vector float) { 1.0, 2.0, 3.0, 4.0 }; |
| 58 |
expected_vresult_f = (vector float) { 23.0, 23.0, 23.0, 23.0 }; |
| 59 |
|
| 60 |
vresult_f = vec_splati (23.0f); |
| 61 |
|
| 62 |
if (!vec_all_eq (vresult_f, expected_vresult_f)) { |
| 63 |
#if DEBUG |
| 64 |
printf("ERROR, vec_splati (src_a_f)\n"); |
| 65 |
for(i = 0; i < 4; i++) |
| 66 |
printf(" vresult_f[%d] = %f, expected_vresult_f[%d] = %f\n", |
| 67 |
i, vresult_f[i], i, expected_vresult_f[i]); |
| 68 |
#else |
| 69 |
abort(); |
| 70 |
#endif |
| 71 |
} |
| 72 |
|
| 73 |
/* Vector splati double */ |
| 74 |
vresult_d = (vector double) { 2.0, 3.0 }; |
| 75 |
expected_vresult_d = (vector double) { -31.0, -31.0 }; |
| 76 |
|
| 77 |
vresult_d = vec_splatid (-31.0f); |
| 78 |
|
| 79 |
if (!vec_all_eq (vresult_d, expected_vresult_d)) { |
| 80 |
#if DEBUG |
| 81 |
printf("ERROR, vec_splati (-31.0f)\n"); |
| 82 |
for(i = 0; i < 2; i++) |
| 83 |
printf(" vresult_d[%i] = %f, expected_vresult_d[%i] = %f\n", |
| 84 |
i, vresult_d[i], i, expected_vresult_d[i]); |
| 85 |
#else |
| 86 |
abort(); |
| 87 |
#endif |
| 88 |
} |
| 89 |
|
| 90 |
/* This test will generate a "note" to the user that the argument is |
| 91 |
subnormal. It is not an error, but results are not defined. Because this |
| 92 |
is undefined, we cannot check that any value is correct. Just store it in |
| 93 |
a volatile variable so the XXSPLTIDP instruction gets generated and the |
| 94 |
warning message printed. */ |
| 95 |
vresult_d_undefined = vec_splatid (6.6E-42f); |
| 96 |
|
| 97 |
/* Vector splat immediate */ |
| 98 |
vsrc_a_int = (vector int) { 2, 3, 4, 5 }; |
| 99 |
vresult_int = (vector int) { 1, 1, 1, 1 }; |
| 100 |
expected_vresult_int = (vector int) { 2, 20, 4, 20 }; |
| 101 |
|
| 102 |
vresult_int = vec_splati_ins (vsrc_a_int, 1, 20); |
| 103 |
|
| 104 |
if (!vec_all_eq (vresult_int, expected_vresult_int)) { |
| 105 |
#if DEBUG |
| 106 |
printf("ERROR, vec_splati_ins (vsrc_a_int, 1, 20)\n"); |
| 107 |
for(i = 0; i < 4; i++) |
| 108 |
printf(" vresult_int[%i] = %d, expected_vresult_int[%i] = %d\n", |
| 109 |
i, vresult_int[i], i, expected_vresult_int[i]); |
| 110 |
#else |
| 111 |
abort(); |
| 112 |
#endif |
| 113 |
} |
| 114 |
|
| 115 |
vsrc_a_uint = (vector unsigned int) { 4, 5, 6, 7 }; |
| 116 |
vresult_uint = (vector unsigned int) { 1, 1, 1, 1 }; |
| 117 |
expected_vresult_uint = (vector unsigned int) { 4, 40, 6, 40 }; |
| 118 |
|
| 119 |
vresult_uint = vec_splati_ins (vsrc_a_uint, 1, 40); |
| 120 |
|
| 121 |
if (!vec_all_eq (vresult_uint, expected_vresult_uint)) { |
| 122 |
#if DEBUG |
| 123 |
printf("ERROR, vec_splati_ins (vsrc_a_uint, 1, 40)\n"); |
| 124 |
for(i = 0; i < 4; i++) |
| 125 |
printf(" vresult_uint[%i] = %d, expected_vresult_uint[%i] = %d\n", |
| 126 |
i, vresult_uint[i], i, expected_vresult_uint[i]); |
| 127 |
#else |
| 128 |
abort(); |
| 129 |
#endif |
| 130 |
} |
| 131 |
|
| 132 |
vsrc_a_f = (vector float) { 2.0, 3.0, 4.0, 5.0 }; |
| 133 |
vresult_f = (vector float) { 1.0, 1.0, 1.0, 1.0 }; |
| 134 |
expected_vresult_f = (vector float) { 2.0, 20.1, 4.0, 20.1 }; |
| 135 |
|
| 136 |
vresult_f = vec_splati_ins (vsrc_a_f, 1, 20.1f); |
| 137 |
|
| 138 |
if (!vec_all_eq (vresult_f, expected_vresult_f)) { |
| 139 |
#if DEBUG |
| 140 |
printf("ERROR, vec_splati_ins (vsrc_a_f, 1, 20.1)\n"); |
| 141 |
for(i = 0; i < 4; i++) |
| 142 |
printf(" vresult_f[%i] = %f, expected_vresult_f[%i] = %f\n", |
| 143 |
i, vresult_f[i], i, expected_vresult_f[i]); |
| 144 |
#else |
| 145 |
abort(); |
| 146 |
#endif |
| 147 |
} |
| 148 |
|
| 149 |
return 0; |
| 150 |
} |
| 151 |
|
| 152 |
/* { dg-final { scan-assembler-times {\mxxspltiw\M} 3 } } */ |
| 153 |
/* { dg-final { scan-assembler-times {\mxxspltidp\M} 3 } } */ |
| 154 |
/* { dg-final { scan-assembler-times {\mxxsplti32dx\M} 3 } } */ |
| 155 |
|
| 156 |
|