(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
advsimd-intrinsics/
vqshrun_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 with negative input.  */
       9  VECT_VAR_DECL(expected_neg,uint,8,16) [] = { 0xfe, 0xfe, 0xfe, 0xfe,
      10  					     0xfe, 0xfe, 0xfe, 0xfe,
      11  					     0x0, 0x0, 0x0, 0x0,
      12  					     0x0,0x0, 0x0, 0x0 };
      13  VECT_VAR_DECL(expected_neg,uint,16,8) [] = { 0xfffd, 0xfffd, 0xfffd, 0xfffd,
      14  					     0x0, 0x0, 0x0, 0x0, 0x0 };
      15  VECT_VAR_DECL(expected_neg,uint,32,4) [] = { 0xfffffffc, 0xfffffffc,
      16  					     0x0, 0x0 };
      17  
      18  /* Expected results with max input value shifted by 1.  */
      19  VECT_VAR_DECL(expected_max_sh1,uint,8,16) [] = { 0x7f, 0x7f, 0x7f, 0x7f,
      20  						 0x7f, 0x7f, 0x7f, 0x7f,
      21  						 0xff, 0xff, 0xff, 0xff,
      22  						 0xff, 0xff, 0xff, 0xff };
      23  VECT_VAR_DECL(expected_max_sh1,uint,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      24  						 0xffff, 0xffff, 0xffff, 0xffff };
      25  VECT_VAR_DECL(expected_max_sh1,uint,32,4) [] = { 0x7fffffff, 0x7fffffff,
      26  						 0xffffffff, 0xffffffff };
      27  
      28  /* Expected results.  */
      29  VECT_VAR_DECL(expected,uint,8,16) [] = { 0x12, 0x12, 0x12, 0x12,
      30  					 0x12, 0x12, 0x12, 0x12,
      31  					 0x48, 0x48, 0x48, 0x48,
      32  					 0x48, 0x48, 0x48, 0x48 };
      33  VECT_VAR_DECL(expected,uint,16,8) [] = { 0x4321, 0x4321, 0x4321, 0x4321,
      34  					 0x0, 0x0, 0x0, 0x0 };
      35  VECT_VAR_DECL(expected,uint,32,4) [] = { 0xdeadbeef, 0xdeadbeef,
      36  					 0xdeadbe, 0xdeadbe };
      37  
      38  #define INSN vqshrun_high_n
      39  #define TEST_MSG "VQSHRUN_HIGH_N"
      40  
      41  #define FNNAME1(NAME) void exec_ ## NAME (void)
      42  #define FNNAME(NAME) FNNAME1(NAME)
      43  
      44  FNNAME (INSN)
      45  {
      46    /* Basic test: y=vqshrun_high_n(x,v), then store the result.  */
      47  #define TEST_VQSHRUN_HIGH_N2(INSN, T1, T2, W, W2, N, N2, V) \
      48    VECT_VAR(vector_res, uint, W2, N2) =			    \
      49      INSN##_##T2##W(VECT_VAR(vector1,uint, W2, N),	    \
      50  		   VECT_VAR(vector2, T1, W, N), V);	    \
      51    vst1q_u##W2(VECT_VAR(result, uint, W2, N2),		    \
      52  	      VECT_VAR(vector_res, uint, W2, N2));	    \
      53  
      54    /* Two auxliary macros are necessary to expand INSN */
      55  #define TEST_VQSHRUN_HIGH_N1(INSN, T1, T2, W, W2, N, N2, V) \
      56    TEST_VQSHRUN_HIGH_N2(INSN, T1, T2, W, W2, N, N2, V)
      57  
      58  #define TEST_VQSHRUN_HIGH_N(T1, T2, W, W2, N, N2, V) \
      59    TEST_VQSHRUN_HIGH_N1(INSN, T1, T2, W, W2, N, N2, V)
      60  
      61  
      62    DECL_VARIABLE(vector1, uint, 8, 8);
      63    DECL_VARIABLE(vector1, uint, 16, 4);
      64    DECL_VARIABLE(vector1, uint, 32, 2);
      65  
      66    /* vector is twice as large as vector_res.  */
      67    DECL_VARIABLE(vector2, int, 16, 8);
      68    DECL_VARIABLE(vector2, int, 32, 4);
      69    DECL_VARIABLE(vector2, int, 64, 2);
      70  
      71    DECL_VARIABLE(vector_res, uint, 8, 16);
      72    DECL_VARIABLE(vector_res, uint, 16, 8);
      73    DECL_VARIABLE(vector_res, uint, 32, 4);
      74  
      75    clean_results ();
      76  
      77    /* Fill input vector with negative values, to check saturation on
      78       limits.  */
      79    VDUP(vector1, , uint, u, 8, 8, -2);
      80    VDUP(vector1, , uint, u, 16, 4, -3);
      81    VDUP(vector1, , uint, u, 32, 2, -4);
      82  
      83    VDUP(vector2, q, int, s, 16, 8, -2);
      84    VDUP(vector2, q, int, s, 32, 4, -3);
      85    VDUP(vector2, q, int, s, 64, 2, -4);
      86  
      87    /* Choose shift amount arbitrarily.  */
      88  #define CMT " (negative input)"
      89    TEST_VQSHRUN_HIGH_N(int, s, 16, 8, 8, 16, 3);
      90    TEST_VQSHRUN_HIGH_N(int, s, 32, 16, 4, 8, 4);
      91    TEST_VQSHRUN_HIGH_N(int, s, 64, 32, 2, 4, 2);
      92  
      93    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_neg, CMT);
      94    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_neg, CMT);
      95    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_neg, CMT);
      96  
      97  
      98    /* Fill input vector with max value, to check saturation on
      99       limits.  */
     100    VDUP(vector1, , uint, u, 8, 8, 0x7F);
     101    VDUP(vector1, , uint, u, 16, 4, 0x7FFF);
     102    VDUP(vector1, , uint, u, 32, 2, 0x7FFFFFFFLL);
     103  
     104    VDUP(vector2, q, int, s, 16, 8, 0x7FFF);
     105    VDUP(vector2, q, int, s, 32, 4, 0x7FFFFFFF);
     106    VDUP(vector2, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
     107  
     108  #undef CMT
     109  #define CMT " (check cumulative saturation)"
     110    TEST_VQSHRUN_HIGH_N(int, s, 16, 8, 8, 16, 1);
     111    TEST_VQSHRUN_HIGH_N(int, s, 32, 16, 4, 8, 1);
     112    TEST_VQSHRUN_HIGH_N(int, s, 64, 32, 2, 4, 1);
     113  
     114    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_max_sh1, CMT);
     115    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_max_sh1, CMT);
     116    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_max_sh1, CMT);
     117  
     118  
     119    /* Fill input vector with positive values, to check normal case.  */
     120    VDUP(vector1, , uint, u, 8, 8, 0x12);
     121    VDUP(vector1, , uint, u, 16, 4, 0x4321);
     122    VDUP(vector1, , uint, u, 32, 2, 0xDEADBEEF);
     123  
     124    VDUP(vector2, q, int, s, 16, 8, 0x1234);
     125    VDUP(vector2, q, int, s, 32, 4, 0x87654321);
     126    VDUP(vector2, q, int, s, 64, 2, 0xDEADBEEF);
     127  
     128  #undef CMT
     129  #define CMT ""
     130    TEST_VQSHRUN_HIGH_N(int, s, 16, 8, 8, 16, 6);
     131    TEST_VQSHRUN_HIGH_N(int, s, 32, 16, 4, 8, 7);
     132    TEST_VQSHRUN_HIGH_N(int, s, 64, 32, 2, 4, 8);
     133  
     134    CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected, CMT);
     135    CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected, CMT);
     136    CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected, CMT);
     137  }
     138  
     139  int main (void)
     140  {
     141    exec_vqshrun_high_n ();
     142    return 0;
     143  }