| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-f32-vcvt/avx2.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2021 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <immintrin.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/intrinsics-polyfill.h" |
| 16 |
#include "xnnpack/vcvt.h" |
| 17 |
|
| 18 |
|
| 19 |
void xnn_qu8_f32_vcvt_ukernel__avx2_u32( |
| 20 |
size_t batch, |
| 21 |
const uint8_t* input, |
| 22 |
float* output, |
| 23 |
const struct xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 24 |
{ |
| 25 |
assert(batch != 0); |
| 26 |
assert(batch % sizeof(uint8_t) == 0); |
| 27 |
assert(input != NULL); |
| 28 |
assert(output != NULL); |
| 29 |
|
| 30 |
const __m256i vzero_point = _mm256_set1_epi32(params->scalar.zero_point); |
| 31 |
const __m256 vscale = _mm256_set1_ps(params->scalar.scale); |
| 32 |
XNN_FORCE_REALIZATION(vzero_point); |
| 33 |
XNN_FORCE_REALIZATION(vscale); |
| 34 |
for (; batch >= 32 * sizeof(uint8_t); batch -= 32 * sizeof(uint8_t)) { |
| 35 |
__m256i vx01234567 = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*) input)); |
| 36 |
__m256i vx89ABCDEF = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*) (input + 8))); |
| 37 |
__m256i vxGHIJKLMN = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*) (input + 16))); |
| 38 |
__m256i vxOPQRSTUV = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*) (input + 24))); |
| 39 |
input += 32; |
| 40 |
|
| 41 |
vx01234567 = _mm256_sub_epi32(vx01234567, vzero_point); |
| 42 |
vx89ABCDEF = _mm256_sub_epi32(vx89ABCDEF, vzero_point); |
| 43 |
vxGHIJKLMN = _mm256_sub_epi32(vxGHIJKLMN, vzero_point); |
| 44 |
vxOPQRSTUV = _mm256_sub_epi32(vxOPQRSTUV, vzero_point); |
| 45 |
|
| 46 |
__m256 vy01234567 = _mm256_cvtepi32_ps(vx01234567); |
| 47 |
__m256 vy89ABCDEF = _mm256_cvtepi32_ps(vx89ABCDEF); |
| 48 |
__m256 vyGHIJKLMN = _mm256_cvtepi32_ps(vxGHIJKLMN); |
| 49 |
__m256 vyOPQRSTUV = _mm256_cvtepi32_ps(vxOPQRSTUV); |
| 50 |
|
| 51 |
vy01234567 = _mm256_mul_ps(vy01234567, vscale); |
| 52 |
vy89ABCDEF = _mm256_mul_ps(vy89ABCDEF, vscale); |
| 53 |
vyGHIJKLMN = _mm256_mul_ps(vyGHIJKLMN, vscale); |
| 54 |
vyOPQRSTUV = _mm256_mul_ps(vyOPQRSTUV, vscale); |
| 55 |
|
| 56 |
_mm256_storeu_ps(output, vy01234567); |
| 57 |
_mm256_storeu_ps(output + 8, vy89ABCDEF); |
| 58 |
_mm256_storeu_ps(output + 16, vyGHIJKLMN); |
| 59 |
_mm256_storeu_ps(output + 24, vyOPQRSTUV); |
| 60 |
output += 32; |
| 61 |
} |
| 62 |
for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) { |
| 63 |
__m256i vx = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*) input)); |
| 64 |
vx = _mm256_sub_epi32(vx, vzero_point); |
| 65 |
input += 8; |
| 66 |
|
| 67 |
__m256 vy = _mm256_cvtepi32_ps(vx); |
| 68 |
vy = _mm256_mul_ps(vy, vscale); |
| 69 |
|
| 70 |
_mm256_storeu_ps(output, vy); |
| 71 |
output += 8; |
| 72 |
} |
| 73 |
if XNN_UNLIKELY(batch != 0) { |
| 74 |
assert(batch >= 1 * sizeof(uint8_t)); |
| 75 |
assert(batch <= 7 * sizeof(uint8_t)); |
| 76 |
|
| 77 |
__m256i vx = _mm256_cvtepu8_epi32(_mm_loadl_epi64((const __m128i*) input)); |
| 78 |
vx = _mm256_sub_epi32(vx, vzero_point); |
| 79 |
|
| 80 |
__m256 vy = _mm256_cvtepi32_ps(vx); |
| 81 |
vy = _mm256_mul_ps(vy, vscale); |
| 82 |
|
| 83 |
__m128 vy_lo = _mm256_castps256_ps128(vy); |
| 84 |
if (batch & (4 * sizeof(uint8_t))) { |
| 85 |
_mm_storeu_ps(output, vy_lo); |
| 86 |
vy_lo = _mm256_extractf128_ps(vy, 1); |
| 87 |
output += 4; |
| 88 |
} |
| 89 |
if (batch & (2 * sizeof(uint8_t))) { |
| 90 |
_mm_storel_pi((__m64*) output, vy_lo); |
| 91 |
vy_lo = _mm_movehl_ps(vy_lo, vy_lo); |
| 92 |
output += 2; |
| 93 |
} |
| 94 |
if (batch & (1 * sizeof(uint8_t))) { |
| 95 |
_mm_store_ss(output, vy_lo); |
| 96 |
} |
| 97 |
} |
| 98 |
} |