1  /* { dg-skip-if "" { arm*-*-* } } */
       2  
       3  #include <arm_neon.h>
       4  #include "arm-neon-ref.h"
       5  #include "compute-ref-data.h"
       6  
       7  /* Expected results.  */
       8  VECT_VAR_DECL(expected, int, 8, 16) [] = { 0x5, 0x5, 0x5, 0x5,
       9  					   0x5, 0x5, 0x5, 0x5,
      10  					   0x12, 0x12, 0x12, 0x12,
      11  					   0x12, 0x12, 0x12, 0x12 };
      12  VECT_VAR_DECL(expected, int, 16, 8) [] = { 0x5, 0x5, 0x5, 0x5,
      13  					   0x1278, 0x1278, 0x1278, 0x1278 };
      14  VECT_VAR_DECL(expected, int, 32, 4) [] = { 0x5, 0x5, 0x12345678, 0x12345678 };
      15  VECT_VAR_DECL(expected, uint, 8, 16) [] = { 0x5, 0x5, 0x5, 0x5,
      16  					    0x5, 0x5, 0x5, 0x5,
      17  					    0x82, 0x82, 0x82, 0x82,
      18  					    0x82, 0x82, 0x82, 0x82 };
      19  VECT_VAR_DECL(expected, uint, 16, 8) [] = { 0x5, 0x5, 0x5, 0x5,
      20  					    0x8765, 0x8765, 0x8765, 0x8765 };
      21  VECT_VAR_DECL(expected, uint, 32, 4) [] = { 0x5, 0x5, 0x87654321, 0x87654321 };
      22  
      23  /* Expected results when saturation occurs.  */
      24  VECT_VAR_DECL(expected1, int, 8, 16) [] = { 0x5, 0x5, 0x5, 0x5,
      25  					    0x5, 0x5, 0x5, 0x5,
      26  					    0x7f, 0x7f, 0x7f, 0x7f,
      27  					    0x7f, 0x7f, 0x7f, 0x7f };
      28  VECT_VAR_DECL(expected1, int, 16, 8) [] = { 0x5, 0x5, 0x5, 0x5,
      29  					    0x7fff, 0x7fff, 0x7fff, 0x7fff };
      30  VECT_VAR_DECL(expected1, int, 32, 4) [] = { 0x5, 0x5, 0x7fffffff, 0x7fffffff };
      31  VECT_VAR_DECL(expected1, uint, 8, 16) [] = { 0x5, 0x5, 0x5, 0x5,
      32  					     0x5, 0x5, 0x5, 0x5,
      33  					     0xff, 0xff, 0xff, 0xff,
      34  					     0xff, 0xff, 0xff, 0xff };
      35  VECT_VAR_DECL(expected1, uint, 16, 8) [] = { 0x5, 0x5, 0x5, 0x5,
      36  					     0xffff, 0xffff, 0xffff, 0xffff };
      37  VECT_VAR_DECL(expected1, uint, 32, 4) [] = { 0x5, 0x5, 
      38  					     0xffffffff, 0xffffffff };
      39  
      40  #define TEST_MSG "VQMOVN_HIGH"
      41  void exec_vqmovn_high (void)
      42  {
      43    /* Basic test: vec128_r=vqmovn_high(vec64_r,vec128_x), store the result.  */
      44  #define TEST_VQMOVN_HIGH(T1, T2, W1, W2, N1, N2, CMT)				\
      45    Set_Neon_Cumulative_Sat(0, VECT_VAR(vec128_r, T1, W1, N2));			\
      46    VECT_VAR(vec128_r, T1, W1, N2) =						\
      47      vqmovn_high_##T2##W2(VECT_VAR(vec64_r, T1, W1, N1),				\
      48  			 VECT_VAR(vec128_x, T1, W2, N1));			\
      49    vst1q##_##T2##W1(VECT_VAR(result, T1, W1, N2),				\
      50  		   VECT_VAR(vec128_r, T1, W1, N2))
      51  
      52    DECL_VARIABLE_128BITS_VARIANTS(vec128_r);
      53    DECL_VARIABLE_64BITS_VARIANTS(vec64_r);
      54    DECL_VARIABLE_128BITS_VARIANTS(vec128_x);
      55  
      56    clean_results ();
      57  
      58    /* Fill vec64_r with a value easy to recognise in the result vector. */
      59    VDUP(vec64_r, , int, s, 8, 8, 0x5);
      60    VDUP(vec64_r, , int, s, 16, 4, 0x5);
      61    VDUP(vec64_r, , int, s, 32, 2, 0x5);
      62    VDUP(vec64_r, , uint, u, 8, 8, 0x5);
      63    VDUP(vec64_r, , uint, u, 16, 4, 0x5);
      64    VDUP(vec64_r, , uint, u, 32, 2, 0x5);
      65  
      66    /* Fill input vector with arbitrary values.  */
      67    VDUP(vec128_x, q, int, s, 16, 8, 0x12);
      68    VDUP(vec128_x, q, int, s, 32, 4, 0x1278);
      69    VDUP(vec128_x, q, int, s, 64, 2, 0x12345678);
      70    VDUP(vec128_x, q, uint, u, 16, 8, 0x82);
      71    VDUP(vec128_x, q, uint, u, 32, 4, 0x8765);
      72    VDUP(vec128_x, q, uint, u, 64, 2, 0x87654321);
      73  
      74  
      75  #define CMT ""
      76    TEST_VQMOVN_HIGH(int, s, 8, 16, 8, 16, CMT);
      77    TEST_VQMOVN_HIGH(int, s, 16, 32, 4, 8, CMT);
      78    TEST_VQMOVN_HIGH(int, s, 32, 64, 2, 4, CMT);
      79    TEST_VQMOVN_HIGH(uint, u, 8, 16, 8, 16, CMT);
      80    TEST_VQMOVN_HIGH(uint, u, 16, 32, 4, 8, CMT);
      81    TEST_VQMOVN_HIGH(uint, u, 32, 64, 2, 4, CMT);
      82  
      83    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected, CMT);
      84    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected, CMT);
      85    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected, CMT);
      86    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected, CMT);
      87    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected, CMT);
      88    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected, CMT);
      89  
      90  
      91    /* Fill input vector with arbitrary values which cause cumulative
      92       saturation.  */
      93    VDUP(vec128_x, q, int, s, 16, 8, 0x1234);
      94    VDUP(vec128_x, q, int, s, 32, 4, 0x12345678);
      95    VDUP(vec128_x, q, int, s, 64, 2, 0x1234567890ABLL);
      96    VDUP(vec128_x, q, uint, u, 16, 8, 0x8234);
      97    VDUP(vec128_x, q, uint, u, 32, 4, 0x87654321);
      98    VDUP(vec128_x, q, uint, u, 64, 2, 0x8765432187654321ULL);
      99  
     100  #undef CMT
     101  #define CMT " (with saturation)"
     102    TEST_VQMOVN_HIGH(int, s, 8, 16, 8, 16, CMT);
     103    TEST_VQMOVN_HIGH(int, s, 16, 32, 4, 8, CMT);
     104    TEST_VQMOVN_HIGH(int, s, 32, 64, 2, 4, CMT);
     105    TEST_VQMOVN_HIGH(uint, u, 8, 16, 8, 16, CMT);
     106    TEST_VQMOVN_HIGH(uint, u, 16, 32, 4, 8, CMT);
     107    TEST_VQMOVN_HIGH(uint, u, 32, 64, 2, 4, CMT);
     108  
     109    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected1, CMT);
     110    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected1, CMT);
     111    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected1, CMT);
     112    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected1, CMT);
     113    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected1, CMT);
     114    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected1, CMT);
     115  }
     116  
     117  int main (void)
     118  {
     119    exec_vqmovn_high ();
     120    return 0;
     121  }