// Copyright 2020 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.

$assert BATCH_TILE % 8 == 0
$assert BATCH_TILE >= 8
$ABC = "01234567456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$assert OP in ["ADD", "DIV", "RDIV", "MAX", "MIN", "MUL", "SUB", "RSUB", "SQRDIFF"]
$assert ACTIVATION in ["LINEAR", "MINMAX"]
#include <assert.h>

#include <arm_neon.h>

#include <xnnpack/common.h>
#include <xnnpack/vbinary.h>


$VOPQ_f16 = {
$  "ADD": lambda x: "vaddq_f16(%s, vb)" % x,
$  "DIV": lambda x: "vdivq_f16(%s, vb)" % x,
$  "RDIV": lambda x: "vdivq_f16(vb, %s)" % x,
$  "MAX": lambda x: "vmaxq_f16(%s, vb)" % x,
$  "MIN": lambda x: "vminq_f16(%s, vb)" % x,
$  "MUL": lambda x: "vmulq_f16(%s, vb)" % x,
$  "SUB": lambda x: "vsubq_f16(%s, vb)" % x,
$  "RSUB": lambda x: "vsubq_f16(vb, %s)" % x,
$  "SQRDIFF": lambda x: "vsubq_f16(%s, vb)" % x,
$}[OP]
$SUFFIX = {"LINEAR": "", "MINMAX": "_minmax"}[ACTIVATION]
$PARAMS = {"LINEAR": "xnn_f16_default_params", "MINMAX": "xnn_f16_minmax_params"}[ACTIVATION]
void xnn_f16_v${OP.lower()}c${SUFFIX}_ukernel__neonfp16arith_x${BATCH_TILE}(
    size_t n,
    const void* restrict a_ptr,
    const void* restrict b_ptr,
    void* restrict y_ptr,
    const union ${PARAMS} params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
{
  assert(n != 0);
  assert(n % sizeof(__fp16) == 0);
  assert(a_ptr != NULL);
  assert(b_ptr != NULL);
  assert(y_ptr != NULL);

  const __fp16* a = (const __fp16*) a_ptr;
  const __fp16* b = (const __fp16*) b_ptr;
  __fp16* y = (__fp16*) y_ptr;

  $if ACTIVATION == "MINMAX":
    const float16x8_t vy_min = vreinterpretq_f16_u16(vld1q_dup_u16(&params->neon.min));
    const float16x8_t vy_max = vreinterpretq_f16_u16(vld1q_dup_u16(&params->neon.max));

  const float16x8_t vb = vld1q_dup_f16(b);
  $if BATCH_TILE > 8:
    for (; n >= ${BATCH_TILE} * sizeof(__fp16); n -= ${BATCH_TILE} * sizeof(__fp16)) {
      $for N in range(0, BATCH_TILE, 8):
        const float16x8_t va${ABC[N:N+8]} = vld1q_f16(a); a += 8;

      $for N in range(0, BATCH_TILE, 8):
        float16x8_t vy${ABC[N:N+8]} = ${VOPQ_f16("va" + ABC[N:N+8])};

      $if OP == "SQRDIFF":
        $for N in range(0, BATCH_TILE, 8):
          vy${ABC[N:N+8]} = vmulq_f16(vy${ABC[N:N+8]}, vy${ABC[N:N+8]});

      $if ACTIVATION == "MINMAX":
        $for N in range(0, BATCH_TILE, 8):
          vy${ABC[N:N+8]} = vmaxq_f16(vy${ABC[N:N+8]}, vy_min);

        $for N in range(0, BATCH_TILE, 8):
          vy${ABC[N:N+8]} = vminq_f16(vy${ABC[N:N+8]}, vy_max);

      $for N in range(0, BATCH_TILE, 8):
        vst1q_f16(y, vy${ABC[N:N+8]}); y += 8;
    }
  for (; n >= 8 * sizeof(__fp16); n -= 8 * sizeof(__fp16)) {
    const float16x8_t va01234567 = vld1q_f16(a); a += 8;

    float16x8_t vy01234567 = ${VOPQ_f16("va01234567")};
    $if OP == "SQRDIFF":
      vy01234567 = vmulq_f16(vy01234567, vy01234567);
    $if ACTIVATION == "MINMAX":
      vy01234567 = vmaxq_f16(vy01234567, vy_min);
      vy01234567 = vminq_f16(vy01234567, vy_max);
    vst1q_f16(y, vy01234567); y += 8;
  }
  if XNN_UNLIKELY(n != 0) {
    const float16x8_t va01234567 = vld1q_f16(a);

    float16x8_t vy01234567 = ${VOPQ_f16("va01234567")};
    $if OP == "SQRDIFF":
      vy01234567 = vmulq_f16(vy01234567, vy01234567);
    $if ACTIVATION == "MINMAX":
      vy01234567 = vmaxq_f16(vy01234567, vy_min);
      vy01234567 = vminq_f16(vy01234567, vy_max);

    float16x4_t vy0123 = vget_low_f16(vy01234567);
    if (n & (4 * sizeof(__fp16))) {
      vst1_f16(y, vy0123); y += 4;
      vy0123 = vget_high_f16(vy01234567);
    }

    if (n & (2 * sizeof(__fp16))) {
      vst1_lane_u32((void*) y, vreinterpret_u32_f16(vy0123), 0); y += 2;
      vy0123 = vext_f16(vy0123, vy0123, 2);
    }

    if (n & (1 * sizeof(__fp16))) {
      vst1_lane_f16(y, vy0123, 0);
    }
  }
}
