// Auto-generated file. Do not edit!
//   Template: src/s16-window/scalar.c.in
//   Generator: tools/xngen
//
// 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.

#include <assert.h>
#include <stddef.h>
#include <stdint.h>

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


void xnn_s16_window_ukernel__scalar_x2(
    size_t rows,
    size_t batch_size,
    const int16_t* input,
    const int16_t* weights,
    int16_t* output,
    uint32_t shift)
{
  assert(rows > 0);
  assert(batch_size != 0);
  assert(input != NULL);
  assert(weights != NULL);
  assert(output != NULL);
  assert(shift < 32);

  do {
    size_t n = batch_size;
    const int16_t* w = weights;
    for (; n >= 2; n -= 2) {
      const int16_t vi0 = input[0];
      const int16_t vi1 = input[1];
      input += 2;

      const int16_t w0 = w[0];
      const int16_t w1 = w[1];
      w += 2;

      int32_t vout0 = (int32_t) vi0 * (int32_t) w0;
      int32_t vout1 = (int32_t) vi1 * (int32_t) w1;

      vout0 = math_asr_s32(vout0, shift);
      vout1 = math_asr_s32(vout1, shift);

      vout0 = math_max_s32(vout0, INT16_MIN);
      vout1 = math_max_s32(vout1, INT16_MIN);

      vout0 = math_min_s32(vout0, INT16_MAX);
      vout1 = math_min_s32(vout1, INT16_MAX);

      output[0] = (int16_t) vout0;
      output[1] = (int16_t) vout1;

      output += 2;
    }

    if XNN_UNLIKELY(n != 0) {
      do {
        const int32_t vi = (int32_t) *input++;
        const int32_t vw = (int32_t) *w++;
        int32_t vout = vi * vw;
        vout = math_asr_s32(vout, shift);
        vout = math_max_s32(vout, INT16_MIN);
        vout = math_min_s32(vout, INT16_MAX);
        *output++ = (int16_t) vout;
      } while (--n != 0);
    }
  } while (--rows != 0);
}
