Debian Codegraph @

src/qu8-f32-vcvt/gen/qu8-f32-vcvt-sse41-u32.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f32-vcvt/sse4.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__sse41_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 __m128i vzero_point = _mm_set1_epi32(params->scalar.zero_point);
31 const __m128 vscale = _mm_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 __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 __m128i vxOPQR = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 24)));
42 __m128i vxSTUV = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input + 28)));
43 input += 32;
44
45 vx0123 = _mm_sub_epi32(vx0123, vzero_point);
46 vx4567 = _mm_sub_epi32(vx4567, vzero_point);
47 vx89AB = _mm_sub_epi32(vx89AB, vzero_point);
48 vxCDEF = _mm_sub_epi32(vxCDEF, vzero_point);
49 vxGHIJ = _mm_sub_epi32(vxGHIJ, vzero_point);
50 vxKLMN = _mm_sub_epi32(vxKLMN, vzero_point);
51 vxOPQR = _mm_sub_epi32(vxOPQR, vzero_point);
52 vxSTUV = _mm_sub_epi32(vxSTUV, vzero_point);
53
54 __m128 vy0123 = _mm_cvtepi32_ps(vx0123);
55 __m128 vy4567 = _mm_cvtepi32_ps(vx4567);
56 __m128 vy89AB = _mm_cvtepi32_ps(vx89AB);
57 __m128 vyCDEF = _mm_cvtepi32_ps(vxCDEF);
58 __m128 vyGHIJ = _mm_cvtepi32_ps(vxGHIJ);
59 __m128 vyKLMN = _mm_cvtepi32_ps(vxKLMN);
60 __m128 vyOPQR = _mm_cvtepi32_ps(vxOPQR);
61 __m128 vySTUV = _mm_cvtepi32_ps(vxSTUV);
62
63 vy0123 = _mm_mul_ps(vy0123, vscale);
64 vy4567 = _mm_mul_ps(vy4567, vscale);
65 vy89AB = _mm_mul_ps(vy89AB, vscale);
66 vyCDEF = _mm_mul_ps(vyCDEF, vscale);
67 vyGHIJ = _mm_mul_ps(vyGHIJ, vscale);
68 vyKLMN = _mm_mul_ps(vyKLMN, vscale);
69 vyOPQR = _mm_mul_ps(vyOPQR, vscale);
70 vySTUV = _mm_mul_ps(vySTUV, vscale);
71
72 _mm_storeu_ps(output, vy0123);
73 _mm_storeu_ps(output + 4, vy4567);
74 _mm_storeu_ps(output + 8, vy89AB);
75 _mm_storeu_ps(output + 12, vyCDEF);
76 _mm_storeu_ps(output + 16, vyGHIJ);
77 _mm_storeu_ps(output + 20, vyKLMN);
78 _mm_storeu_ps(output + 24, vyOPQR);
79 _mm_storeu_ps(output + 28, vySTUV);
80 output += 32;
81 }
82 for (; batch >= 4 * sizeof(uint8_t); batch -= 4 * sizeof(uint8_t)) {
83 __m128i vx = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input)));
84 vx = _mm_sub_epi32(vx, vzero_point);
85 input += 4;
86
87 __m128 vy = _mm_cvtepi32_ps(vx);
88 vy = _mm_mul_ps(vy, vscale);
89
90 _mm_storeu_ps(output, vy);
91 output += 4;
92 }
93 if XNN_UNLIKELY(batch != 0) {
94 assert(batch >= 1 * sizeof(uint8_t));
95 assert(batch <= 3 * sizeof(uint8_t));
96
97 __m128i vx = _mm_cvtepu8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(input)));
98 vx = _mm_sub_epi32(vx, vzero_point);
99
100 __m128 vy = _mm_cvtepi32_ps(vx);
101 vy = _mm_mul_ps(vy, vscale);
102
103 if (batch & (2 * sizeof(uint8_t))) {
104 _mm_storel_pi((__m64*) output, vy);
105 vy = _mm_movehl_ps(vy, vy);
106 output += 2;
107 }
108 if (batch & (1 * sizeof(uint8_t))) {
109 _mm_store_ss(output, vy);
110 }
111 }
112 }