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_phaddsw256 (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, j;
      44    int fail = 0;
      45  
      46  
      47    for (i = 0; i < 256; i += 16)
      48      {
      49        s1.x = _mm256_loadu_si256 ((__m256i *) & vals[i]);
      50        s2.x = _mm256_loadu_si256 ((__m256i *) & vals[i + 8]);
      51  
      52        res.x = _mm256_hadds_epi16 (s1.x, s2.x);
      53  
      54        compute_phaddsw256 (s1.a, s2.a, res_ref);
      55  
      56        fail += check_union256i_w (res, res_ref);
      57      }
      58  
      59    if (fail != 0)
      60      abort ();
      61  }