blob: ad5324a48f0f55e9eed60ba621720fa9fe7fc470 [file] [log] [blame]
// Auto-generated file. Do not edit!
// Template: src/qs8-f32-vcvt/avx.c.in
// Generator: tools/xngen
//
// 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.
#include <assert.h>
#include <immintrin.h>
#include <xnnpack/common.h>
#include <xnnpack/intrinsics-polyfill.h>
#include <xnnpack/vcvt.h>
void xnn_qu8_f32_vcvt_ukernel__avx_x8(
size_t n,
const uint8_t* x,
float* y,
const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
{
assert(n != 0);
assert(n % sizeof(uint8_t) == 0);
assert(x != NULL);
assert(y != NULL);
const __m128i vminus_zero_point = _mm_load_si128((const __m128i*) params->avx.minus_zero_point);
const __m256 vscale = _mm256_load_ps(params->avx.scale);
for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
__m128i vx0123 = _mm_cvtepu8_epi32(_mm_loadu_si32(x));
__m128i vx4567 = _mm_cvtepu8_epi32(_mm_loadu_si32(x + 4));
x += 8;
vx0123 = _mm_add_epi32(vx0123, vminus_zero_point);
vx4567 = _mm_add_epi32(vx4567, vminus_zero_point);
const __m256i vx01234567 = _mm256_insertf128_si256(_mm256_castsi128_si256(vx0123), vx4567, 1);
__m256 vy01234567 = _mm256_cvtepi32_ps(vx01234567);
vy01234567 = _mm256_mul_ps(vy01234567, vscale);
_mm256_storeu_ps(y, vy01234567);
y += 8;
}
for (; n >= 4 * sizeof(uint8_t); n -= 4 * sizeof(uint8_t)) {
__m128i vx = _mm_cvtepu8_epi32(_mm_loadu_si32(x));
vx = _mm_add_epi32(vx, vminus_zero_point);
x += 4;
__m128 vy = _mm_cvtepi32_ps(vx);
vy = _mm_mul_ps(vy, _mm256_castps256_ps128(vscale));
_mm_storeu_ps(y, vy);
y += 4;
}
if XNN_UNLIKELY(n != 0) {
assert(n >= 1 * sizeof(uint8_t));
assert(n <= 3 * sizeof(uint8_t));
__m128i vx = _mm_cvtepu8_epi32(_mm_loadu_si32(x));
vx = _mm_add_epi32(vx, vminus_zero_point);
__m128 vy = _mm_cvtepi32_ps(vx);
vy = _mm_mul_ps(vy, _mm256_castps256_ps128(vscale));
if (n & (2 * sizeof(uint8_t))) {
_mm_storel_pi((__m64*) y, vy);
vy = _mm_movehl_ps(vy, vy);
y += 2;
}
if (n & (1 * sizeof(uint8_t))) {
_mm_store_ss(y, vy);
}
}
}