| 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_pmaddubsw256 (short *i1, short *i2, short *r) |
| 22 |
{ |
| 23 |
unsigned char *ub1 = (unsigned char *) i1; |
| 24 |
char *sb2 = (char *) i2; |
| 25 |
short *sout = (short *) r; |
| 26 |
int t0; |
| 27 |
int i; |
| 28 |
|
| 29 |
for (i = 0; i < 16; i++) |
| 30 |
{ |
| 31 |
t0 = ((int) ub1[2 * i] * (int) sb2[2 * i] + |
| 32 |
(int) ub1[2 * i + 1] * (int) sb2[2 * i + 1]); |
| 33 |
sout[i] = signed_saturate_to_word (t0); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
static void |
| 38 |
avx2_test (void) |
| 39 |
{ |
| 40 |
union256i_w s1, s2, res; |
| 41 |
short res_ref[16]; |
| 42 |
int i; |
| 43 |
int fail = 0; |
| 44 |
|
| 45 |
for (i = 0; i < 256; i += 16) |
| 46 |
{ |
| 47 |
s1.x = _mm256_loadu_si256 ((__m256i *) & vals[i]); |
| 48 |
s2.x = _mm256_loadu_si256 ((__m256i *) & vals[i + 8]); |
| 49 |
|
| 50 |
res.x = _mm256_maddubs_epi16 (s1.x, s2.x); |
| 51 |
|
| 52 |
compute_pmaddubsw256 (s1.a, s2.a, res_ref); |
| 53 |
|
| 54 |
fail += check_union256i_w (res, res_ref); |
| 55 |
} |
| 56 |
|
| 57 |
if (fail != 0) |
| 58 |
abort (); |
| 59 |
} |