// 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 % 4 == 0
$assert BATCH_TILE >= 4
$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#include <assert.h>

#include <wasm_simd128.h>

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


void xnn_f32_vclamp_ukernel__wasmsimd_${"x86" if X86 else "arm"}_x${BATCH_TILE}(
    size_t n,
    const float* x,
    float* y,
    const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
{
  assert(n != 0);
  assert(n % sizeof(float) == 0);
  assert(x != NULL);
  assert(y != NULL);

  const v128_t vy_min = wasm_v128_load64_splat(params->wasmsimd.min);
  const v128_t vy_max = wasm_v128_load64_splat(params->wasmsimd.max);

  $if BATCH_TILE > 4:
    for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
      v128_t vacc${ABC[0:4]} = wasm_v128_load(x);
      $for N in range(4, BATCH_TILE, 4):
        v128_t vacc${ABC[N:N+4]} = wasm_v128_load(x + ${N});
      x += ${BATCH_TILE};

      $if X86:
        $for N in range(0, BATCH_TILE, 4):
          vacc${ABC[N:N+4]} = wasm_f32x4_pmax(vy_min, vacc${ABC[N:N+4]});

        $for N in range(0, BATCH_TILE, 4):
          vacc${ABC[N:N+4]} = wasm_f32x4_pmin(vy_max, vacc${ABC[N:N+4]});
      $else:
        $for N in range(0, BATCH_TILE, 4):
          vacc${ABC[N:N+4]} = wasm_f32x4_max(vacc${ABC[N:N+4]}, vy_min);

        $for N in range(0, BATCH_TILE, 4):
          vacc${ABC[N:N+4]} = wasm_f32x4_min(vacc${ABC[N:N+4]}, vy_max);

      wasm_v128_store(y, vacc${ABC[0:4]});
      $for N in range(4, BATCH_TILE, 4):
        wasm_v128_store(y + ${N}, vacc${ABC[N:N+4]});
      y += ${BATCH_TILE};
    }
  for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
    v128_t vacc = wasm_v128_load(x);
    x += 4;

    $if X86:
      vacc = wasm_f32x4_pmax(vy_min, vacc);
      vacc = wasm_f32x4_pmin(vy_max, vacc);
    $else:
      vacc = wasm_f32x4_max(vacc, vy_min);
      vacc = wasm_f32x4_min(vacc, vy_max);

    wasm_v128_store(y, vacc);
    y += 4;
  }
  if XNN_UNLIKELY(n != 0) {
    v128_t vacc = wasm_v128_load(x);

    $if X86:
      vacc = wasm_f32x4_pmax(vy_min, vacc);
      vacc = wasm_f32x4_pmin(vy_max, vacc);
    $else:
      vacc = wasm_f32x4_max(vacc, vy_min);
      vacc = wasm_f32x4_min(vacc, vy_max);

    if (n & (2 * sizeof(float))) {
      *((double*) y) = wasm_f64x2_extract_lane(vacc, 0);
      vacc = wasm_v32x4_shuffle(vacc, vacc, 2, 3, 2, 3);
      y += 2;
    }
    if (n & (1 * sizeof(float))) {
      *y = wasm_f32x4_extract_lane(vacc, 0);
    }
  }
}
