// Copyright 2021 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 SSE in [2, 4]
$assert not AVX or SSE == 4
$assert BATCH_TILE % 8 == 0
$assert BATCH_TILE >= 8
$SIMD_TILE = BATCH_TILE // 8
$SSE_HEADER = {2: "emmintrin.h", 4: "smmintrin.h"}[SSE]
$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#include <assert.h>

#include <${SSE_HEADER}>

#include <xnnpack/common.h>
#include <xnnpack/unaligned.h>
#include <xnnpack/vcvt.h>


$ISA = "avx" if AVX else {2: "sse2", 4: "sse41"}[SSE]
void xnn_f32_f16_vcvt_ukernel__${ISA}_x${BATCH_TILE}(
    size_t n,
    const float* input,
    void* output,
    const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
{
  assert(n != 0);
  assert(n % sizeof(float) == 0);
  assert(input != NULL);
  assert(output != NULL);

  const __m128 vnonsign_mask = _mm_load_ps((const float*) params->sse2.nonsign_mask);
  const __m128i vexp_bias = _mm_load_si128((const __m128i*) params->sse2.exp_bias);
  const __m128 vscale_to_inf = _mm_load_ps(params->sse2.scale_to_inf);
  const __m128i vexpw_max = _mm_load_si128((const __m128i*) params->sse2.expw_max);
  const __m128 vscale_to_zero = _mm_load_ps(params->sse2.scale_to_zero);
  const __m128i vbias_min = _mm_load_si128((const __m128i*) params->sse2.bias_min);
  const __m128i vmanth_mask = _mm_load_si128((const __m128i*) params->sse2.manth_mask);
  const __m128i vexph_mask = _mm_load_si128((const __m128i*) params->sse2.exph_mask);
  const __m128i vnanh = _mm_load_si128((const __m128i*) params->sse2.nanh);

  uint16_t* o = (uint16_t*) output;
  $if BATCH_TILE > 8:
    for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
      const __m128 vx0 = _mm_loadu_ps(input);
      $for N in range(1, 2*SIMD_TILE):
        const __m128 vx${N} = _mm_loadu_ps(input + ${N * 4});
      input += ${BATCH_TILE};

      $for N in range(2*SIMD_TILE):
        const __m128 vabsx${N} = _mm_and_ps(vx${N}, vnonsign_mask);

      $for N in range(2*SIMD_TILE):
        const __m128 vsignx${N} = _mm_xor_ps(vx${N}, vabsx${N});

      $for N in range(2*SIMD_TILE):
        __m128i vbias${N} = _mm_add_epi32(_mm_castps_si128(vabsx${N}), vexp_bias);

      $for N in range(2*SIMD_TILE):
        __m128 vf${N} = _mm_mul_ps(vabsx${N}, vscale_to_inf);

      $for N in range(2*SIMD_TILE):
        const __m128i vnanmaskw${N} = _mm_cmpgt_epi32(_mm_castps_si128(vabsx${N}), vexpw_max);

      $for N in range(2*SIMD_TILE):
        vbias${N} = _mm_and_si128(vbias${N}, vexpw_max);

      $for N in range(2*SIMD_TILE):
        vf${N} = _mm_mul_ps(vf${N}, vscale_to_zero);

      $for N in range(SIMD_TILE):
        const __m128i vnanmaskh${N} = _mm_packs_epi32(vnanmaskw${2*N}, vnanmaskw${2*N+1});

      $for N in range(SIMD_TILE):
        const __m128i vsignh${N} = _mm_packs_epi32(_mm_castps_si128(vsignx${2*N}), _mm_castps_si128(vsignx${2*N+1}));

      $for N in range(2*SIMD_TILE):
        vbias${N} = _mm_max_epi16(vbias${N}, vbias_min);

      $if SSE < 4:
        $for N in range(SIMD_TILE):
          __m128i vh${N} = _mm_and_si128(vnanh, vnanmaskh${N});

      $for N in range(2*SIMD_TILE):
        vf${N} = _mm_add_ps(vf${N}, _mm_castsi128_ps(vbias${N}));

      $if SSE < 4:
        $for N in range(SIMD_TILE):
          vh${N} = _mm_or_si128(vh${N}, vsignh${N});

      $for N in range(2*SIMD_TILE):
        __m128i vexpw${N} = _mm_srli_epi32(_mm_castps_si128(vf${N}), 13);

      $for N in range(2*SIMD_TILE):
        const __m128i vmantw${N} = _mm_and_si128(_mm_castps_si128(vf${N}), vmanth_mask);

      $for N in range(2*SIMD_TILE):
        vexpw${N} = _mm_and_si128(vexpw${N}, vexph_mask);

      $for N in range(2*SIMD_TILE):
        const __m128i vnonsignw${N} = _mm_add_epi32(vmantw${N}, vexpw${N});

      $for N in range(SIMD_TILE):
        const __m128i vnonsignh${N} = _mm_packs_epi32(vnonsignw${2*N}, vnonsignw${2*N+1});

      $if SSE == 4:
        $for N in range(SIMD_TILE):
          const __m128i vabsh${N} = _mm_blendv_epi8(vnonsignh${N}, vnanh, vnanmaskh${N});

        $for N in range(SIMD_TILE):
          const __m128i vh${N} = _mm_or_si128(vabsh${N}, vsignh${N});
      $else:
        $for N in range(SIMD_TILE):
          vh${N} = _mm_or_si128(vh${N}, _mm_andnot_si128(vnanmaskh${N}, vnonsignh${N}));

      _mm_storeu_si128((__m128i*) o, vh0);
      $for N in range(1, SIMD_TILE):
        _mm_storeu_si128((__m128i*) (o + ${N * 8}), vh${N});
      o += ${BATCH_TILE};
    }
  for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
    const __m128 vx_lo = _mm_loadu_ps(input);
    const __m128 vx_hi = _mm_loadu_ps(input + 4);
    input += 8;

    const __m128 vabsx_lo = _mm_and_ps(vx_lo, vnonsign_mask);
    const __m128 vabsx_hi = _mm_and_ps(vx_hi, vnonsign_mask);

    const __m128 vsignx_lo = _mm_xor_ps(vx_lo, vabsx_lo);
    const __m128 vsignx_hi = _mm_xor_ps(vx_hi, vabsx_hi);
    __m128i vbias_lo = _mm_add_epi32(_mm_castps_si128(vabsx_lo), vexp_bias);
    __m128i vbias_hi = _mm_add_epi32(_mm_castps_si128(vabsx_hi), vexp_bias);
    __m128 vf_lo = _mm_mul_ps(vabsx_lo, vscale_to_inf);
    __m128 vf_hi = _mm_mul_ps(vabsx_hi, vscale_to_inf);
    const __m128i vnanmaskw_lo = _mm_cmpgt_epi32(_mm_castps_si128(vabsx_lo), vexpw_max);
    const __m128i vnanmaskw_hi = _mm_cmpgt_epi32(_mm_castps_si128(vabsx_hi), vexpw_max);

    vbias_lo = _mm_and_si128(vbias_lo, vexpw_max);
    vbias_hi = _mm_and_si128(vbias_hi, vexpw_max);
    vf_lo = _mm_mul_ps(vf_lo, vscale_to_zero);
    vf_hi = _mm_mul_ps(vf_hi, vscale_to_zero);
    const __m128i vnanmaskh = _mm_packs_epi32(vnanmaskw_lo, vnanmaskw_hi);
    const __m128i vsignh = _mm_packs_epi32(_mm_castps_si128(vsignx_lo), _mm_castps_si128(vsignx_hi));

    vbias_lo = _mm_max_epi16(vbias_lo, vbias_min);
    vbias_hi = _mm_max_epi16(vbias_hi, vbias_min);
    $if SSE < 4:
      __m128i vh = _mm_and_si128(vnanh, vnanmaskh);

    vf_lo = _mm_add_ps(vf_lo, _mm_castsi128_ps(vbias_lo));
    vf_hi = _mm_add_ps(vf_hi, _mm_castsi128_ps(vbias_hi));
    $if SSE < 4:
      vh = _mm_or_si128(vh, vsignh);

    __m128i vexpw_lo = _mm_srli_epi32(_mm_castps_si128(vf_lo), 13);
    __m128i vexpw_hi = _mm_srli_epi32(_mm_castps_si128(vf_hi), 13);
    const __m128i vmantw_lo = _mm_and_si128(_mm_castps_si128(vf_lo), vmanth_mask);
    const __m128i vmantw_hi = _mm_and_si128(_mm_castps_si128(vf_hi), vmanth_mask);

    vexpw_lo = _mm_and_si128(vexpw_lo, vexph_mask);
    vexpw_hi = _mm_and_si128(vexpw_hi, vexph_mask);

    const __m128i vnonsignw_lo = _mm_add_epi32(vmantw_lo, vexpw_lo);
    const __m128i vnonsignw_hi = _mm_add_epi32(vmantw_hi, vexpw_hi);

    const __m128i vnonsignh = _mm_packs_epi32(vnonsignw_lo, vnonsignw_hi);

    $if SSE == 4:
      const __m128i vabsh = _mm_blendv_epi8(vnonsignh, vnanh, vnanmaskh);

      const __m128i vh = _mm_or_si128(vabsh, vsignh);
    $else:
      vh = _mm_or_si128(vh, _mm_andnot_si128(vnanmaskh, vnonsignh));

    _mm_storeu_si128((__m128i*) o, vh);
    o += 8;
  }
  if XNN_UNPREDICTABLE(n != 0) {
    const __m128 vx_lo = _mm_loadu_ps(input);
    const float* input_hi = (const float*) ((uintptr_t) input + (n & (4 * sizeof(float))));
    const __m128 vx_hi = _mm_loadu_ps(input_hi);

    const __m128 vabsx_lo = _mm_and_ps(vx_lo, vnonsign_mask);
    const __m128 vabsx_hi = _mm_and_ps(vx_hi, vnonsign_mask);

    const __m128 vsignx_lo = _mm_xor_ps(vx_lo, vabsx_lo);
    const __m128 vsignx_hi = _mm_xor_ps(vx_hi, vabsx_hi);
    __m128i vbias_lo = _mm_add_epi32(_mm_castps_si128(vabsx_lo), vexp_bias);
    __m128i vbias_hi = _mm_add_epi32(_mm_castps_si128(vabsx_hi), vexp_bias);
    __m128 vf_lo = _mm_mul_ps(vabsx_lo, vscale_to_inf);
    __m128 vf_hi = _mm_mul_ps(vabsx_hi, vscale_to_inf);
    const __m128i vnanmaskw_lo = _mm_cmpgt_epi32(_mm_castps_si128(vabsx_lo), vexpw_max);
    const __m128i vnanmaskw_hi = _mm_cmpgt_epi32(_mm_castps_si128(vabsx_hi), vexpw_max);

    vbias_lo = _mm_and_si128(vbias_lo, vexpw_max);
    vbias_hi = _mm_and_si128(vbias_hi, vexpw_max);
    vf_lo = _mm_mul_ps(vf_lo, vscale_to_zero);
    vf_hi = _mm_mul_ps(vf_hi, vscale_to_zero);
    const __m128i vnanmaskh = _mm_packs_epi32(vnanmaskw_lo, vnanmaskw_hi);
    const __m128i vsignh = _mm_packs_epi32(_mm_castps_si128(vsignx_lo), _mm_castps_si128(vsignx_hi));

    vbias_lo = _mm_max_epi16(vbias_lo, vbias_min);
    vbias_hi = _mm_max_epi16(vbias_hi, vbias_min);
    $if SSE < 4:
      __m128i vh = _mm_and_si128(vnanh, vnanmaskh);

    vf_lo = _mm_add_ps(vf_lo, _mm_castsi128_ps(vbias_lo));
    vf_hi = _mm_add_ps(vf_hi, _mm_castsi128_ps(vbias_hi));
    $if SSE < 4:
      vh = _mm_or_si128(vh, vsignh);

    __m128i vexpw_lo = _mm_srli_epi32(_mm_castps_si128(vf_lo), 13);
    __m128i vexpw_hi = _mm_srli_epi32(_mm_castps_si128(vf_hi), 13);
    const __m128i vmantw_lo = _mm_and_si128(_mm_castps_si128(vf_lo), vmanth_mask);
    const __m128i vmantw_hi = _mm_and_si128(_mm_castps_si128(vf_hi), vmanth_mask);

    vexpw_lo = _mm_and_si128(vexpw_lo, vexph_mask);
    vexpw_hi = _mm_and_si128(vexpw_hi, vexph_mask);

    const __m128i vnonsignw_lo = _mm_add_epi32(vmantw_lo, vexpw_lo);
    const __m128i vnonsignw_hi = _mm_add_epi32(vmantw_hi, vexpw_hi);

    const __m128i vnonsignh = _mm_packs_epi32(vnonsignw_lo, vnonsignw_hi);

    $if SSE == 4:
      const __m128i vabsh = _mm_blendv_epi8(vnonsignh, vnanh, vnanmaskh);

      __m128i vh = _mm_or_si128(vabsh, vsignh);
    $else:
      vh = _mm_or_si128(vh, _mm_andnot_si128(vnanmaskh, vnonsignh));

    if (n & (4 * sizeof(float))) {
      _mm_storel_epi64((__m128i*) o, vh);
      vh = _mm_unpackhi_epi64(vh, vh);
      o += 4;
    }
    if (n & (2 * sizeof(float))) {
      unaligned_store_u32(o, (uint32_t) _mm_cvtsi128_si32(vh));
      vh = _mm_srli_epi64(vh, 32);
      o += 2;
    }
    if (n & (1 * sizeof(float))) {
      $if SSE == 4:
        *o = (uint16_t) _mm_extract_epi16(vh, 0);
      $else:
        *o = (uint16_t) _mm_cvtsi128_si32(vh);
    }
  }
}
