1  /* { dg-do run } */
       2  /* { dg-options "-O2 -mavxvnniint8" } */
       3  /* { dg-require-effective-target avxvnniint8 } */
       4  
       5  #define AVXVNNIINT8
       6  #ifndef CHECK
       7  #define CHECK "avx-check.h"
       8  #endif
       9  
      10  #ifndef TEST
      11  #define TEST avx_test
      12  #endif
      13  
      14  #include CHECK
      15  #include "vnniint8-auto-vectorize-1.c"
      16  
      17  #define N 256
      18  char a_i8[N], b_i8[N];
      19  unsigned char c_u8[N], d_u8[N];
      20  int i8_exp, i8_ref;
      21  
      22  int __attribute__((noipa, optimize("no-tree-vectorize")))
      23  sdot_prod_qi_scalar (char * restrict a, char * restrict b,
      24  		     int c, int n)
      25  {
      26    int i;
      27    for (i = 0; i < n; i++)
      28      {
      29        c += ((int) a[i] * (int) b[i]);
      30      }
      31    return c;
      32  }
      33  
      34  int __attribute__((noipa, optimize("no-tree-vectorize")))
      35  udot_prod_qi_scalar (unsigned char * restrict a, unsigned char *restrict b,
      36  		     int c, int n)
      37  {
      38    int i;
      39    for (i = 0; i < n; i++)
      40      {
      41        c += ((int) a[i] * (int) b[i]);
      42      }
      43    return c;
      44  }
      45  
      46  void init ()
      47  {
      48    int i;
      49  
      50    i8_exp = i8_ref = 127;
      51  
      52    for (i = 0; i < N; i++)
      53      {
      54        a_i8[i] = (-i + 4) % 128;
      55        b_i8[i] = (i + 1) % 128;
      56        c_u8[i] = (i + 3) % 256;
      57        d_u8[i] = (i + 5) % 256;
      58      }
      59  }
      60  
      61  void
      62  TEST (void)
      63  {
      64    init ();
      65    i8_exp = sdot_prod_qi (a_i8, b_i8, i8_exp, N);
      66    i8_ref = sdot_prod_qi_scalar (a_i8, b_i8, i8_ref, N);
      67    if (i8_exp != i8_ref)
      68      abort ();
      69  
      70    init ();
      71    i8_exp = udot_prod_qi (c_u8, d_u8, i8_exp, N);
      72    i8_ref = udot_prod_qi_scalar (c_u8, d_u8, i8_ref, N);
      73    if (i8_exp != i8_ref)
      74      abort ();
      75  }