// File: kernel.cpp
#include "loop_110.h"
#include <stdint.h>
#include <arm_sve.h>
#define restrict __restrict
#define SC_SVE_ATTR
#define FOR_COND(P, S, I, N) svptest_first(svptrue_b##S(), P = svwhilelt_b##S(I, N))
#define FOR_LOOP(T, I, M, N, P, S, W) for (T I = M; FOR_COND(P, S, I, N); I += svcnt##W())
#define FOR_LOOP_8(T, I, M, N, P)  FOR_LOOP(T, I, M, N, P, 8, b)
#define FOR_LOOP_16(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 16, h)
#define FOR_LOOP_32(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 32, w)
#define FOR_LOOP_64(T, I, M, N, P) FOR_LOOP(T, I, M, N, P, 64, d)
static inline uint32_t get_sve_vl(void) {
  uint64_t vl = 0; asm volatile("incb %[vl], all, mul #8" : [vl] "+r"(vl) : :);
  return (uint32_t)vl;
}
static inline uint32_t get_vl(void) { return get_sve_vl(); }

extern "C" void inner_loop_110(struct loop_110_data * input)

{
  cint8_t *a0 = input->a0;
  cint8_t *b0 = input->b0;
  cint32_t *c0 = input->c0;
  uint64_t size = input->size;

  svbool_t p;
  FOR_LOOP_32(uint64_t, i, 0, size, p) {
    svint8_t a1 = svreinterpret_s8(svld1_s32(p, (int32_t *)(a0 + 2 * i)));
    svint8_t b1 = svreinterpret_s8(svld1_s32(p, (int32_t *)(b0 + 2 * i)));
    svint32_t cr = svcdot(svdup_s32(0), a1, b1, 0);
    svint32_t ci = svcdot(svdup_s32(0), a1, b1, 90);
    svint32x2_t c1 = svcreate2(cr, ci);
    svst2(p, (int32_t *)(c0 + i), c1);
  }
}