| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target p9vector_hw } */ |
| 3 |
/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ |
| 4 |
|
| 5 |
#include <altivec.h> |
| 6 |
#include <stdio.h> |
| 7 |
|
| 8 |
void abort (void); |
| 9 |
|
| 10 |
int main() { |
| 11 |
int i; |
| 12 |
vector float vfa, vfb; |
| 13 |
vector unsigned short vresult, vexpected; |
| 14 |
|
| 15 |
vfa = (vector float){0.4, 1.6, 20.0, 99.9 }; |
| 16 |
vfb = (vector float){10.0, -2.0, 70.0, 999.0 }; |
| 17 |
|
| 18 |
/* Expected results. */ |
| 19 |
vexpected = (vector unsigned short) { 0x3666, 0x3e66, 0x4d00, 0x563e, |
| 20 |
0x4900, 0xc000, 0x5460, 0x63ce }; |
| 21 |
|
| 22 |
/* |
| 23 |
vresult = vec_pack_to_short_fp32 (vfa, vfb); |
| 24 |
This built-in converts a pair of vector floats into a single vector of |
| 25 |
packed half-precision (F16) values. The result type is a vector of |
| 26 |
signed shorts. |
| 27 |
The expected codegen for this builtin is |
| 28 |
xvcvsphp t, vfa |
| 29 |
xvcvsphp u, vfb |
| 30 |
if (little endian) |
| 31 |
vpkuwum vresult, t, u |
| 32 |
else |
| 33 |
vpkuwum vresult, u, t |
| 34 |
*/ |
| 35 |
|
| 36 |
vresult = vec_pack_to_short_fp32 (vfa, vfb); |
| 37 |
|
| 38 |
#ifdef DEBUG |
| 39 |
for(i = 0; i< 4; i++) { printf("i=[%d] %f \n",i,vfa[i]); } |
| 40 |
for(i = 0; i< 4; i++) { printf("i=[%d] %f \n",i+4,vfb[i]); } |
| 41 |
for(i = 0; i< 8; i++) { printf("i=[%d] %d \n",i,vresult[i]); } |
| 42 |
#endif |
| 43 |
|
| 44 |
for(i = 0; i< 8; i++) { |
| 45 |
if (vresult[i] != vexpected[i]) { |
| 46 |
printf("i=[%d] 0x%x != 0x%x \n",i,vresult[i],vexpected[i]); |
| 47 |
abort(); |
| 48 |
} |
| 49 |
} |
| 50 |
} |