(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
x86_64/
abi/
avx512fp16/
m256h/
test_varargs-m256.c
       1  /* Test variable number of 256-bit vector arguments passed to functions.  */
       2  
       3  #include <stdio.h>
       4  #include "avx512fp16-ymm-check.h"
       5  #include "args.h"
       6  
       7  struct IntegerRegisters iregs;
       8  struct FloatRegisters fregs;
       9  
      10  /* This struct holds values for argument checking.  */
      11  struct 
      12  {
      13    YMM_T i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
      14  } values;
      15  
      16  char *pass;
      17  int failed = 0;
      18  
      19  #undef assert
      20  #define assert(c) do { \
      21    if (!(c)) {failed++; printf ("failed %s\n", pass); } \
      22  } while (0)
      23  
      24  #define compare(X1,X2,T) do { \
      25    assert (memcmp (&X1, &X2, sizeof (T)) == 0); \
      26  } while (0)
      27  
      28  void
      29  fun_check_passing_m256_varargs (__m256 i0, __m256 i1, __m256 i2,
      30  				__m256 i3, ...)
      31  {
      32    /* Check argument values.  */
      33    void **fp = __builtin_frame_address (0);
      34    void *ra = __builtin_return_address (0);
      35    __m256 *argp;
      36  
      37    compare (values.i0, i0, __m256);
      38    compare (values.i1, i1, __m256);
      39    compare (values.i2, i2, __m256);
      40    compare (values.i3, i3, __m256);
      41  
      42    /* Get the pointer to the return address on stack.  */
      43    while (*fp != ra)
      44      fp++;
      45  
      46    /* Skip the return address stack slot.  */
      47    argp = (__m256 *)(((char *) fp) + 8);
      48  
      49    /* Check __m256 arguments passed on stack.  */
      50    compare (values.i4, argp[0], __m256);
      51    compare (values.i5, argp[1], __m256);
      52    compare (values.i6, argp[2], __m256);
      53    compare (values.i7, argp[3], __m256);
      54    compare (values.i8, argp[4], __m256);
      55    compare (values.i9, argp[5], __m256);
      56  
      57    /* Check register contents.  */
      58    compare (fregs.ymm0, ymm_regs[0], __m256);
      59    compare (fregs.ymm1, ymm_regs[1], __m256);
      60    compare (fregs.ymm2, ymm_regs[2], __m256);
      61    compare (fregs.ymm3, ymm_regs[3], __m256);
      62  }
      63  
      64  void
      65  fun_check_passing_m256h_varargs (__m256h i0, __m256h i1, __m256h i2,
      66  				 __m256h i3, ...)
      67  {
      68    /* Check argument values.  */
      69    void **fp = __builtin_frame_address (0);
      70    void *ra = __builtin_return_address (0);
      71    __m256h *argp;
      72  
      73    compare (values.i0, i0, __m256h);
      74    compare (values.i1, i1, __m256h);
      75    compare (values.i2, i2, __m256h);
      76    compare (values.i3, i3, __m256h);
      77  
      78    /* Get the pointer to the return address on stack.  */
      79    while (*fp != ra)
      80      fp++;
      81  
      82    /* Skip the return address stack slot.  */
      83    argp = (__m256h *)(((char *) fp) + 8);
      84  
      85    /* Check __m256h arguments passed on stack.  */
      86    compare (values.i4, argp[0], __m256h);
      87    compare (values.i5, argp[1], __m256h);
      88    compare (values.i6, argp[2], __m256h);
      89    compare (values.i7, argp[3], __m256h);
      90    compare (values.i8, argp[4], __m256h);
      91    compare (values.i9, argp[5], __m256h);
      92  
      93    /* Check register contents.  */
      94    compare (fregs.ymm0, ymm_regs[0], __m256h);
      95    compare (fregs.ymm1, ymm_regs[1], __m256h);
      96    compare (fregs.ymm2, ymm_regs[2], __m256h);
      97    compare (fregs.ymm3, ymm_regs[3], __m256h);
      98  }
      99  
     100  #define def_check_int_passing_varargs(_i0, _i1, _i2, _i3, _i4, _i5, \
     101  				      _i6, _i7, _i8, _i9, \
     102  				      _func, TYPE) \
     103    values.i0.TYPE[0] = _i0; \
     104    values.i1.TYPE[0] = _i1; \
     105    values.i2.TYPE[0] = _i2; \
     106    values.i3.TYPE[0] = _i3; \
     107    values.i4.TYPE[0] = _i4; \
     108    values.i5.TYPE[0] = _i5; \
     109    values.i6.TYPE[0] = _i6; \
     110    values.i7.TYPE[0] = _i7; \
     111    values.i8.TYPE[0] = _i8; \
     112    values.i9.TYPE[0] = _i9; \
     113    clear_struct_registers; \
     114    fregs.F0.TYPE[0] = _i0; \
     115    fregs.F1.TYPE[0] = _i1; \
     116    fregs.F2.TYPE[0] = _i2; \
     117    fregs.F3.TYPE[0] = _i3; \
     118    WRAP_CALL(_func) (_i0, _i1, _i2, _i3, _i4, _i5, _i6, _i7, _i8, _i9);
     119  
     120  void
     121  test_m256_varargs (void)
     122  {
     123    __m256 x[10];
     124    int i;
     125    for (i = 0; i < 10; i++)
     126      x[i] = (__m256){32+i, 0, 0, 0, 0, 0, 0, 0};
     127    pass = "m256-varargs";
     128    def_check_int_passing_varargs (x[0], x[1], x[2], x[3], x[4], x[5],
     129  				 x[6], x[7], x[8], x[9],
     130  				 fun_check_passing_m256_varargs,
     131  				 _m256);
     132  }
     133  
     134  void
     135  test_m256h_varargs (void)
     136  {
     137    __m256h x[10];
     138    int i;
     139    for (i = 0; i < 10; i++)
     140      x[i] = (__m256h) {
     141          1.1f16 + i, 2.2f16 + i, 3.3f16 + i, 4.4f16 + i,
     142  	5.5f16 + i, 6.6f16 + i, 7.7f16 + i, 8.8f16 + i,
     143  	9.9f16 + i, 10.10f16 + i, 11.11f16 + i, 12.12f16 + i,
     144  	13.13f16 + i, 14.14f16 + i, 15.15f16 + i, 16.16f16 + i
     145      };
     146    pass = "m256h-varargs";
     147    def_check_int_passing_varargs (x[0], x[1], x[2], x[3], x[4], x[5],
     148  				 x[6], x[7], x[8], x[9],
     149  				 fun_check_passing_m256h_varargs,
     150  				 _m256h);
     151  }
     152  
     153  void
     154  do_test (void)
     155  {
     156    test_m256_varargs ();
     157    test_m256h_varargs ();
     158    if (failed)
     159      abort ();
     160  }