(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
advsimd-intrinsics/
vqrdmulh_lane.c
       1  #include <arm_neon.h>
       2  #include "arm-neon-ref.h"
       3  #include "compute-ref-data.h"
       4  
       5  /* Expected results.  */
       6  VECT_VAR_DECL(expected,int,16,4) [] = { 0x0, 0x0, 0x0, 0x0 };
       7  VECT_VAR_DECL(expected,int,32,2) [] = { 0x0, 0x0 };
       8  VECT_VAR_DECL(expected,int,16,8) [] = { 0x0, 0x0, 0x0, 0x0,
       9  					0x0, 0x0, 0x0, 0x0 };
      10  VECT_VAR_DECL(expected,int,32,4) [] = { 0x0, 0x0, 0x0, 0x0 };
      11  
      12  /* Expected results when multiplication saturates.  */
      13  VECT_VAR_DECL(expected_mul,int,16,4) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff };
      14  VECT_VAR_DECL(expected_mul,int,32,2) [] = { 0x7fffffff, 0x7fffffff };
      15  VECT_VAR_DECL(expected_mul,int,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      16  					    0x7fff, 0x7fff, 0x7fff, 0x7fff };
      17  VECT_VAR_DECL(expected_mul,int,32,4) [] = { 0x7fffffff, 0x7fffffff,
      18  					    0x7fffffff, 0x7fffffff };
      19  
      20  /* Expected results when rounding should not cause saturation.  */
      21  VECT_VAR_DECL(expected_round,int,16,4) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff };
      22  VECT_VAR_DECL(expected_round,int,32,2) [] = { 0x7fffffff, 0x7fffffff };
      23  VECT_VAR_DECL(expected_round,int,16,8) [] = { 0x7fff, 0x7fff, 0x7fff, 0x7fff,
      24  					      0x7fff, 0x7fff, 0x7fff, 0x7fff };
      25  VECT_VAR_DECL(expected_round,int,32,4) [] = { 0x7fffffff, 0x7fffffff,
      26  					      0x7fffffff, 0x7fffffff };
      27  
      28  #define INSN vqrdmulh
      29  #define TEST_MSG "VQRDMULH_LANE"
      30  
      31  #define FNNAME1(NAME) void exec_ ## NAME ## _lane (void)
      32  #define FNNAME(NAME) FNNAME1(NAME)
      33  
      34  FNNAME (INSN)
      35  {
      36    /* vector_res = vqrdmulh_lane(vector,vector2,lane), then store the result.  */
      37  #define TEST_VQRDMULH_LANE2(INSN, Q, T1, T2, W, N, N2, L, CMT) \
      38    Set_Neon_Cumulative_Sat(0, VECT_VAR(vector_res, T1, W, N));		\
      39    VECT_VAR(vector_res, T1, W, N) =					\
      40      INSN##Q##_lane_##T2##W(VECT_VAR(vector, T1, W, N),			\
      41  			   VECT_VAR(vector2, T1, W, N2),		\
      42  			   L);						\
      43    vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N),				\
      44  		    VECT_VAR(vector_res, T1, W, N))
      45  
      46    /* Two auxliary macros are necessary to expand INSN */
      47  #define TEST_VQRDMULH_LANE1(INSN, Q, T1, T2, W, N, N2, L, CMT) \
      48    TEST_VQRDMULH_LANE2(INSN, Q, T1, T2, W, N, N2, L, CMT)
      49  
      50  #define TEST_VQRDMULH_LANE(Q, T1, T2, W, N, N2, L, CMT) \
      51    TEST_VQRDMULH_LANE1(INSN, Q, T1, T2, W, N, N2, L, CMT)
      52  
      53  
      54    DECL_VARIABLE(vector, int, 16, 4);
      55    DECL_VARIABLE(vector, int, 32, 2);
      56    DECL_VARIABLE(vector, int, 16, 8);
      57    DECL_VARIABLE(vector, int, 32, 4);
      58  
      59    DECL_VARIABLE(vector_res, int, 16, 4);
      60    DECL_VARIABLE(vector_res, int, 32, 2);
      61    DECL_VARIABLE(vector_res, int, 16, 8);
      62    DECL_VARIABLE(vector_res, int, 32, 4);
      63  
      64    /* vector2: vqrdmulh_lane and vqrdmulhq_lane have a 2nd argument with
      65       the same number of elements, so we need only one variable of each
      66       type.  */
      67    DECL_VARIABLE(vector2, int, 16, 4);
      68    DECL_VARIABLE(vector2, int, 32, 2);
      69  
      70    clean_results ();
      71  
      72    VLOAD(vector, buffer, , int, s, 16, 4);
      73    VLOAD(vector, buffer, , int, s, 32, 2);
      74  
      75    VLOAD(vector, buffer, q, int, s, 16, 8);
      76    VLOAD(vector, buffer, q, int, s, 32, 4);
      77  
      78    /* Initialize vector2.  */
      79    VDUP(vector2, , int, s, 16, 4, 0x55);
      80    VDUP(vector2, , int, s, 32, 2, 0xBB);
      81  
      82    /* Choose lane arbitrarily.  */
      83  #define CMT ""
      84    TEST_VQRDMULH_LANE(, int, s, 16, 4, 4, 2, CMT);
      85    TEST_VQRDMULH_LANE(, int, s, 32, 2, 2, 1, CMT);
      86    TEST_VQRDMULH_LANE(q, int, s, 16, 8, 4, 3, CMT);
      87    TEST_VQRDMULH_LANE(q, int, s, 32, 4, 2, 0, CMT);
      88  
      89    CHECK(TEST_MSG, int, 16, 4, PRIx16, expected, CMT);
      90    CHECK(TEST_MSG, int, 32, 2, PRIx32, expected, CMT);
      91    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected, CMT);
      92    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected, CMT);
      93  
      94    /* Now use input values such that the multiplication causes
      95       saturation.  */
      96  #define TEST_MSG_MUL " (check mul cumulative saturation)"
      97    VDUP(vector, , int, s, 16, 4, 0x8000);
      98    VDUP(vector, , int, s, 32, 2, 0x80000000);
      99    VDUP(vector, q, int, s, 16, 8, 0x8000);
     100    VDUP(vector, q, int, s, 32, 4, 0x80000000);
     101    VDUP(vector2, , int, s, 16, 4, 0x8000);
     102    VDUP(vector2, , int, s, 32, 2, 0x80000000);
     103  
     104    TEST_VQRDMULH_LANE(, int, s, 16, 4, 4, 2, TEST_MSG_MUL);
     105    TEST_VQRDMULH_LANE(, int, s, 32, 2, 2, 1, TEST_MSG_MUL);
     106    TEST_VQRDMULH_LANE(q, int, s, 16, 8, 4, 3, TEST_MSG_MUL);
     107    TEST_VQRDMULH_LANE(q, int, s, 32, 4, 2, 0, TEST_MSG_MUL);
     108  
     109    CHECK(TEST_MSG, int, 16, 4, PRIx16, expected_mul, TEST_MSG_MUL);
     110    CHECK(TEST_MSG, int, 32, 2, PRIx32, expected_mul, TEST_MSG_MUL);
     111    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected_mul, TEST_MSG_MUL);
     112    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected_mul, TEST_MSG_MUL);
     113  
     114    VDUP(vector, , int, s, 16, 4, 0x8000);
     115    VDUP(vector, , int, s, 32, 2, 0x80000000);
     116    VDUP(vector, q, int, s, 16, 8, 0x8000);
     117    VDUP(vector, q, int, s, 32, 4, 0x80000000);
     118    VDUP(vector2, , int, s, 16, 4, 0x8001);
     119    VDUP(vector2, , int, s, 32, 2, 0x80000001);
     120  
     121    /* Use input values where rounding produces a result equal to the
     122       saturation value, but does not set the saturation flag.  */
     123  #define TEST_MSG_ROUND " (check rounding)"
     124    TEST_VQRDMULH_LANE(, int, s, 16, 4, 4, 2, TEST_MSG_ROUND);
     125    TEST_VQRDMULH_LANE(, int, s, 32, 2, 2, 1, TEST_MSG_ROUND);
     126    TEST_VQRDMULH_LANE(q, int, s, 16, 8, 4, 3, TEST_MSG_ROUND);
     127    TEST_VQRDMULH_LANE(q, int, s, 32, 4, 2, 0, TEST_MSG_ROUND);
     128  
     129    CHECK(TEST_MSG, int, 16, 4, PRIx16, expected_round, TEST_MSG_ROUND);
     130    CHECK(TEST_MSG, int, 32, 2, PRIx32, expected_round, TEST_MSG_ROUND);
     131    CHECK(TEST_MSG, int, 16, 8, PRIx16, expected_round, TEST_MSG_ROUND);
     132    CHECK(TEST_MSG, int, 32, 4, PRIx32, expected_round, TEST_MSG_ROUND);
     133  }
     134  
     135  int main (void)
     136  {
     137    exec_vqrdmulh_lane ();
     138    return 0;
     139  }
     140