1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/* { dg-do run } */
/* { dg-require-effective-target p9vector_hw } */
/* { dg-options "-mdejagnu-cpu=power9 -O2" } */
#ifdef DEBUG
#include <stdio.h>
#endif
#include <altivec.h> // vector
void abort (void);
int main() {
int i;
vector float vfr, vfexpt;
vector unsigned short vusha;
/* 1.0, -2.0, 0.0, 8.5, 1.5, 0.5, 1.25, -0.25 */
vusha = (vector unsigned short){0B011110000000000, 0B1100000000000000,
0B000000000000000, 0B0100100001000000,
0B011111000000000, 0B0011100000000000,
0B011110100000000, 0B1011010000000000};
#ifdef DEBUG
printf ("Claim, source data is 8 16-bit floats:\n");
printf (" {1.0, -2.0, 0.0, 8.5, 1.5, 0.5, 1.25, -0.25}\n");
printf ("vusha = (vector unsigned short){0B011110000000000, 0B1100000000000000,\n");
printf (" 0B000000000000000, 0B0100100001000000,\n");
printf (" 0B011111000000000, 0B0011100000000000,\n");
printf (" 0B011110100000000, 0B1011010000000000};\n\n");
#endif
/* The ABI lists the builtins as:
vec_extract_fp32_from_shorth()
vec_extract_fp32_from_shortl()
GCC will also accept and map the builtin names
vec_extract_fp_from_shorth()
vec_extract_fp_from_shortl()
to the same builtins internally. For completeness,
test both builtin function names. */
vfexpt = (vector float){1.0, -2.0, 0.0, 8.5};
vfr = vec_extract_fp32_from_shorth(vusha);
#ifdef DEBUG
printf ("vec_extract_fp32_from_shorth\n");
for (i=0; i<4; i++)
printf("result[%d] = %f; expected[%d] = %f\n",
i, vfr[i], i, vfexpt[i]);
#endif
for (i=0; i<4; i++) {
if (vfr[i] != vfexpt[i])
abort();
}
vfexpt = (vector float){1.5, 0.5, 1.25, -0.25};
vfr = vec_extract_fp32_from_shortl(vusha);
#ifdef DEBUG
printf ("\nvec_extract_fp32_from_shortl\n");
for (i=0; i<4; i++)
printf("result[%d] = %f; expected[%d] = %f\n",
i, vfr[i], i, vfexpt[i]);
#endif
for (i=0; i<4; i++) {
if (vfr[i] != vfexpt[i])
abort();
}
vfexpt = (vector float){1.0, -2.0, 0.0, 8.5};
vfr = vec_extract_fp_from_shorth(vusha);
#ifdef DEBUG
printf ("vec_extract_fp_from_shorth\n");
for (i=0; i<4; i++)
printf("result[%d] = %f; expected[%d] = %f\n",
i, vfr[i], i, vfexpt[i]);
#endif
for (i=0; i<4; i++) {
if (vfr[i] != vfexpt[i])
abort();
}
vfexpt = (vector float){1.5, 0.5, 1.25, -0.25};
vfr = vec_extract_fp_from_shortl(vusha);
#ifdef DEBUG
printf ("\nvec_extract_fp_from_shortl\n");
for (i=0; i<4; i++)
printf("result[%d] = %f; expected[%d] = %f\n",
i, vfr[i], i, vfexpt[i]);
#endif
for (i=0; i<4; i++) {
if (vfr[i] != vfexpt[i])
abort();
}
}
|