// 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 ROW_TILE >= 1
$assert ACCUMULATORS >= 1
$VMULADDQ_LANE_F32 = "vfmaq_lane_f32" if FMA else "vmlaq_lane_f32"
#include <assert.h>

#include <arm_neon.h>

#include <xnnpack/dwconv.h>
#include <xnnpack/math.h>


void xnn_f32_dwconv2d_chw_ukernel_5x5p2__${"neonfma" if FMA else "neon"}_${ROW_TILE}x4${"_acc%d" % ACCUMULATORS if ACCUMULATORS > 1 else ""}(
    size_t input_height,
    size_t input_width,
    const float* input,
    const float* weights,
    const float* zero,
    float* output,
    uint32_t padding_top,
    const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
{
  assert(input_height != 0);
  assert(input_width != 0);
  assert(input_width % sizeof(float) == 0);
  assert(padding_top == 2);

  const uint32x4_t vmask = vld1q_u32(params->neon.mask);
  const float32x4_t vmax = vld1q_dup_f32(&params->neon.max);
  const float32x4_t vmin = vld1q_dup_f32(&params->neon.min);

  const float32x4_t vw0123 = vld1q_f32(weights);
  const float32x4_t vw4567 = vld1q_f32(weights + 4);
  const float32x4_t vw89AB = vld1q_f32(weights + 8);
  const float32x4_t vwCDEF = vld1q_f32(weights + 12);
  const float32x4_t vwGHIJ = vld1q_f32(weights + 16);
  const float32x4_t vwKLMN = vld1q_f32(weights + 20);
  const float32x2_t vwOP = vld1_f32(weights + 24);

  const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));

  const float* i0 = zero;
  const float* i1 = zero;
  const float* i2 = input;
  $for M in range(3, 4 + ROW_TILE):
    const float* i${M} = (const float*) ((uintptr_t) i${M-1} + input_width);

  float* o0 = output;
  $for M in range(1, ROW_TILE):
    float* o${M} = (float*) ((uintptr_t) o${M-1} + input_width);

  size_t output_height = input_height;
  do {
    $for M in range(2, 3 + ROW_TILE):
      if XNN_UNPREDICTABLE(output_height < ${M}) {
        i${M+1} = zero;
        $if M <= ROW_TILE:
          o${M-1} = o${M-2};
      }

    $for M in range(4 + ROW_TILE):
      float32x4_t vi${M}x0123 = vmovq_n_f32(0.0f);

    $for M in range(4 + ROW_TILE):
      float32x4_t vi${M}x4567 = vld1q_f32(i${M}); i${M} += 4;

    size_t w = input_width;
    for (; w > 8 * sizeof(float); w -= 4 * sizeof(float)) {
      $for M in range(ROW_TILE):
        float32x4_t vo${M}p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x89AB = vld1q_f32(i${M}); i${M} += 4;

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 1:
          float32x4_t vo${M}p1 = vmulq_lane_f32(vi${M}x4567, vget_high_f32(vw0123), 1);
        $else:
          vo${M}p0 = ${VMULADDQ_LANE_F32}(vo${M}p0, vi${M}x4567, vget_high_f32(vw0123), 1);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 2:
          float32x4_t vo${M}p2 = vmulq_lane_f32(vi${M+1}x4567, vget_low_f32(vw89AB), 0);
        $else:
          vo${M}p0 = ${VMULADDQ_LANE_F32}(vo${M}p0, vi${M+1}x4567, vget_low_f32(vw89AB), 0);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 3:
          float32x4_t vo${M}p3 = vmulq_lane_f32(vi${M+2}x4567, vget_low_f32(vwCDEF), 1);
        $else:
          vo${M}p${4 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${4 % ACCUMULATORS}, vi${M+2}x4567, vget_low_f32(vwCDEF), 1);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 4:
          float32x4_t vo${M}p4 = vmulq_lane_f32(vi${M+3}x4567, vget_high_f32(vwGHIJ), 0);
        $else:
          vo${M}p${5 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${5 % ACCUMULATORS}, vi${M+3}x4567, vget_high_f32(vwGHIJ), 0);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 6:
          float32x4_t vo${M}p5 = vmulq_lane_f32(vi${M+4}x4567, vget_high_f32(vwKLMN), 1);
        $else:
          vo${M}p${6 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${6 % ACCUMULATORS}, vi${M+4}x4567, vget_high_f32(vwKLMN), 1);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x3456 = vextq_f32(vi${M}x0123, vi${M}x4567, 3);

      $for M in range(ROW_TILE):
        vo${M}p${7 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${7 % ACCUMULATORS}, vi${M}x3456, vget_high_f32(vw0123), 0);

      $for M in range(ROW_TILE):
        vo${M}p${8 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${8 % ACCUMULATORS}, vi${M+1}x3456, vget_high_f32(vw4567), 1);

      $for M in range(ROW_TILE):
        vo${M}p${9 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${9 % ACCUMULATORS}, vi${M+2}x3456, vget_low_f32(vwCDEF), 0);

      $for M in range(ROW_TILE):
        vo${M}p${10 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${10 % ACCUMULATORS}, vi${M+3}x3456, vget_low_f32(vwGHIJ), 1);

      $for M in range(ROW_TILE):
        vo${M}p${11 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${11 % ACCUMULATORS}, vi${M+4}x3456, vget_high_f32(vwKLMN), 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x2345 = vextq_f32(vi${M}x0123, vi${M}x4567, 2);
        vi${M}x0123 = vi${M}x4567;

      $for M in range(ROW_TILE):
        vo${M}p${12 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${12 % ACCUMULATORS}, vi${M}x2345, vget_low_f32(vw0123), 1);

      $for M in range(ROW_TILE):
        vo${M}p${13 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${13 % ACCUMULATORS}, vi${M+1}x2345, vget_high_f32(vw4567), 0);

      $for M in range(ROW_TILE):
        vo${M}p${14 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${14 % ACCUMULATORS}, vi${M+2}x2345, vget_high_f32(vw89AB), 1);

      $for M in range(ROW_TILE):
        vo${M}p${15 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${15 % ACCUMULATORS}, vi${M+3}x2345, vget_low_f32(vwGHIJ), 0);

      $for M in range(ROW_TILE):
        vo${M}p${16 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${16 % ACCUMULATORS}, vi${M+4}x2345, vget_low_f32(vwKLMN), 1);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x5678 = vextq_f32(vi${M}x4567, vi${M}x89AB, 1);

      $for M in range(ROW_TILE):
        vo${M}p${17 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${17 % ACCUMULATORS}, vi${M}x5678, vget_low_f32(vw4567), 0);

      $for M in range(ROW_TILE):
        vo${M}p${18 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${18 % ACCUMULATORS}, vi${M+1}x5678, vget_low_f32(vw89AB), 1);

      $for M in range(ROW_TILE):
        vo${M}p${19 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${19 % ACCUMULATORS}, vi${M+2}x5678, vget_high_f32(vwCDEF), 0);

      $for M in range(ROW_TILE):
        vo${M}p${20 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${20 % ACCUMULATORS}, vi${M+3}x5678, vget_high_f32(vwGHIJ), 1);

      $for M in range(ROW_TILE):
        vo${M}p${21 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${21 % ACCUMULATORS}, vi${M+4}x5678, vwOP, 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x6789 = vextq_f32(vi${M}x4567, vi${M}x89AB, 2);
        vi${M}x4567 = vi${M}x89AB;

      $for M in range(ROW_TILE):
        vo${M}p${22 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${22 % ACCUMULATORS}, vi${M}x6789, vget_low_f32(vw4567), 1);

      $for M in range(ROW_TILE):
        vo${M}p${23 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${23 % ACCUMULATORS}, vi${M+1}x6789, vget_high_f32(vw89AB), 0);

      $for M in range(ROW_TILE):
        vo${M}p${24 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${24 % ACCUMULATORS}, vi${M+2}x6789, vget_high_f32(vwCDEF), 1);

      $for M in range(ROW_TILE):
        vo${M}p${25 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${25 % ACCUMULATORS}, vi${M+3}x6789, vget_low_f32(vwKLMN), 0);

      $for M in range(ROW_TILE):
        vo${M}p${26 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${26 % ACCUMULATORS}, vi${M+4}x6789, vwOP, 1);

      $if ACCUMULATORS > 1:
        $ACC_SLICE = 1
        $while ACC_SLICE < ACCUMULATORS:
          $for A in range(0, ACCUMULATORS, ACC_SLICE * 2):
            $if A + ACC_SLICE < ACCUMULATORS:
              $for M in range(ROW_TILE):
                vo${M}p${A} = vaddq_f32(vo${M}p${A}, vo${M}p${A + ACC_SLICE});
          $ACC_SLICE *= 2

      $for M in range(ROW_TILE):
        float32x4_t vo${M} = vmaxq_f32(vo${M}p0, vmin);

      $for M in range(ROW_TILE):
        vo${M} = vminq_f32(vo${M}, vmax);

      $for M in reversed(range(ROW_TILE)):
        vst1q_f32(o${M}, vo${M}); o${M} += 4;
    }
    // Always process the last block of 5..8 pixels.
    if XNN_LIKELY(w > 4 * sizeof(float)) {
      $for M in range(ROW_TILE):
        float32x4_t vo${M}p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);

      $for M in range(4 + ROW_TILE):
        float32x4_t vi${M}x89AB = vld1q_f32(i${M}); i${M} += 4;

      $for M in range(4 + ROW_TILE):
        vi${M}x89AB = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi${M}x89AB)));

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 1:
          float32x4_t vo${M}p1 = vmulq_lane_f32(vi${M}x4567, vget_high_f32(vw0123), 1);
        $else:
          vo${M}p0 = ${VMULADDQ_LANE_F32}(vo${M}p0, vi${M}x4567, vget_high_f32(vw0123), 1);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 2:
          float32x4_t vo${M}p2 = vmulq_lane_f32(vi${M+1}x4567, vget_low_f32(vw89AB), 0);
        $else:
          vo${M}p0 = ${VMULADDQ_LANE_F32}(vo${M}p0, vi${M+1}x4567, vget_low_f32(vw89AB), 0);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 3:
          float32x4_t vo${M}p3 = vmulq_lane_f32(vi${M+2}x4567, vget_low_f32(vwCDEF), 1);
        $else:
          vo${M}p${4 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${4 % ACCUMULATORS}, vi${M+2}x4567, vget_low_f32(vwCDEF), 1);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 4:
          float32x4_t vo${M}p4 = vmulq_lane_f32(vi${M+3}x4567, vget_high_f32(vwGHIJ), 0);
        $else:
          vo${M}p${5 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${5 % ACCUMULATORS}, vi${M+3}x4567, vget_high_f32(vwGHIJ), 0);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 6:
          float32x4_t vo${M}p5 = vmulq_lane_f32(vi${M+4}x4567, vget_high_f32(vwKLMN), 1);
        $else:
          vo${M}p${6 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${6 % ACCUMULATORS}, vi${M+4}x4567, vget_high_f32(vwKLMN), 1);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x3456 = vextq_f32(vi${M}x0123, vi${M}x4567, 3);

      $for M in range(ROW_TILE):
        vo${M}p${7 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${7 % ACCUMULATORS}, vi${M}x3456, vget_high_f32(vw0123), 0);

      $for M in range(ROW_TILE):
        vo${M}p${8 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${8 % ACCUMULATORS}, vi${M+1}x3456, vget_high_f32(vw4567), 1);

      $for M in range(ROW_TILE):
        vo${M}p${9 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${9 % ACCUMULATORS}, vi${M+2}x3456, vget_low_f32(vwCDEF), 0);

      $for M in range(ROW_TILE):
        vo${M}p${10 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${10 % ACCUMULATORS}, vi${M+3}x3456, vget_low_f32(vwGHIJ), 1);

      $for M in range(ROW_TILE):
        vo${M}p${11 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${11 % ACCUMULATORS}, vi${M+4}x3456, vget_high_f32(vwKLMN), 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x2345 = vextq_f32(vi${M}x0123, vi${M}x4567, 2);
        vi${M}x0123 = vi${M}x4567;

      $for M in range(ROW_TILE):
        vo${M}p${12 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${12 % ACCUMULATORS}, vi${M}x2345, vget_low_f32(vw0123), 1);

      $for M in range(ROW_TILE):
        vo${M}p${13 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${13 % ACCUMULATORS}, vi${M+1}x2345, vget_high_f32(vw4567), 0);

      $for M in range(ROW_TILE):
        vo${M}p${14 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${14 % ACCUMULATORS}, vi${M+2}x2345, vget_high_f32(vw89AB), 1);

      $for M in range(ROW_TILE):
        vo${M}p${15 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${15 % ACCUMULATORS}, vi${M+3}x2345, vget_low_f32(vwGHIJ), 0);

      $for M in range(ROW_TILE):
        vo${M}p${16 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${16 % ACCUMULATORS}, vi${M+4}x2345, vget_low_f32(vwKLMN), 1);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x5678 = vextq_f32(vi${M}x4567, vi${M}x89AB, 1);

      $for M in range(ROW_TILE):
        vo${M}p${17 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${17 % ACCUMULATORS}, vi${M}x5678, vget_low_f32(vw4567), 0);

      $for M in range(ROW_TILE):
        vo${M}p${18 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${18 % ACCUMULATORS}, vi${M+1}x5678, vget_low_f32(vw89AB), 1);

      $for M in range(ROW_TILE):
        vo${M}p${19 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${19 % ACCUMULATORS}, vi${M+2}x5678, vget_high_f32(vwCDEF), 0);

      $for M in range(ROW_TILE):
        vo${M}p${20 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${20 % ACCUMULATORS}, vi${M+3}x5678, vget_high_f32(vwGHIJ), 1);

      $for M in range(ROW_TILE):
        vo${M}p${21 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${21 % ACCUMULATORS}, vi${M+4}x5678, vwOP, 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x6789 = vextq_f32(vi${M}x4567, vi${M}x89AB, 2);
        vi${M}x4567 = vi${M}x89AB;

      $for M in range(ROW_TILE):
        vo${M}p${22 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${22 % ACCUMULATORS}, vi${M}x6789, vget_low_f32(vw4567), 1);

      $for M in range(ROW_TILE):
        vo${M}p${23 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${23 % ACCUMULATORS}, vi${M+1}x6789, vget_high_f32(vw89AB), 0);

      $for M in range(ROW_TILE):
        vo${M}p${24 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${24 % ACCUMULATORS}, vi${M+2}x6789, vget_high_f32(vwCDEF), 1);

      $for M in range(ROW_TILE):
        vo${M}p${25 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${25 % ACCUMULATORS}, vi${M+3}x6789, vget_low_f32(vwKLMN), 0);

      $for M in range(ROW_TILE):
        vo${M}p${26 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${26 % ACCUMULATORS}, vi${M+4}x6789, vwOP, 1);

      $if ACCUMULATORS > 1:
        $ACC_SLICE = 1
        $while ACC_SLICE < ACCUMULATORS:
          $for A in range(0, ACCUMULATORS, ACC_SLICE * 2):
            $if A + ACC_SLICE < ACCUMULATORS:
              $for M in range(ROW_TILE):
                vo${M}p${A} = vaddq_f32(vo${M}p${A}, vo${M}p${A + ACC_SLICE});
          $ACC_SLICE *= 2

      $for M in range(ROW_TILE):
        float32x4_t vo${M} = vmaxq_f32(vo${M}p0, vmin);

      $for M in range(ROW_TILE):
        vo${M} = vminq_f32(vo${M}, vmax);

      $for M in reversed(range(ROW_TILE)):
        vst1q_f32(o${M}, vo${M}); o${M} += 4;

      w -= 4 * sizeof(float);
    }
    assert(w >= 1 * sizeof(float));
    assert(w <= 4 * sizeof(float));
    {
      $for M in range(ROW_TILE):
        float32x4_t vo${M}p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);

      $for M in range(4 + ROW_TILE):
        vi${M}x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi${M}x4567)));

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 1:
          float32x4_t vo${M}p1 = vmulq_lane_f32(vi${M}x4567, vget_high_f32(vw0123), 1);
        $else:
          vo${M}p0 = ${VMULADDQ_LANE_F32}(vo${M}p0, vi${M}x4567, vget_high_f32(vw0123), 1);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 2:
          float32x4_t vo${M}p2 = vmulq_lane_f32(vi${M+1}x4567, vget_low_f32(vw89AB), 0);
        $else:
          vo${M}p0 = ${VMULADDQ_LANE_F32}(vo${M}p0, vi${M+1}x4567, vget_low_f32(vw89AB), 0);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 3:
          float32x4_t vo${M}p3 = vmulq_lane_f32(vi${M+2}x4567, vget_low_f32(vwCDEF), 1);
        $else:
          vo${M}p${4 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${4 % ACCUMULATORS}, vi${M+2}x4567, vget_low_f32(vwCDEF), 1);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 4:
          float32x4_t vo${M}p4 = vmulq_lane_f32(vi${M+3}x4567, vget_high_f32(vwGHIJ), 0);
        $else:
          vo${M}p${5 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${5 % ACCUMULATORS}, vi${M+3}x4567, vget_high_f32(vwGHIJ), 0);

      $for M in range(ROW_TILE):
        $if ACCUMULATORS > 6:
          float32x4_t vo${M}p5 = vmulq_lane_f32(vi${M+4}x4567, vget_high_f32(vwKLMN), 1);
        $else:
          vo${M}p${6 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${6 % ACCUMULATORS}, vi${M+4}x4567, vget_high_f32(vwKLMN), 1);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x3456 = vextq_f32(vi${M}x0123, vi${M}x4567, 3);

      $for M in range(ROW_TILE):
        vo${M}p${7 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${7 % ACCUMULATORS}, vi${M}x3456, vget_high_f32(vw0123), 0);

      $for M in range(ROW_TILE):
        vo${M}p${8 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${8 % ACCUMULATORS}, vi${M+1}x3456, vget_high_f32(vw4567), 1);

      $for M in range(ROW_TILE):
        vo${M}p${9 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${9 % ACCUMULATORS}, vi${M+2}x3456, vget_low_f32(vwCDEF), 0);

      $for M in range(ROW_TILE):
        vo${M}p${10 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${10 % ACCUMULATORS}, vi${M+3}x3456, vget_low_f32(vwGHIJ), 1);

      $for M in range(ROW_TILE):
        vo${M}p${11 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${11 % ACCUMULATORS}, vi${M+4}x3456, vget_high_f32(vwKLMN), 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x2345 = vextq_f32(vi${M}x0123, vi${M}x4567, 2);

      $for M in range(ROW_TILE):
        vo${M}p${12 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${12 % ACCUMULATORS}, vi${M}x2345, vget_low_f32(vw0123), 1);

      $for M in range(ROW_TILE):
        vo${M}p${13 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${13 % ACCUMULATORS}, vi${M+1}x2345, vget_high_f32(vw4567), 0);

      $for M in range(ROW_TILE):
        vo${M}p${14 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${14 % ACCUMULATORS}, vi${M+2}x2345, vget_high_f32(vw89AB), 1);

      $for M in range(ROW_TILE):
        vo${M}p${15 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${15 % ACCUMULATORS}, vi${M+3}x2345, vget_low_f32(vwGHIJ), 0);

      $for M in range(ROW_TILE):
        vo${M}p${16 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${16 % ACCUMULATORS}, vi${M+4}x2345, vget_low_f32(vwKLMN), 1);

      const float32x4_t vzero = vmovq_n_f32(0.0f);
      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x5678 = vextq_f32(vi${M}x4567, vzero, 1);

      $for M in range(ROW_TILE):
        vo${M}p${17 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${17 % ACCUMULATORS}, vi${M}x5678, vget_low_f32(vw4567), 0);

      $for M in range(ROW_TILE):
        vo${M}p${18 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${18 % ACCUMULATORS}, vi${M+1}x5678, vget_low_f32(vw89AB), 1);

      $for M in range(ROW_TILE):
        vo${M}p${19 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${19 % ACCUMULATORS}, vi${M+2}x5678, vget_high_f32(vwCDEF), 0);

      $for M in range(ROW_TILE):
        vo${M}p${20 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${20 % ACCUMULATORS}, vi${M+3}x5678, vget_high_f32(vwGHIJ), 1);

      $for M in range(ROW_TILE):
        vo${M}p${21 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${21 % ACCUMULATORS}, vi${M+4}x5678, vwOP, 0);

      $for M in range(4 + ROW_TILE):
        const float32x4_t vi${M}x6789 = vextq_f32(vi${M}x5678, vzero, 1);

      $for M in range(ROW_TILE):
        vo${M}p${22 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${22 % ACCUMULATORS}, vi${M}x6789, vget_low_f32(vw4567), 1);

      $for M in range(ROW_TILE):
        vo${M}p${23 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${23 % ACCUMULATORS}, vi${M+1}x6789, vget_high_f32(vw89AB), 0);

      $for M in range(ROW_TILE):
        vo${M}p${24 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${24 % ACCUMULATORS}, vi${M+2}x6789, vget_high_f32(vwCDEF), 1);

      $for M in range(ROW_TILE):
        vo${M}p${25 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${25 % ACCUMULATORS}, vi${M+3}x6789, vget_low_f32(vwKLMN), 0);

      $for M in range(ROW_TILE):
        vo${M}p${26 % ACCUMULATORS} = ${VMULADDQ_LANE_F32}(vo${M}p${26 % ACCUMULATORS}, vi${M+4}x6789, vwOP, 1);

      $if ACCUMULATORS > 1:
        $ACC_SLICE = 1
        $while ACC_SLICE < ACCUMULATORS:
          $for A in range(0, ACCUMULATORS, ACC_SLICE * 2):
            $if A + ACC_SLICE < ACCUMULATORS:
              $for M in range(ROW_TILE):
                vo${M}p${A} = vaddq_f32(vo${M}p${A}, vo${M}p${A + ACC_SLICE});
          $ACC_SLICE *= 2

      $for M in range(ROW_TILE):
        float32x4_t vo${M} = vmaxq_f32(vo${M}p0, vmin);

      $for M in range(ROW_TILE):
        vo${M} = vminq_f32(vo${M}, vmax);

      if XNN_LIKELY(w & (4 * sizeof(float))) {
        $for M in reversed(range(ROW_TILE)):
          vst1q_f32(o${M}, vo${M}); o${M} += 4;
      } else {
        $for M in range(ROW_TILE):
          float32x2_t vo${M}_lo = vget_low_f32(vo${M});
        if (w & (2 * sizeof(float))) {
          $for M in reversed(range(ROW_TILE)):
            vst1_f32(o${M}, vo${M}_lo); o${M} += 2;

          $for M in range(ROW_TILE):
            vo${M}_lo = vget_high_f32(vo${M});
        }
        if (w & (1 * sizeof(float))) {
          $for M in reversed(range(ROW_TILE)):
            vst1_lane_f32(o${M}, vo${M}_lo, 0); o${M} += 1;
        }
      }
    }

    i0 = (const float*) ((uintptr_t) i${ROW_TILE} - input_decrement);
    i1 = (const float*) ((uintptr_t) i${ROW_TILE+1} - input_decrement);
    $for M in range(2, 4 + ROW_TILE):
      i${M} = (const float*) ((uintptr_t) i${M-1} + input_width);

    $if ROW_TILE > 1:
      o0 = o${ROW_TILE - 1};
      $for M in range(1, ROW_TILE):
        o${M} = (float*) ((uintptr_t) o${M-1} + input_width);

    $if ROW_TILE > 1:
      output_height = doz(output_height, ${ROW_TILE});
  } while (${"--" if ROW_TILE == 1 else ""}output_height != 0);
}
