Debian Codegraph @

src/qu8-f32-vcvt/gen/qu8-f32-vcvt-avx-u24.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f32-vcvt/avx.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/unaligned.h"
16 #include "xnnpack/vcvt.h"
17
18
19 void xnn_qu8_f32_vcvt_ukernel__avx_u24(
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 __m128i vzero_point = _mm_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 >= 24 * sizeof(uint8_t); batch -= 24 * sizeof(uint8_t)) {
35 __m128i vx0123 = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input)));
36 __m128i vx4567 = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 4)));
37 __m128i vx89AB = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 8)));
38 __m128i vxCDEF = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 12)));
39 __m128i vxGHIJ = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 16)));
40 __m128i vxKLMN = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 20)));
41 input += 24;
42
43 vx0123 = _mm_sub_epi32(vx0123, vzero_point);
44 vx4567 = _mm_sub_epi32(vx4567, vzero_point);
45 vx89AB = _mm_sub_epi32(vx89AB, vzero_point);
46 vxCDEF = _mm_sub_epi32(vxCDEF, vzero_point);
47 vxGHIJ = _mm_sub_epi32(vxGHIJ, vzero_point);
48 vxKLMN = _mm_sub_epi32(vxKLMN, vzero_point);
49
50 const __m256i vx01234567 = _mm256_insertf128_si256(_mm256_castsi128_si256(vx0123), vx4567, 1);
51 const __m256i vx89ABCDEF = _mm256_insertf128_si256(_mm256_castsi128_si256(vx89AB), vxCDEF, 1);
52 const __m256i vxGHIJKLMN = _mm256_insertf128_si256(_mm256_castsi128_si256(vxGHIJ), vxKLMN, 1);
53
54 __m256 vy01234567 = _mm256_cvtepi32_ps(vx01234567);
55 __m256 vy89ABCDEF = _mm256_cvtepi32_ps(vx89ABCDEF);
56 __m256 vyGHIJKLMN = _mm256_cvtepi32_ps(vxGHIJKLMN);
57
58 vy01234567 = _mm256_mul_ps(vy01234567, vscale);
59 vy89ABCDEF = _mm256_mul_ps(vy89ABCDEF, vscale);
60 vyGHIJKLMN = _mm256_mul_ps(vyGHIJKLMN, vscale);
61
62 _mm256_storeu_ps(output, vy01234567);
63 _mm256_storeu_ps(output + 8, vy89ABCDEF);
64 _mm256_storeu_ps(output + 16, vyGHIJKLMN);
65 output += 24;
66 }
67 for (; batch >= 4 * sizeof(uint8_t); batch -= 4 * sizeof(uint8_t)) {
68 __m128i vx = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input)));
69 vx = _mm_sub_epi32(vx, vzero_point);
70 input += 4;
71
72 __m128 vy = _mm_cvtepi32_ps(vx);
73 vy = _mm_mul_ps(vy, _mm256_castps256_ps128(vscale));
74
75 _mm_storeu_ps(output, vy);
76 output += 4;
77 }
78 if XNN_UNLIKELY(batch != 0) {
79 assert(batch >= 1 * sizeof(uint8_t));
80 assert(batch <= 3 * sizeof(uint8_t));
81
82 __m128i vx = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input)));
83 vx = _mm_sub_epi32(vx, vzero_point);
84
85 __m128 vy = _mm_cvtepi32_ps(vx);
86 vy = _mm_mul_ps(vy, _mm256_castps256_ps128(vscale));
87
88 if (batch & (2 * sizeof(uint8_t))) {
89 _mm_storel_pi((__m64*) output, vy);
90 vy = _mm_movehl_ps(vy, vy);
91 output += 2;
92 }
93 if (batch & (1 * sizeof(uint8_t))) {
94 _mm_store_ss(output, vy);
95 }
96 }
97 }