(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
advsimd-intrinsics/
vqrshrn_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, 0xf9, 0xf9, 0xfa,
      12  					0xfa, 0xfb, 0xfb, 0xfc };
      13  VECT_VAR_DECL(expected,int,16,8) [] = { 0xfff0, 0xfff1, 0xfff2, 0xfff3,
      14  					0xfff8, 0xfff9, 0xfff9, 0xfffa };
      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 shift by 3.  */
      27  VECT_VAR_DECL(expected_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_sh3,int,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      32  					    0x7fff, 0x7fff, 0x7fff, 0x7fff };
      33  VECT_VAR_DECL(expected_sh3,int,32,4) [] = { 0x7fffffff, 0x7fffffff,
      34  					    0x7fffffff, 0x7fffffff };
      35  VECT_VAR_DECL(expected_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_sh3,uint,16,8) [] = { 0xffff, 0xffff, 0xffff, 0xffff,
      40  					     0xffff, 0xffff, 0xffff, 0xffff };
      41  VECT_VAR_DECL(expected_sh3,uint,32,4) [] = { 0xffffffff, 0xffffffff,
      42  					     0xffffffff, 0xffffffff };
      43  
      44  /* Expected results with shift by max amount.  */
      45  VECT_VAR_DECL(expected_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_shmax,int,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      50  					      0x7fff, 0x7fff, 0x7fff, 0x7fff };
      51  VECT_VAR_DECL(expected_shmax,int,32,4) [] = { 0x7fffffff, 0x7fffffff,
      52  					      0x7fffffff, 0x7fffffff };
      53  VECT_VAR_DECL(expected_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_shmax,uint,16,8) [] = { 0xffff, 0xffff, 0xffff, 0xffff,
      58  					       0xffff, 0xffff, 0xffff, 0xffff };
      59  VECT_VAR_DECL(expected_shmax,uint,32,4) [] = { 0xffffffff, 0xffffffff,
      60  					       0xffffffff, 0xffffffff };
      61  
      62  #define INSN vqrshrn_high_n
      63  #define TEST_MSG "VQRSHRN_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=vqrshrn_high_n(x,v), then store the result.  */
      71  #define TEST_VQRSHRN_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_VQRSHRN_HIGH_N1(INSN, T1, T2, W, W2, N, N2, V) \
      80    TEST_VQRSHRN_HIGH_N2(INSN, T1, T2, W, W2, N, N2, V)
      81  
      82  #define TEST_VQRSHRN_HIGH_N(T1, T2, W, W2, N, N2, V) \
      83    TEST_VQRSHRN_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_VQRSHRN_HIGH_N(int, s, 16, 8, 8, 16, 1);
     127    TEST_VQRSHRN_HIGH_N(int, s, 32, 16, 4, 8, 1);
     128    TEST_VQRSHRN_HIGH_N(int, s, 64, 32, 2, 4, 2);
     129    TEST_VQRSHRN_HIGH_N(uint, u, 16, 8, 8, 16, 2);
     130    TEST_VQRSHRN_HIGH_N(uint, u, 32, 16, 4, 8, 3);
     131    TEST_VQRSHRN_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  
     141    /* Another set of tests, shifting max value by 3.  */
     142    VDUP(vector1, , int, s, 8, 8, 0x7F);
     143    VDUP(vector1, , int, s, 16, 4, 0x7FFF);
     144    VDUP(vector1, , int, s, 32, 2, 0x7FFFFFFFLL);
     145    VDUP(vector1, , uint, u, 8, 8, 0xFF);
     146    VDUP(vector1, , uint, u, 16, 4, 0xFFFF);
     147    VDUP(vector1, , uint, u, 32, 2, 0xFFFFFFFFULL);
     148  
     149    VDUP(vector2, q, int, s, 16, 8, 0x7FFF);
     150    VDUP(vector2, q, int, s, 32, 4, 0x7FFFFFFF);
     151    VDUP(vector2, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
     152    VDUP(vector2, q, uint, u, 16, 8, 0xFFFF);
     153    VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFFF);
     154    VDUP(vector2, q, uint, u, 64, 2, 0xFFFFFFFFFFFFFFFFULL);
     155  
     156  #undef CMT
     157  #define CMT " (check saturation: shift by 3)"
     158    TEST_VQRSHRN_HIGH_N(int, s, 16, 8, 8, 16, 3);
     159    TEST_VQRSHRN_HIGH_N(int, s, 32, 16, 4, 8, 3);
     160    TEST_VQRSHRN_HIGH_N(int, s, 64, 32, 2, 4, 3);
     161    TEST_VQRSHRN_HIGH_N(uint, u, 16, 8, 8, 16, 3);
     162    TEST_VQRSHRN_HIGH_N(uint, u, 32, 16, 4, 8, 3);
     163    TEST_VQRSHRN_HIGH_N(uint, u, 64, 32, 2, 4, 3);
     164  
     165    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected_sh3, CMT);
     166    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected_sh3, CMT);
     167    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected_sh3, CMT);
     168    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_sh3, CMT);
     169    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_sh3, CMT);
     170    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_sh3, CMT);
     171  
     172  
     173    /* Shift by max amount.  */
     174  #undef CMT
     175  #define CMT " (check saturation: shift by max)"
     176    TEST_VQRSHRN_HIGH_N(int, s, 16, 8, 8, 16, 8);
     177    TEST_VQRSHRN_HIGH_N(int, s, 32, 16, 4, 8, 16);
     178    TEST_VQRSHRN_HIGH_N(int, s, 64, 32, 2, 4, 32);
     179    TEST_VQRSHRN_HIGH_N(uint, u, 16, 8, 8, 16, 8);
     180    TEST_VQRSHRN_HIGH_N(uint, u, 32, 16, 4, 8, 16);
     181    TEST_VQRSHRN_HIGH_N(uint, u, 64, 32, 2, 4, 32);
     182  
     183    CHECK(TEST_MSG, int, 8, 16, PRIx8, expected_shmax, CMT);
     184    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected_shmax, CMT);
     185    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected_shmax, CMT);
     186    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_shmax, CMT);
     187    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_shmax, CMT);
     188    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_shmax, CMT);
     189  }
     190  
     191  int main (void)
     192  {
     193    exec_vqrshrn_high_n ();
     194    return 0;
     195  }