// Copyright 2022 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 % 4 == 0
$assert BATCH_TILE >= 4
$SIMD_TILE = BATCH_TILE // 4
#include <assert.h>
#include <stddef.h>
#include <stdint.h>

#include <arm_neon.h>

#include <xnnpack/vsquareabs.h>


void xnn_cs16_vsquareabs_ukernel__neon_mlal_ld128_x${BATCH_TILE}(
    size_t batch,
    const int16_t* input,
    uint32_t* output) {

  assert(batch != 0);
  assert(input != NULL);
  assert(output != NULL);

  $if BATCH_TILE > 4:
    for (; batch >= ${BATCH_TILE}; batch -= ${BATCH_TILE}) {
      $for N in range(SIMD_TILE):
        const int16x4x2_t vi${N} = vld2_s16(input); input += 8;

      $for N in range(SIMD_TILE):
        int32x4_t vacc${N} = vmull_s16(vi${N}.val[0], vi${N}.val[0]);
        vacc${N} = vmlal_s16(vacc${N}, vi${N}.val[1], vi${N}.val[1]);

      $for N in range(SIMD_TILE):
        vst1q_u32(output, vreinterpretq_u32_s32(vacc${N})); output += 4;
    }

  // Remainder of full vectors
  for (; batch >= 4; batch -= 4) {
    const int16x4x2_t vi = vld2_s16(input); input += 8;

    int32x4_t vacc = vmull_s16(vi.val[0], vi.val[0]);

    vacc = vmlal_s16(vacc, vi.val[1], vi.val[1]);

    vst1q_u32(output, vreinterpretq_u32_s32(vacc)); output += 4;
  }

  // Remainder of 1 to 3 elements
  if XNN_UNLIKELY(batch != 0) {
    const int16x4x2_t vi = vld2_s16(input);

    int32x4_t vacc = vmull_s16(vi.val[0], vi.val[0]);
    vacc = vmlal_s16(vacc, vi.val[1], vi.val[1]);

    uint32x2_t vacc_lo = vreinterpret_u32_s32(vget_low_s32(vacc));
    if (batch & 2) {
      vst1_u32(output, vacc_lo); output += 2;
      vacc_lo = vreinterpret_u32_s32(vget_high_s32(vacc));
    }
    if (batch & 1) {
      vst1_lane_u32(output, vacc_lo, 0);
    }
  }
}
