(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
advsimd-intrinsics/
vget_lane.c
       1  #include <arm_neon.h>
       2  #include "arm-neon-ref.h"
       3  #include "compute-ref-data.h"
       4  
       5  /* Expected results.  */
       6  int8_t     expected_s8   = 0xf7;
       7  int16_t    expected_s16  = 0xfff3;
       8  int32_t    expected_s32  = 0xfffffff1;
       9  int64_t    expected_s64  = 0xfffffffffffffff0;
      10  uint8_t    expected_u8   = 0xf6;
      11  uint16_t   expected_u16  = 0xfff2;
      12  uint32_t   expected_u32  = 0xfffffff1;
      13  uint64_t   expected_u64  = 0xfffffffffffffff0;
      14  poly8_t    expected_p8   = 0xf6;
      15  poly16_t   expected_p16  = 0xfff2;
      16  hfloat16_t expected_f16  = 0xcb80;
      17  hfloat32_t expected_f32  = 0xc1700000;
      18  
      19  int8_t     expectedq_s8  = 0xff;
      20  int16_t    expectedq_s16 = 0xfff5;
      21  int32_t    expectedq_s32 = 0xfffffff3;
      22  int64_t    expectedq_s64 = 0xfffffffffffffff1;
      23  uint8_t    expectedq_u8  = 0xfe;
      24  uint16_t   expectedq_u16 = 0xfff6;
      25  uint32_t   expectedq_u32 = 0xfffffff2;
      26  uint64_t   expectedq_u64 = 0xfffffffffffffff1;
      27  poly8_t    expectedq_p8  = 0xfe;
      28  poly16_t   expectedq_p16 = 0xfff6;
      29  hfloat16_t expectedq_f16 = 0xca80;
      30  hfloat32_t expectedq_f32 = 0xc1500000;
      31  
      32  int error_found = 0;
      33  
      34  #define TEST_MSG "VGET_LANE"
      35  void exec_vget_lane (void)
      36  {
      37    /* vec=vget_lane(vec, lane), then store the result.  */
      38  #define TEST_VGET_LANE(Q, T1, T2, W, N, L)				   \
      39    VAR(var, T1, W) = vget##Q##_lane_##T2##W(VECT_VAR(vector, T1, W, N), L); \
      40    if (VAR(var, T1, W) != expected##Q##_##T2##W) {			   \
      41      fprintf(stderr,							   \
      42  	    "ERROR in %s (%s line %d in result '%s') at type %s "	   \
      43  	    "got 0x%" PRIx##W " != 0x%" PRIx##W "\n",			   \
      44  	    TEST_MSG, __FILE__, __LINE__,				   \
      45  	    STR(expected##Q##_##T2##W),					   \
      46  	    STR(VECT_NAME(T1, W, N)),					   \
      47  	    VAR(var, T1, W),						   \
      48  	    expected##Q##_##T2##W);					   \
      49      error_found = 1;							   \
      50    }
      51  
      52    /* Special variant for floating-point.  */
      53    union {
      54      uint32_t var_int32;
      55      float32_t var_float32;
      56    } var_int32_float32;
      57  #if defined (__ARM_FP16_FORMAT_IEEE) || defined (__ARM_FP16_FORMAT_ALTERNATIVE)
      58    union {
      59      uint16_t var_int16;
      60      float16_t var_float16;
      61    } var_int16_float16;
      62  #endif
      63  
      64  #define TEST_VGET_LANE_FP(Q, T1, T2, W, N, L)				   \
      65    VAR(var, T1, W) = vget##Q##_lane_##T2##W(VECT_VAR(vector, T1, W, N), L); \
      66    var_int##W##_float##W.var_float##W = VAR(var, T1, W);			   \
      67    if (var_int##W##_float##W.var_int##W != expected##Q##_##T2##W) {	   \
      68      fprintf(stderr,							   \
      69  	    "ERROR in %s (%s line %d in result '%s') at type %s "	   \
      70  	    "got 0x%" PRIx##W " != 0x%" PRIx##W "\n",			   \
      71  	    TEST_MSG, __FILE__, __LINE__,				   \
      72  	    STR(expected##Q##_##T2##W),					   \
      73  	    STR(VECT_NAME(T1, W, N)),					   \
      74  	    var_int##W##_float##W.var_int##W,				   \
      75  	    expected##Q##_##T2##W);					   \
      76      error_found = 1;							   \
      77    }
      78  
      79    DECL_VARIABLE_ALL_VARIANTS(vector);
      80  
      81    /* Scalar variables.  */
      82    VAR_DECL(var, int, 8);
      83    VAR_DECL(var, int, 16);
      84    VAR_DECL(var, int, 32);
      85    VAR_DECL(var, int, 64);
      86    VAR_DECL(var, uint, 8);
      87    VAR_DECL(var, uint, 16);
      88    VAR_DECL(var, uint, 32);
      89    VAR_DECL(var, uint, 64);
      90    VAR_DECL(var, poly, 8);
      91    VAR_DECL(var, poly, 16);
      92  #if defined (__ARM_FP16_FORMAT_IEEE) || defined (__ARM_FP16_FORMAT_ALTERNATIVE)
      93    VAR_DECL(var, float, 16);
      94  #endif
      95    VAR_DECL(var, float, 32);
      96  
      97    /* Initialize input values.  */
      98    TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
      99  #if defined (__ARM_FP16_FORMAT_IEEE) || defined (__ARM_FP16_FORMAT_ALTERNATIVE)
     100    VLOAD(vector, buffer, , float, f, 16, 4);
     101    VLOAD(vector, buffer, q, float, f, 16, 8);
     102  #endif
     103    VLOAD(vector, buffer, , float, f, 32, 2);
     104    VLOAD(vector, buffer, q, float, f, 32, 4);
     105  
     106    /* Choose lane arbitrarily.  */
     107    TEST_VGET_LANE(, int, s, 8, 8, 7);
     108    TEST_VGET_LANE(, int, s, 16, 4, 3);
     109    TEST_VGET_LANE(, int, s, 32, 2, 1);
     110    TEST_VGET_LANE(, int, s, 64, 1, 0);
     111    TEST_VGET_LANE(, uint, u, 8, 8, 6);
     112    TEST_VGET_LANE(, uint, u, 16, 4, 2);
     113    TEST_VGET_LANE(, uint, u, 32, 2, 1);
     114    TEST_VGET_LANE(, uint, u, 64, 1, 0);
     115    TEST_VGET_LANE(, poly, p, 8, 8, 6);
     116    TEST_VGET_LANE(, poly, p, 16, 4, 2);
     117  #if defined (__ARM_FP16_FORMAT_IEEE) || defined (__ARM_FP16_FORMAT_ALTERNATIVE)
     118    TEST_VGET_LANE_FP(, float, f, 16, 4, 1);
     119  #endif
     120    TEST_VGET_LANE_FP(, float, f, 32, 2, 1);
     121  
     122    TEST_VGET_LANE(q, int, s, 8, 16, 15);
     123    TEST_VGET_LANE(q, int, s, 16, 8, 5);
     124    TEST_VGET_LANE(q, int, s, 32, 4, 3);
     125    TEST_VGET_LANE(q, int, s, 64, 2, 1);
     126    TEST_VGET_LANE(q, uint, u, 8, 16, 14);
     127    TEST_VGET_LANE(q, uint, u, 16, 8, 6);
     128    TEST_VGET_LANE(q, uint, u, 32, 4, 2);
     129    TEST_VGET_LANE(q, uint, u, 64, 2, 1);
     130    TEST_VGET_LANE(q, poly, p, 8, 16, 14);
     131    TEST_VGET_LANE(q, poly, p, 16, 8, 6);
     132  #if defined (__ARM_FP16_FORMAT_IEEE) || defined (__ARM_FP16_FORMAT_ALTERNATIVE)
     133    TEST_VGET_LANE_FP(q, float, f, 16, 8, 3);
     134  #endif
     135    TEST_VGET_LANE_FP(q, float, f, 32, 4, 3);
     136  }
     137  
     138  int main (void)
     139  {
     140    exec_vget_lane ();
     141  
     142    if (error_found)
     143      abort();
     144  
     145    return 0;
     146  }