// 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
$SIMD_TILE = BATCH_TILE // 8
#include <assert.h>

#include <immintrin.h>

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


void xnn_f32_velu_ukernel__avx2_rr1_p6_x${BATCH_TILE}(
    size_t n,
    const float* x,
    float* y,
    const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
{
  assert(n % sizeof(float) == 0);

  const __m256 vprescale = _mm256_load_ps(params->avx2_rr1_p6.prescale);
  const __m256 valpha = _mm256_load_ps(params->avx2_rr1_p6.alpha);
  const __m256 vbeta = _mm256_load_ps(params->avx2_rr1_p6.beta);
  const __m256 vsat_cutoff = _mm256_load_ps(params->avx2_rr1_p6.sat_cutoff);
  const __m256 vmagic_bias = _mm256_load_ps(params->avx2_rr1_p6.magic_bias);
  const __m256 vlog2e = _mm256_load_ps(params->avx2_rr1_p6.log2e);
  const __m256 vminus_ln2 = _mm256_load_ps(params->avx2_rr1_p6.minus_ln2);
  const __m256 vc6 = _mm256_load_ps(params->avx2_rr1_p6.c6);
  const __m256 vc5 = _mm256_load_ps(params->avx2_rr1_p6.c5);
  const __m256 vc4 = _mm256_load_ps(params->avx2_rr1_p6.c4);
  const __m256 vc3 = _mm256_load_ps(params->avx2_rr1_p6.c3);
  const __m256 vc2 = _mm256_load_ps(params->avx2_rr1_p6.c2);

  $if BATCH_TILE > 8:
    for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
      __m256 vx0 = _mm256_loadu_ps(x);
      $for N in range(1, SIMD_TILE):
        __m256 vx${N} = _mm256_loadu_ps(x + ${N * 8});
      x += ${BATCH_TILE};

      $for N in range(SIMD_TILE):
        const __m256 vz${N} = _mm256_max_ps(vsat_cutoff, _mm256_mul_ps(vx${N}, vprescale));

      $for N in range(SIMD_TILE):
        __m256 vn${N} = _mm256_fmadd_ps(vz${N}, vlog2e, vmagic_bias);

      $for N in range(SIMD_TILE):
        __m256 vs${N} = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(vn${N}), 23));
        vn${N} = _mm256_sub_ps(vn${N}, vmagic_bias);

      $for N in range(SIMD_TILE):
        __m256 vt${N} = _mm256_fmadd_ps(vn${N}, vminus_ln2, vz${N});

      $for N in range(SIMD_TILE):
        __m256 vp${N} = _mm256_fmadd_ps(vc6, vt${N}, vc5);

      $for N in range(SIMD_TILE):
        vp${N} = _mm256_fmadd_ps(vp${N}, vt${N}, vc4);

      $for N in range(SIMD_TILE):
        vp${N} = _mm256_fmadd_ps(vp${N}, vt${N}, vc3);

      $for N in range(SIMD_TILE):
        vp${N} = _mm256_fmadd_ps(vp${N}, vt${N}, vc2);

      $for N in range(SIMD_TILE):
        vp${N} = _mm256_mul_ps(vp${N}, vt${N});
        vt${N} = _mm256_mul_ps(vt${N}, vs${N});

      $for N in range(SIMD_TILE):
        vs${N} = _mm256_fmsub_ps(vs${N}, valpha, valpha);
        vp${N} = _mm256_fmadd_ps(vp${N}, vt${N}, vt${N});

      $for N in range(SIMD_TILE):
        const __m256 ve${N} = _mm256_fmadd_ps(vp${N}, valpha, vs${N});
        vx${N} = _mm256_mul_ps(vx${N}, vbeta);

      $for N in range(SIMD_TILE):
        const __m256 vy${N} = _mm256_blendv_ps(vx${N}, ve${N}, vx${N});

      _mm256_storeu_ps(y, vy0);
      $for N in range(1, SIMD_TILE):
        _mm256_storeu_ps(y + ${N * 8}, vy${N});
      y += ${BATCH_TILE};
    }
  for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
    __m256 vx = _mm256_loadu_ps(x);
    x += 8;

    const __m256 vz = _mm256_max_ps(vsat_cutoff, _mm256_mul_ps(vx, vprescale));

    __m256 vn = _mm256_fmadd_ps(vz, vlog2e, vmagic_bias);
    __m256 vs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(vn), 23));
    vn = _mm256_sub_ps(vn, vmagic_bias);

    __m256 vt = _mm256_fmadd_ps(vn, vminus_ln2, vz);

    __m256 vp = _mm256_fmadd_ps(vc6, vt, vc5);
    vp = _mm256_fmadd_ps(vp, vt, vc4);
    vp = _mm256_fmadd_ps(vp, vt, vc3);
    vp = _mm256_fmadd_ps(vp, vt, vc2);
    vp = _mm256_mul_ps(vp, vt);

    vt = _mm256_mul_ps(vt, vs);
    vs = _mm256_fmsub_ps(vs, valpha, valpha);
    vp = _mm256_fmadd_ps(vp, vt, vt);
    const __m256 ve = _mm256_fmadd_ps(vp, valpha, vs);

    vx = _mm256_mul_ps(vx, vbeta);
    const __m256 vy = _mm256_blendv_ps(vx, ve, vx);

    _mm256_storeu_ps(y, vy);
    y += 8;
  }
  if XNN_UNLIKELY(n != 0) {
    assert(n >= 1 * sizeof(float));
    assert(n <= 7 * sizeof(float));
    const __m256i vmask = _mm256_loadu_si256((const __m256i*) ((uintptr_t) &params->avx2_rr1_p6.mask_table[7] - n));

    __m256 vx = _mm256_maskload_ps(x, vmask);

    const __m256 vz = _mm256_max_ps(vsat_cutoff, _mm256_mul_ps(vx, vprescale));

    __m256 vn = _mm256_fmadd_ps(vz, vlog2e, vmagic_bias);
    __m256 vs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(vn), 23));
    vn = _mm256_sub_ps(vn, vmagic_bias);

    __m256 vt = _mm256_fmadd_ps(vn, vminus_ln2, vz);

    __m256 vp = _mm256_fmadd_ps(vc6, vt, vc5);
    vp = _mm256_fmadd_ps(vp, vt, vc4);
    vp = _mm256_fmadd_ps(vp, vt, vc3);
    vp = _mm256_fmadd_ps(vp, vt, vc2);
    vp = _mm256_mul_ps(vp, vt);

    vt = _mm256_mul_ps(vt, vs);
    vs = _mm256_fmsub_ps(vs, valpha, valpha);
    vp = _mm256_fmadd_ps(vp, vt, vt);
    const __m256 ve = _mm256_fmadd_ps(vp, valpha, vs);

    vx = _mm256_mul_ps(vx, vbeta);
    const __m256 vy = _mm256_blendv_ps(vx, ve, vx);

    __m128 vy_lo = _mm256_castps256_ps128(vy);
    if (n & (4 * sizeof(float))) {
      _mm_storeu_ps(y, vy_lo);
      vy_lo = _mm256_extractf128_ps(vy, 1);
      y += 4;
    }
    if (n & (2 * sizeof(float))) {
      _mm_storel_pi((__m64*) y, vy_lo);
      vy_lo = _mm_movehl_ps(vy_lo, vy_lo);
      y += 2;
    }
    if (n & (1 * sizeof(float))) {
      _mm_store_ss(y, vy_lo);
    }
  }
}
