// 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 SSE in [2, 3, 4]
$assert not XOP or AVX
$assert not AVX or SSE == 4
$assert REQUANTIZATION == "FP32"
$assert DATATYPE in ["QC8", "QS8", "QU8"]
$assert VARIANT in ["LD64", "LD128"]
$assert MR <= 4
#include <assert.h>

$if XOP:
  #if defined(__GNUC__) || defined(__clang__)
    #include <x86intrin.h>
  #else
    #include <immintrin.h>
    #include <ammintrin.h>
  #endif
$else:
  $SSE_HEADER = {2: "emmintrin.h", 3: "tmmintrin.h", 4: "smmintrin.h"}[SSE]
  #include <${SSE_HEADER}>

#include <xnnpack/igemm.h>
#include <xnnpack/math.h>
#include <xnnpack/unaligned.h>


$PARAMS_STRUCT = REQUANTIZATION.lower() + "_" + ("sse4" if SSE == 4 and DATATYPE != "QU8" else "sse2")
$PARAMS_UNION = "xnn_%s_conv_minmax_params" % DATATYPE.lower()
$XINT8_T = "uint8_t" if DATATYPE == "QU8" else "int8_t"
$ISA = "xop" if XOP else "avx" if AVX else {2: "sse2", 3: "ssse3", 4: "sse41"}[SSE]
void xnn_${DATATYPE.lower()}_igemm_minmax_fp32_ukernel_${MR}x4c8__${ISA}_${VARIANT.lower()}(
    size_t mr,
    size_t nc,
    size_t kc,
    size_t ks,
    const ${XINT8_T}** restrict a,
    const void* restrict w,
    ${XINT8_T}* restrict c,
    size_t cm_stride,
    size_t cn_stride,
    size_t a_offset,
    const ${XINT8_T}* zero,
    const union ${PARAMS_UNION} params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
{
  assert(mr != 0);
  assert(mr <= ${MR});
  assert(nc != 0);
  assert(kc != 0);
  assert(ks != 0);
  assert(ks % (${MR} * sizeof(void*)) == 0);
  assert(a_offset % sizeof(${XINT8_T}) == 0);
  assert(a != NULL);
  assert(w != NULL);
  assert(c != NULL);

  kc = round_up_po2(kc, 8);
  ${XINT8_T}* c0 = c;
  $for M in range(1, MR):
    ${XINT8_T}* c${M} = (${XINT8_T}*) ((uintptr_t) c${M-1} + cm_stride);
    $if M % 2 == 0:
      if XNN_UNPREDICTABLE(mr <= ${M}) {
        c${M} = c${M-1};
      }
    $elif M + 1 == MR:
      if XNN_UNPREDICTABLE(mr != ${M+1}) {
        c${M} = c${M-1};
      }
    $else:
      if XNN_UNPREDICTABLE(mr < ${M+1}) {
        c${M} = c${M-1};
      }

  do {
    $for N in range(4):
      __m128i vacc0x${N} = _mm_cvtsi32_si128(((const int*) w)[${N}]);
    $for M in range(1, MR):
      $for N in range(4):
        __m128i vacc${M}x${N} = vacc0x${N};
    w = (const int32_t*) w + 4;

    size_t p = ks;
    do {
      $for M in range(MR):
        const ${XINT8_T}* restrict a${M} = a[${M}];
        if XNN_UNPREDICTABLE(a${M} != zero) {
          a${M} = (const ${XINT8_T}*) ((uintptr_t) a${M} + a_offset);
        }
      a += ${MR};

      size_t k = 0;
      $if DATATYPE == "QU8":
        const __m128i vb_zero_point = _mm_load_si128((const __m128i*) params->${PARAMS_STRUCT}.kernel_zero_point);
        $if SSE < 4 or VARIANT == "LD128":
          const __m128i vzero = _mm_setzero_si128();
      while (k < kc) {
        $for M in range(MR):
          const __m128i va${M} = _mm_loadl_epi64((const __m128i*) a${M});
          $if DATATYPE == "QU8":
            $if SSE == 4:
              const __m128i vxa${M} = _mm_cvtepu8_epi16(va${M});
            $else:
              const __m128i vxa${M} = _mm_unpacklo_epi8(va${M}, vzero);
          $else:
            $if SSE == 4:
              const __m128i vxa${M} = _mm_cvtepi8_epi16(va${M});
            $else:
              const __m128i vxa${M} = _mm_srai_epi16(_mm_unpacklo_epi8(va${M}, va${M}), 8);
          a${M} += 8;

        $if VARIANT == "LD128":
          $for N in range(0, 4, 2):
            $if N == 0:
              const __m128i vb${N}${N+1} = _mm_load_si128((const __m128i*) w);
            $else:
              const __m128i vb${N}${N+1} = _mm_load_si128((const __m128i*) ((const ${XINT8_T}*) w + ${N * 8}));
            $if DATATYPE == "QU8":
              const __m128i vxb${N} = _mm_sub_epi16(_mm_unpacklo_epi8(vb${N}${N+1}, vzero), vb_zero_point);
              const __m128i vxb${N+1} = _mm_sub_epi16(_mm_unpackhi_epi8(vb${N}${N+1}, vzero), vb_zero_point);
            $elif SSE == 4:
              const __m128i vxb${N} = _mm_cvtepi8_epi16(vb${N}${N+1});
              const __m128i vxb${N+1} = _mm_srai_epi16(_mm_unpackhi_epi8(vb${N}${N+1}, vb${N}${N+1}), 8);
            $else:
              const __m128i vsb${N}${N+1} = _mm_cmpgt_epi8(_mm_setzero_si128(), vb${N}${N+1});
              const __m128i vxb${N} = _mm_unpacklo_epi8(vb${N}${N+1}, vsb${N}${N+1});
              const __m128i vxb${N+1} = _mm_unpackhi_epi8(vb${N}${N+1}, vsb${N}${N+1});

            $for M in range(MR):
              $if XOP:
                vacc${M}x${N} = _mm_maddd_epi16(vxa${M}, vxb${N}, vacc${M}x${N});
                vacc${M}x${N+1} = _mm_maddd_epi16(vxa${M}, vxb${N+1}, vacc${M}x${N+1});
              $else:
                vacc${M}x${N} = _mm_add_epi32(vacc${M}x${N}, _mm_madd_epi16(vxa${M}, vxb${N}));
                vacc${M}x${N+1} = _mm_add_epi32(vacc${M}x${N+1}, _mm_madd_epi16(vxa${M}, vxb${N+1}));
        $else:
          $for N in range(4):
            $if N == 0:
              const __m128i vb${N} = _mm_loadl_epi64((const __m128i*) w);
            $else:
              const __m128i vb${N} = _mm_loadl_epi64((const __m128i*) ((const ${XINT8_T}*) w + ${N * 8}));
            $if DATATYPE == "QU8":
              $if SSE == 4:
                const __m128i vxb${N} = _mm_sub_epi16(_mm_cvtepu8_epi16(vb${N}), vb_zero_point);
              $else:
                const __m128i vxb${N} = _mm_sub_epi16(_mm_unpacklo_epi8(vb${N}, vzero), vb_zero_point);
            $else:
              $if SSE == 4:
                const __m128i vxb${N} = _mm_cvtepi8_epi16(vb${N});
              $else:
                const __m128i vxb${N} = _mm_srai_epi16(_mm_unpacklo_epi8(vb${N}, vb${N}), 8);

            $for M in range(MR):
              $if XOP:
                vacc${M}x${N} = _mm_maddd_epi16(vxa${M}, vxb${N}, vacc${M}x${N});
              $else:
                vacc${M}x${N} = _mm_add_epi32(vacc${M}x${N}, _mm_madd_epi16(vxa${M}, vxb${N}));

        w = (const void*) ((const ${XINT8_T}*) w + 32);
        k += 8 * sizeof(${XINT8_T});
      }
      p -= ${MR} * sizeof(void*);
    } while (p != 0);

    $if SSE >= 3:
      $for M in range(MR):
        const __m128i vacc${M}x01 = _mm_hadd_epi32(vacc${M}x0, vacc${M}x1);
        const __m128i vacc${M}x23 = _mm_hadd_epi32(vacc${M}x2, vacc${M}x3);

      $for M in range(MR):
        __m128i vacc${M}x0123 = _mm_hadd_epi32(vacc${M}x01, vacc${M}x23);
    $else:
      $for M in range(MR):
        const __m128i vacc${M}x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc${M}x0, vacc${M}x2), _mm_unpackhi_epi32(vacc${M}x0, vacc${M}x2));
        const __m128i vacc${M}x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc${M}x1, vacc${M}x3), _mm_unpackhi_epi32(vacc${M}x1, vacc${M}x3));

      $for M in range(MR):
        __m128i vacc${M}x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc${M}x02, vacc${M}x13), _mm_unpackhi_epi32(vacc${M}x02, vacc${M}x13));

    $for M in range(MR):
      __m128 vscaled${M}x0123 = _mm_cvtepi32_ps(vacc${M}x0123);

    $if DATATYPE == "QC8":
      const __m128 vscale0123 = _mm_load_ps((const float*) w);
      w = (const void*) ((const float*) w + 4);
      $for M in range(MR):
        vscaled${M}x0123 = _mm_mul_ps(vscaled${M}x0123, vscale0123);
    $else:
      const __m128 vscale = _mm_load_ps(params->${PARAMS_STRUCT}.scale);
      $for M in range(MR):
        vscaled${M}x0123 = _mm_mul_ps(vscaled${M}x0123, vscale);

    const __m128 voutput_max_less_zero_point = _mm_load_ps(params->${PARAMS_STRUCT}.output_max_less_zero_point);
    $for M in range(MR):
      vscaled${M}x0123 = _mm_min_ps(vscaled${M}x0123, voutput_max_less_zero_point);

    $for M in range(MR):
      vacc${M}x0123 = _mm_cvtps_epi32(vscaled${M}x0123);

    const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->${PARAMS_STRUCT}.output_zero_point);
    $for M in range(0, MR, 2):
      __m128i vacc${M}${min(M+1, MR-1)}x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc${M}x0123, vacc${min(M+1, MR-1)}x0123), voutput_zero_point);

    $if DATATYPE == "QU8":
      $if MR > 2:
        __m128i vout = _mm_packus_epi16(vacc0${min(1, MR-1)}x0123, vacc${min(2, MR-1)}${min(3, MR-1)}x0123);
      $else:
        __m128i vout = _mm_packus_epi16(vacc0${min(1, MR-1)}x0123, vacc0${min(1, MR-1)}x0123);

      vout = _mm_max_epu8(vout, _mm_load_si128((const __m128i*) params->${PARAMS_STRUCT}.output_min));
    $else:
      $if SSE < 4:
        const __m128i voutput_min = _mm_load_si128((const __m128i*) params->${PARAMS_STRUCT}.output_min);
        $for M in range(0, MR, 2):
          vacc${M}${min(M+1, MR-1)}x0123 = _mm_max_epi16(vacc${M}${min(M+1, MR-1)}x0123, voutput_min);

      $if MR > 2:
        __m128i vout = _mm_packs_epi16(vacc0${min(1, MR-1)}x0123, vacc${min(2, MR-1)}${min(3, MR-1)}x0123);
      $else:
        __m128i vout = _mm_packs_epi16(vacc0${min(1, MR-1)}x0123, vacc0${min(1, MR-1)}x0123);

      $if SSE == 4:
        vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->${PARAMS_STRUCT}.output_min));

    if (nc >= 4) {
      $for M in reversed(range(1, MR)):
        $if SSE == 4:
          unaligned_store_u32(c${M}, (uint32_t) _mm_extract_epi32(vout, ${M}));
        $else:
          unaligned_store_u32(c${M}, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(${M}, ${M}, ${M}, ${M}))));
        c${M} = (${XINT8_T}*) ((uintptr_t) c${M} + cn_stride);
      unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout));
      c0 = (${XINT8_T}*) ((uintptr_t) c0 + cn_stride);

      a = (const ${XINT8_T}**restrict) ((uintptr_t) a - ks);

      nc -= 4;
    } else {
      if (nc & 2) {
        $for M in reversed(range(MR)):
          unaligned_store_u16(c${M}, (uint16_t) _mm_extract_epi16(vout, ${M * 2}));
          c${M} += 2;
        vout = _mm_srli_epi32(vout, 16);
      }
      if (nc & 1) {
        $if SSE == 4:
          $for M in reversed(range(MR)):
            *c${M} = (${XINT8_T}) _mm_extract_epi8(vout, ${M * 4});
        $else:
          $for M in reversed(range(1, MR)):
            *c${M} = (${XINT8_T}) _mm_extract_epi16(vout, ${M * 2});
          *c0 = (${XINT8_T}) _mm_cvtsi128_si32(vout);
      }

      nc = 0;
    }
  } while (nc != 0);
}
