// 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 % 16 == 0
$assert BATCH_TILE >= 16
$assert RR_STEPS in [1, 2]
$assert DIV_ALGO in ["div", "nr1fma", "nr1fma1adj"]
$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$SIMD_TILE = BATCH_TILE // 16
#include <assert.h>

#include <immintrin.h>

#include <xnnpack/common.h>
#include <xnnpack/intrinsics-polyfill.h>
#include <xnnpack/vunary.h>


void xnn_f32_vsigmoid_ukernel__avx512f_rr${RR_STEPS}_p5_scalef_${DIV_ALGO}_x${BATCH_TILE}(
    size_t n,
    const float* x,
    float* y,
    const void* params)
{
  assert(n % sizeof(float) == 0);

  const __m512i vsign_mask = _mm512_set1_epi32(0x80000000);
  const __m512 vlog2e = _mm512_set1_ps(0x1.715476p+0f);
  $if RR_STEPS == 1:
    const __m512 vminus_ln2 = _mm512_set1_ps(-0x1.62E43p-1f);
  $else:
    const __m512 vminus_ln2_hi = _mm512_set1_ps(-0x1.62E43p-1f);
    const __m512 vminus_ln2_lo = _mm512_set1_ps(0x1.05C61p-29f);
  const __m512 vc5 = _mm512_set1_ps(0x1.0F9F9Cp-7f);
  const __m512 vc4 = _mm512_set1_ps(0x1.573A1Ap-5f);
  const __m512 vc3 = _mm512_set1_ps(0x1.555A80p-3f);
  const __m512 vc2 = _mm512_set1_ps(0x1.FFFDC6p-2f);
  const __m512 vc1 = _mm512_set1_ps(0x1.FFFFF6p-1f);
  const __m512 vone = _mm512_set1_ps(1.0f);

  $if BATCH_TILE > 16:
    for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
      const __m512 vx${ABC[0]} = _mm512_loadu_ps(x);
      $for N in range(1, SIMD_TILE):
        const __m512 vx${ABC[N]} = _mm512_loadu_ps(x + ${N * 16});
      x += ${BATCH_TILE};

      $for N in range(SIMD_TILE):
        const __m512 vz${ABC[N]} = _mm512_castsi512_ps(_mm512_or_epi32(_mm512_castps_si512(vx${ABC[N]}), vsign_mask));

      $for N in range(SIMD_TILE):
        __m512 vn${ABC[N]} = _mm512_mul_ps(vz${ABC[N]}, vlog2e);

      $for N in range(SIMD_TILE):
        vn${ABC[N]} = _mm512_roundscale_ps(vn${ABC[N]}, 0);

      $if RR_STEPS == 1:
        $for N in range(SIMD_TILE):
          __m512 vt${ABC[N]} = _mm512_fmadd_ps(vn${ABC[N]}, vminus_ln2, vz${ABC[N]});
      $else:
        $for N in range(SIMD_TILE):
          __m512 vt${ABC[N]} = _mm512_fmadd_ps(vn${ABC[N]}, vminus_ln2_hi, vz${ABC[N]});

        $for N in range(SIMD_TILE):
          vt${ABC[N]} = _mm512_fmadd_ps(vn${ABC[N]}, vminus_ln2_lo, vt${ABC[N]});

      $for N in range(SIMD_TILE):
        __m512 vp${ABC[N]} = _mm512_fmadd_ps(vc5, vt${ABC[N]}, vc4);

      $for N in range(SIMD_TILE):
        vp${ABC[N]} = _mm512_fmadd_ps(vp${ABC[N]}, vt${ABC[N]}, vc3);

      $for N in range(SIMD_TILE):
        vp${ABC[N]} = _mm512_fmadd_ps(vp${ABC[N]}, vt${ABC[N]}, vc2);

      $for N in range(SIMD_TILE):
        vp${ABC[N]} = _mm512_fmadd_ps(vp${ABC[N]}, vt${ABC[N]}, vc1);

      $for N in range(SIMD_TILE):
        vp${ABC[N]} = _mm512_fmadd_ps(vp${ABC[N]}, vt${ABC[N]}, vone);

      $for N in range(SIMD_TILE):
        const __m512 ve${ABC[N]} = _mm512_scalef_ps(vp${ABC[N]}, vn${ABC[N]});

      $for N in range(SIMD_TILE):
        const __m512 vd${ABC[N]} = _mm512_add_ps(ve${ABC[N]}, vone);

      $if DIV_ALGO == "div":
        $for N in range(SIMD_TILE):
          __m512 vf${ABC[N]} = _mm512_div_ps(ve${ABC[N]}, vd${ABC[N]});
      $else:
        $for N in range(SIMD_TILE):
          __m512 vr${ABC[N]} = _mm512_rcp14_ps(vd${ABC[N]});

        $for N in range(SIMD_TILE):
          vr${ABC[N]} = _mm512_fmadd_ps(_mm512_fnmadd_ps(vr${ABC[N]}, vd${ABC[N]}, vone), vr${ABC[N]}, vr${ABC[N]});

        $for N in range(SIMD_TILE):
          __m512 vf${ABC[N]} = _mm512_mul_ps(ve${ABC[N]}, vr${ABC[N]});

        $if DIV_ALGO == "nr1fma1adj":
          $for N in range(SIMD_TILE):
            vf${ABC[N]} = _mm512_fmadd_ps(_mm512_fnmadd_ps(vf${ABC[N]}, vd${ABC[N]}, ve${ABC[N]}), vr${ABC[N]}, vf${ABC[N]});

      $for N in range(SIMD_TILE):
        vf${ABC[N]} = _mm512_mask_sub_ps(vf${ABC[N]}, _mm512_testn_epi32_mask(_mm512_castps_si512(vx${ABC[N]}), vsign_mask), vone, vf${ABC[N]});

      _mm512_storeu_ps(y, vf${ABC[0]});
      $for N in range(1, SIMD_TILE):
        _mm512_storeu_ps(y + ${N * 16}, vf${ABC[N]});
      y += ${BATCH_TILE};
    }
  for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
    const __m512 vx = _mm512_loadu_ps(x);
    x += 16;

    const __m512 vz = _mm512_castsi512_ps(_mm512_or_epi32(_mm512_castps_si512(vx), vsign_mask));

    const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vz, vlog2e), 0);

    $if RR_STEPS == 1:
      __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vz);
    $else:
      __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2_hi, vz);
      vt = _mm512_fmadd_ps(vn, vminus_ln2_lo, vt);

    __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
    vp = _mm512_fmadd_ps(vp, vt, vc3);
    vp = _mm512_fmadd_ps(vp, vt, vc2);
    vp = _mm512_fmadd_ps(vp, vt, vc1);
    vp = _mm512_fmadd_ps(vp, vt, vone);

    const __m512 ve = _mm512_scalef_ps(vp, vn);
    const __m512 vd = _mm512_add_ps(ve, vone);

    $if DIV_ALGO == "div":
      __m512 vf = _mm512_div_ps(ve, vd);
    $else:
      __m512 vr = _mm512_rcp14_ps(vd);
      vr = _mm512_fmadd_ps(_mm512_fnmadd_ps(vr, vd, vone), vr, vr);

      __m512 vf = _mm512_mul_ps(ve, vr);
      $if DIV_ALGO == "nr1fma1adj":
        vf = _mm512_fmadd_ps(_mm512_fnmadd_ps(vf, vd, ve), vr, vf);

    vf = _mm512_mask_sub_ps(vf, _mm512_testn_epi32_mask(_mm512_castps_si512(vx), vsign_mask), vone, vf);

    _mm512_storeu_ps(y, vf);
    y += 16;
  }
  if XNN_UNLIKELY(n != 0) {
    assert(n >= 1 * sizeof(float));
    assert(n <= 15 * sizeof(float));

    // Prepare mask for valid 32-bit elements (depends on n).
    n >>= 2 /* log2(sizeof(float)) */;
    const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));

    const __m512 vx = _mm512_maskz_loadu_ps(vmask, x);
    const __m512 vz = _mm512_castsi512_ps(_mm512_or_epi32(_mm512_castps_si512(vx), vsign_mask));

    const __m512 vn = _mm512_roundscale_ps(_mm512_mul_ps(vz, vlog2e), 0);

    $if RR_STEPS == 1:
      __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vz);
    $else:
      __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2_hi, vz);
      vt = _mm512_fmadd_ps(vn, vminus_ln2_lo, vt);

    __m512 vp = _mm512_fmadd_ps(vc5, vt, vc4);
    vp = _mm512_fmadd_ps(vp, vt, vc3);
    vp = _mm512_fmadd_ps(vp, vt, vc2);
    vp = _mm512_fmadd_ps(vp, vt, vc1);
    vp = _mm512_fmadd_ps(vp, vt, vone);

    const __m512 ve = _mm512_scalef_ps(vp, vn);
    const __m512 vd = _mm512_add_ps(ve, vone);

    $if DIV_ALGO == "div":
      __m512 vf = _mm512_div_ps(ve, vd);
    $else:
      __m512 vr = _mm512_rcp14_ps(vd);
      vr = _mm512_fmadd_ps(_mm512_fnmadd_ps(vr, vd, vone), vr, vr);

      __m512 vf = _mm512_mul_ps(ve, vr);
      $if DIV_ALGO == "nr1fma1adj":
        vf = _mm512_fmadd_ps(_mm512_fnmadd_ps(vf, vd, ve), vr, vf);

    vf = _mm512_mask_sub_ps(vf, _mm512_testn_epi32_mask(_mm512_castps_si512(vx), vsign_mask), vone, vf);

    _mm512_mask_storeu_ps(y, vmask, vf);
  }
}
