(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
i386/
ssse3-pshufb.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target ssse3 } */
       3  /* { dg-options "-O2 -fno-strict-aliasing -mssse3" } */
       4  
       5  #ifndef CHECK_H
       6  #define CHECK_H "ssse3-check.h"
       7  #endif
       8  
       9  #ifndef TEST
      10  #define TEST ssse3_test
      11  #endif
      12  
      13  #include CHECK_H
      14  
      15  #include "ssse3-vals.h"
      16  
      17  #include <tmmintrin.h>
      18  
      19  /* Test the 64-bit form */
      20  static void
      21  ssse3_test_pshufb (int *i1, int *i2, int *r)
      22  {
      23    __m64 t1 = *(__m64 *) i1;
      24    __m64 t2 = *(__m64 *) i2;
      25    *(__m64 *)r = _mm_shuffle_pi8 (t1, t2);
      26    _mm_empty ();
      27  }
      28  
      29  /* Test the 128-bit form */
      30  static void
      31  ssse3_test_pshufb128 (int *i1, int *i2, int *r)
      32  {
      33    /* Assumes incoming pointers are 16-byte aligned */
      34    __m128i t1 = *(__m128i *) i1;
      35    __m128i t2 = *(__m128i *) i2;
      36    *(__m128i *)r = _mm_shuffle_epi8 (t1, t2);
      37  }
      38  
      39  /* Routine to manually compute the results */
      40  static void
      41  compute_correct_result_64 (int *i1, int *i2, int *r)
      42  {
      43    char *b1 = (char *) i1;
      44    char *b2 = (char *) i2;
      45    char *bout = (char *) r;
      46    int i;
      47    char select;
      48  
      49    for (i = 0; i < 16; i++)
      50      {
      51        select = b2[i];
      52        if (select & 0x80)
      53  	bout[i] = 0;
      54        else if (i < 8)
      55  	bout[i] = b1[select & 0x7];
      56        else
      57  	bout[i] = b1[8 + (select & 0x7)];
      58      }
      59  }
      60  
      61  static void
      62  compute_correct_result_128 (int *i1, int *i2, int *r)
      63  {
      64    char *b1 = (char *) i1;
      65    char *b2 = (char *) i2;
      66    char *bout = (char *) r;
      67    int i;
      68    char select;
      69  
      70    for (i = 0; i < 16; i++)
      71      {
      72        select = b2[i];
      73        if (select & 0x80)
      74  	bout[i] = 0;
      75        else
      76  	bout[i] = b1[select & 0xf];
      77      }
      78  }
      79  
      80  static void
      81  TEST (void)
      82  {
      83    int i;
      84    int r [4] __attribute__ ((aligned(16)));
      85    int ck [4];
      86    int fail = 0;
      87  
      88    for (i = 0; i < 256; i += 8)
      89      {
      90        /* Manually compute the result */
      91        compute_correct_result_64 (&vals[i + 0], &vals[i + 4], ck);
      92  
      93        /* Run the 64-bit tests */
      94        ssse3_test_pshufb (&vals[i + 0], &vals[i + 4], &r[0]);
      95        ssse3_test_pshufb (&vals[i + 2], &vals[i + 6], &r[2]);
      96        fail += chk_128 (ck, r);
      97  
      98        /* Recompute the result for 128-bits */
      99        compute_correct_result_128 (&vals[i + 0], &vals[i + 4], ck);
     100  
     101        /* Run the 128-bit tests */
     102        ssse3_test_pshufb128 (&vals[i + 0], &vals[i + 4], r);
     103        fail += chk_128 (ck, r);
     104      }
     105  
     106    if (fail != 0)
     107      abort ();
     108  }