// File: kernel.cpp
#include "loop_010.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_010(struct loop_010_data * data)

{
  float *a = data->a;
  uint64_t n = data->n;

  int any = 0;
  int all = 1;
  svint32_t any_vec = svdup_s32(0);
  svint32_t all_vec = svdup_s32(1);

  svbool_t p0;
  FOR_LOOP_32(uint64_t, i, 0, n, p0) {
    svfloat32_t a_vec = svld1(p0, &a[i]);
    svbool_t p1 = svcmplt(p0, a_vec, 0.0f);
    any = svclastb(p1, any, all_vec);
    svbool_t p2 = svnot_z(p0, p1);
    all = svclastb(p2, all, any_vec);
  }

  data->res = all ? 1 : any ? 2 : 3;
}