(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
advsimd-intrinsics/
vqshrn_high_n.c
       1  /* { dg-do run } */
       2  /* { dg-skip-if "" { arm*-*-* } } */
       3  
       4  #include <arm_neon.h>
       5  #include "arm-neon-ref.h"
       6  #include "compute-ref-data.h"
       7  
       8  /* Expected results.  */
       9  VECT_VAR_DECL(expected,int,8,16) [] = { 0xf0, 0xf1, 0xf2, 0xf3,
      10  					0xf4, 0xf5, 0xf6, 0xf7,
      11  					0xf8, 0xf8, 0xf9, 0xf9,
      12  					0xfa, 0xfa, 0xfb, 0xfb };
      13  VECT_VAR_DECL(expected,int,16,8) [] = { 0xfff0, 0xfff1, 0xfff2, 0xfff3,
      14  					0xfff8, 0xfff8, 0xfff9, 0xfff9 };
      15  VECT_VAR_DECL(expected,int,32,4) [] = { 0xfffffff0, 0xfffffff1,
      16  					0xfffffffc, 0xfffffffc };
      17  VECT_VAR_DECL(expected,uint,8,16) [] = { 0xf0, 0xf1, 0xf2, 0xf3,
      18  					 0xf4, 0xf5, 0xf6, 0xf7,
      19  					 0xff, 0xff, 0xff, 0xff,
      20  					 0xff, 0xff, 0xff, 0xff };
      21  VECT_VAR_DECL(expected,uint,16,8) [] = { 0xfff0, 0xfff1, 0xfff2, 0xfff3,
      22  					 0xffff, 0xffff, 0xffff, 0xffff };
      23  VECT_VAR_DECL(expected,uint,32,4) [] = { 0xfffffff0, 0xfffffff1,
      24  					 0xffffffff, 0xffffffff };
      25  
      26  /* Expected results with max input value shifted by 3.  */
      27  VECT_VAR_DECL(expected_max_sh3,int,8,16) [] = { 0x7f, 0x7f, 0x7f, 0x7f,
      28  						0x7f, 0x7f, 0x7f, 0x7f,
      29  						0x7f, 0x7f, 0x7f, 0x7f,
      30  						0x7f, 0x7f, 0x7f, 0x7f };
      31  VECT_VAR_DECL(expected_max_sh3,int,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      32  						0x7fff, 0x7fff, 0x7fff, 0x7fff };
      33  VECT_VAR_DECL(expected_max_sh3,int,32,4) [] = { 0x7fffffff, 0x7fffffff,
      34  						0x7fffffff, 0x7fffffff };
      35  VECT_VAR_DECL(expected_max_sh3,uint,8,16) [] = { 0xff, 0xff, 0xff, 0xff,
      36  						 0xff, 0xff, 0xff, 0xff,
      37  						 0xff, 0xff, 0xff, 0xff,
      38  						 0xff, 0xff, 0xff, 0xff };
      39  VECT_VAR_DECL(expected_max_sh3,uint,16,8) [] = { 0xffff, 0xffff, 0xffff, 0xffff,
      40  						 0xffff, 0xffff, 0xffff, 0xffff };
      41  VECT_VAR_DECL(expected_max_sh3,uint,32,4) [] = { 0xffffffff, 0xffffffff,
      42  						 0xffffffff, 0xffffffff };
      43  
      44  /* Expected results with max input value shifted by type size.  */
      45  VECT_VAR_DECL(expected_max_shmax,int,8,16) [] = { 0x7f, 0x7f, 0x7f, 0x7f,
      46  						  0x7f, 0x7f, 0x7f, 0x7f,
      47  						  0x7f, 0x7f, 0x7f, 0x7f,
      48  						  0x7f, 0x7f, 0x7f, 0x7f };
      49  VECT_VAR_DECL(expected_max_shmax,int,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      50  						  0x7fff, 0x7fff, 0x7fff, 0x7fff };
      51  VECT_VAR_DECL(expected_max_shmax,int,32,4) [] = { 0x7fffffff, 0x7fffffff,
      52  						  0x7fffffff, 0x7fffffff };
      53  VECT_VAR_DECL(expected_max_shmax,uint,8,16) [] = { 0xff, 0xff, 0xff, 0xff,
      54  						   0xff, 0xff, 0xff, 0xff,
      55  						   0xff, 0xff, 0xff, 0xff,
      56  						   0xff, 0xff, 0xff, 0xff };
      57  VECT_VAR_DECL(expected_max_shmax,uint,16,8) [] = { 0xffff, 0xffff, 0xffff, 0xffff,
      58  						   0xffff, 0xffff, 0xffff, 0xffff };
      59  VECT_VAR_DECL(expected_max_shmax,uint,32,4) [] = { 0xffffffff, 0xffffffff,
      60  						   0xffffffff, 0xffffffff };
      61  
      62  #define INSN vqshrn_high_n
      63  #define TEST_MSG "VQSHRN_HIGH_N"
      64  
      65  #define FNNAME1(NAME) void exec_ ## NAME (void)
      66  #define FNNAME(NAME) FNNAME1(NAME)
      67  
      68  FNNAME (INSN)
      69  {
      70    /* Basic test: y=vqshrn_high_n(x1,x2,v), then store the result.  */
      71  #define TEST_VQSHRN_HIGH_N2(INSN, T1, T2, W, W2, N, N2, V) \
      72    VECT_VAR(vector_res, T1, W2, N2) =			   \
      73      INSN##_##T2##W(VECT_VAR(vector1, T1, W2, N),	   \
      74  		   VECT_VAR(vector2, T1, W, N), V);	   \
      75    vst1q_##T2##W2(VECT_VAR(result, T1, W2, N2),		   \
      76  		 VECT_VAR(vector_res, T1, W2, N2));
      77  
      78    /* Two auxliary macros are necessary to expand INSN */
      79  #define TEST_VQSHRN_HIGH_N1(INSN, T1, T2, W, W2, N, N2, V) \
      80    TEST_VQSHRN_HIGH_N2(INSN, T1, T2, W, W2, N, N2, V)
      81  
      82  #define TEST_VQSHRN_HIGH_N(T1, T2, W, W2, N, N2, V) \
      83    TEST_VQSHRN_HIGH_N1(INSN, T1, T2, W, W2, N, N2, V)
      84  
      85  
      86    DECL_VARIABLE(vector1, int, 8, 8);
      87    DECL_VARIABLE(vector1, int, 16, 4);
      88    DECL_VARIABLE(vector1, int, 32, 2);
      89    DECL_VARIABLE(vector1, uint, 8, 8);
      90    DECL_VARIABLE(vector1, uint, 16, 4);
      91    DECL_VARIABLE(vector1, uint, 32, 2);
      92  
      93    /* vector is twice as large as vector_res.  */
      94    DECL_VARIABLE(vector2, int, 16, 8);
      95    DECL_VARIABLE(vector2, int, 32, 4);
      96    DECL_VARIABLE(vector2, int, 64, 2);
      97    DECL_VARIABLE(vector2, uint, 16, 8);
      98    DECL_VARIABLE(vector2, uint, 32, 4);
      99    DECL_VARIABLE(vector2, uint, 64, 2);
     100  
     101    DECL_VARIABLE(vector_res, int, 8, 16);
     102    DECL_VARIABLE(vector_res, int, 16, 8);
     103    DECL_VARIABLE(vector_res, int, 32, 4);
     104    DECL_VARIABLE(vector_res, uint, 8, 16);
     105    DECL_VARIABLE(vector_res, uint, 16, 8);
     106    DECL_VARIABLE(vector_res, uint, 32, 4);
     107  
     108    clean_results ();
     109  
     110    VLOAD(vector1, buffer, , int, s, 8, 8);
     111    VLOAD(vector1, buffer, , int, s, 16, 4);
     112    VLOAD(vector1, buffer, , int, s, 32, 2);
     113    VLOAD(vector1, buffer, , uint, u, 8, 8);
     114    VLOAD(vector1, buffer, , uint, u, 16, 4);
     115    VLOAD(vector1, buffer, , uint, u, 32, 2);
     116  
     117    VLOAD(vector2, buffer, q, int, s, 16, 8);
     118    VLOAD(vector2, buffer, q, int, s, 32, 4);
     119    VLOAD(vector2, buffer, q, int, s, 64, 2);
     120    VLOAD(vector2, buffer, q, uint, u, 16, 8);
     121    VLOAD(vector2, buffer, q, uint, u, 32, 4);
     122    VLOAD(vector2, buffer, q, uint, u, 64, 2);
     123  
     124    /* Choose shift amount arbitrarily.  */
     125  #define CMT ""
     126    TEST_VQSHRN_HIGH_N(int, s, 16, 8, 8, 16, 1);
     127    TEST_VQSHRN_HIGH_N(int, s, 32, 16, 4, 8, 1);
     128    TEST_VQSHRN_HIGH_N(int, s, 64, 32, 2, 4, 2);
     129    TEST_VQSHRN_HIGH_N(uint, u, 16, 8, 8, 16, 2);
     130    TEST_VQSHRN_HIGH_N(uint, u, 32, 16, 4, 8, 3);
     131    TEST_VQSHRN_HIGH_N(uint, u, 64, 32, 2, 4, 3);
     132  
     133    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected, CMT);
     134    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected, CMT);
     135    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected, CMT);
     136    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected, CMT);
     137    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected, CMT);
     138    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected, CMT);
     139  
     140    /* Use max possible value as input.  */
     141    VDUP(vector1, , int, s, 8, 8, 0x7F);
     142    VDUP(vector1, , int, s, 16, 4, 0x7FFF);
     143    VDUP(vector1, , int, s, 32, 2, 0x7FFFFFFFLL);
     144    VDUP(vector1, , uint, u, 8, 8, 0xFF);
     145    VDUP(vector1, , uint, u, 16, 4, 0xFFFF);
     146    VDUP(vector1, , uint, u, 32, 2, 0xFFFFFFFFULL);
     147  
     148    VDUP(vector2, q, int, s, 16, 8, 0x7FFF);
     149    VDUP(vector2, q, int, s, 32, 4, 0x7FFFFFFF);
     150    VDUP(vector2, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
     151    VDUP(vector2, q, uint, u, 16, 8, 0xFFFF);
     152    VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFFF);
     153    VDUP(vector2, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
     154  
     155  #undef CMT
     156  #define CMT " (check saturation: shift by 3)"
     157    TEST_VQSHRN_HIGH_N(int, s, 16, 8, 8, 16, 3);
     158    TEST_VQSHRN_HIGH_N(int, s, 32, 16, 4, 8, 3);
     159    TEST_VQSHRN_HIGH_N(int, s, 64, 32, 2, 4, 3);
     160    TEST_VQSHRN_HIGH_N(uint, u, 16, 8, 8, 16, 3);
     161    TEST_VQSHRN_HIGH_N(uint, u, 32, 16, 4, 8, 3);
     162    TEST_VQSHRN_HIGH_N(uint, u, 64, 32, 2, 4, 3);
     163  
     164    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected_max_sh3, CMT);
     165    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected_max_sh3, CMT);
     166    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected_max_sh3, CMT);
     167    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_max_sh3, CMT);
     168    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_max_sh3, CMT);
     169    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_max_sh3, CMT);
     170  
     171  
     172  #undef CMT
     173  #define CMT " (check saturation: shift by max)"
     174    TEST_VQSHRN_HIGH_N(int, s, 16, 8, 8, 16, 8);
     175    TEST_VQSHRN_HIGH_N(int, s, 32, 16, 4, 8, 16);
     176    TEST_VQSHRN_HIGH_N(int, s, 64, 32, 2, 4, 32);
     177    TEST_VQSHRN_HIGH_N(uint, u, 16, 8, 8, 16, 8);
     178    TEST_VQSHRN_HIGH_N(uint, u, 32, 16, 4, 8, 16);
     179    TEST_VQSHRN_HIGH_N(uint, u, 64, 32, 2, 4, 32);
     180  
     181    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected_max_shmax, CMT);
     182    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected_max_shmax, CMT);
     183    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected_max_shmax, CMT);
     184    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_max_shmax, CMT);
     185    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_max_shmax, CMT);
     186    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_max_shmax, CMT);
     187  }
     188  
     189  int main (void)
     190  {
     191    exec_vqshrn_high_n ();
     192    return 0;
     193  }