| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-mavx2 -O2" } */ |
| 3 |
/* { dg-require-effective-target avx2 } */ |
| 4 |
|
| 5 |
#include "avx2-check.h" |
| 6 |
#include "ssse3-vals.h" |
| 7 |
|
| 8 |
static short |
| 9 |
signed_saturate_to_word (int x) |
| 10 |
{ |
| 11 |
if (x > (int) 0x7fff) |
| 12 |
return 0x7fff; |
| 13 |
|
| 14 |
if (x < (int) 0xffff8000) |
| 15 |
return 0x8000; |
| 16 |
|
| 17 |
return (short) x; |
| 18 |
} |
| 19 |
|
| 20 |
static void |
| 21 |
compute_phsubsw256 (short *i1, short *i2, short *r) |
| 22 |
{ |
| 23 |
int i; |
| 24 |
|
| 25 |
for (i = 0; i < 4; i++) |
| 26 |
r[i + 0] = signed_saturate_to_word (i1[2 * i] - i1[2 * i + 1]); |
| 27 |
|
| 28 |
for (i = 0; i < 4; i++) |
| 29 |
r[i + 4] = signed_saturate_to_word (i2[2 * i] - i2[2 * i + 1]); |
| 30 |
|
| 31 |
for (i = 0; i < 4; i++) |
| 32 |
r[i + 8] = signed_saturate_to_word (i1[2 * i + 8] - i1[2 * i + 9]); |
| 33 |
|
| 34 |
for (i = 0; i < 4; i++) |
| 35 |
r[i + 12] = signed_saturate_to_word (i2[2 * i + 8] - i2[2 * i + 9]); |
| 36 |
} |
| 37 |
|
| 38 |
static void |
| 39 |
avx2_test (void) |
| 40 |
{ |
| 41 |
union256i_w s1, s2, res; |
| 42 |
short res_ref[16]; |
| 43 |
int i; |
| 44 |
int fail = 0; |
| 45 |
|
| 46 |
for (i = 0; i < 256; i += 16) |
| 47 |
{ |
| 48 |
s1.x = _mm256_loadu_si256 ((__m256i *) & vals[i]); |
| 49 |
s2.x = _mm256_loadu_si256 ((__m256i *) & vals[i + 8]); |
| 50 |
|
| 51 |
res.x = _mm256_hsubs_epi16 (s1.x, s2.x); |
| 52 |
|
| 53 |
compute_phsubsw256 (s1.a, s2.a, res_ref); |
| 54 |
|
| 55 |
fail += check_union256i_w (res, res_ref); |
| 56 |
} |
| 57 |
|
| 58 |
if (fail != 0) |
| 59 |
abort (); |
| 60 |
} |