Debian Codegraph @

src/qs8-f32-vcvt/gen/qs8-f32-vcvt-sse2-u32.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f32-vcvt/sse2.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 <emmintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/vcvt.h"
17
18
19 void xnn_qs8_f32_vcvt_ukernel__sse2_u32(
20 size_t batch,
21 const int8_t* input,
22 float* output,
23 const struct xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(int8_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 const __m128i vsign_mask = _mm_set1_epi8(UINT8_C(0x80));
31 XNN_FORCE_REALIZATION(vsign_mask);
32 const __m128i vmagic_exp = _mm_set1_epi16(UINT16_C(0x4B00));
33 const __m128 vmagic_bias = _mm_set1_ps((float) (INT32_C(0x00800080) + (int32_t) params->scalar.zero_point));
34 const __m128 vscale = _mm_set1_ps(params->scalar.scale);
35 const __m128i vzero = _mm_setzero_si128();
36 XNN_FORCE_REALIZATION(vmagic_exp);
37 XNN_FORCE_REALIZATION(vmagic_bias);
38 XNN_FORCE_REALIZATION(vscale);
39 for (; batch >= 32 * sizeof(int8_t); batch -= 32 * sizeof(int8_t)) {
40 __m128i vx01234567 = _mm_loadl_epi64((const __m128i*) input);
41 __m128i vx89ABCDEF = _mm_loadl_epi64((const __m128i*) (input + 8));
42 __m128i vxGHIJKLMN = _mm_loadl_epi64((const __m128i*) (input + 16));
43 __m128i vxOPQRSTUV = _mm_loadl_epi64((const __m128i*) (input + 24));
44 input += 32;
45
46 vx01234567 = _mm_xor_si128(vx01234567, vsign_mask);
47 vx89ABCDEF = _mm_xor_si128(vx89ABCDEF, vsign_mask);
48 vxGHIJKLMN = _mm_xor_si128(vxGHIJKLMN, vsign_mask);
49 vxOPQRSTUV = _mm_xor_si128(vxOPQRSTUV, vsign_mask);
50
51 vx01234567 = _mm_unpacklo_epi8(vx01234567, vzero);
52 vx89ABCDEF = _mm_unpacklo_epi8(vx89ABCDEF, vzero);
53 vxGHIJKLMN = _mm_unpacklo_epi8(vxGHIJKLMN, vzero);
54 vxOPQRSTUV = _mm_unpacklo_epi8(vxOPQRSTUV, vzero);
55
56 __m128 vy0123 = _mm_castsi128_ps(_mm_unpacklo_epi16(vx01234567, vmagic_exp));
57 __m128 vy4567 = _mm_castsi128_ps(_mm_unpackhi_epi16(vx01234567, vmagic_exp));
58 __m128 vy89AB = _mm_castsi128_ps(_mm_unpacklo_epi16(vx89ABCDEF, vmagic_exp));
59 __m128 vyCDEF = _mm_castsi128_ps(_mm_unpackhi_epi16(vx89ABCDEF, vmagic_exp));
60 __m128 vyGHIJ = _mm_castsi128_ps(_mm_unpacklo_epi16(vxGHIJKLMN, vmagic_exp));
61 __m128 vyKLMN = _mm_castsi128_ps(_mm_unpackhi_epi16(vxGHIJKLMN, vmagic_exp));
62 __m128 vyOPQR = _mm_castsi128_ps(_mm_unpacklo_epi16(vxOPQRSTUV, vmagic_exp));
63 __m128 vySTUV = _mm_castsi128_ps(_mm_unpackhi_epi16(vxOPQRSTUV, vmagic_exp));
64
65 vy0123 = _mm_sub_ps(vy0123, vmagic_bias);
66 vy4567 = _mm_sub_ps(vy4567, vmagic_bias);
67 vy89AB = _mm_sub_ps(vy89AB, vmagic_bias);
68 vyCDEF = _mm_sub_ps(vyCDEF, vmagic_bias);
69 vyGHIJ = _mm_sub_ps(vyGHIJ, vmagic_bias);
70 vyKLMN = _mm_sub_ps(vyKLMN, vmagic_bias);
71 vyOPQR = _mm_sub_ps(vyOPQR, vmagic_bias);
72 vySTUV = _mm_sub_ps(vySTUV, vmagic_bias);
73
74 vy0123 = _mm_mul_ps(vy0123, vscale);
75 vy4567 = _mm_mul_ps(vy4567, vscale);
76 vy89AB = _mm_mul_ps(vy89AB, vscale);
77 vyCDEF = _mm_mul_ps(vyCDEF, vscale);
78 vyGHIJ = _mm_mul_ps(vyGHIJ, vscale);
79 vyKLMN = _mm_mul_ps(vyKLMN, vscale);
80 vyOPQR = _mm_mul_ps(vyOPQR, vscale);
81 vySTUV = _mm_mul_ps(vySTUV, vscale);
82
83 _mm_storeu_ps(output, vy0123);
84 _mm_storeu_ps(output + 4, vy4567);
85 _mm_storeu_ps(output + 8, vy89AB);
86 _mm_storeu_ps(output + 12, vyCDEF);
87 _mm_storeu_ps(output + 16, vyGHIJ);
88 _mm_storeu_ps(output + 20, vyKLMN);
89 _mm_storeu_ps(output + 24, vyOPQR);
90 _mm_storeu_ps(output + 28, vySTUV);
91 output += 32;
92 }
93 for (; batch >= 8 * sizeof(int8_t); batch -= 8 * sizeof(int8_t)) {
94 __m128i vx = _mm_loadl_epi64((const __m128i*) input);
95 vx = _mm_xor_si128(vx, vsign_mask);
96 vx = _mm_unpacklo_epi8(vx, vzero);
97 input += 8;
98
99 __m128 vy_lo = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
100 __m128 vy_hi = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
101
102 vy_lo = _mm_sub_ps(vy_lo, vmagic_bias);
103 vy_hi = _mm_sub_ps(vy_hi, vmagic_bias);
104
105 vy_lo = _mm_mul_ps(vy_lo, vscale);
106 vy_hi = _mm_mul_ps(vy_hi, vscale);
107
108 _mm_storeu_ps(output, vy_lo);
109 _mm_storeu_ps(output + 4, vy_hi);
110 output += 8;
111 }
112 if XNN_UNLIKELY(batch != 0) {
113 assert(batch >= 1 * sizeof(int8_t));
114 assert(batch <= 7 * sizeof(int8_t));
115
116 __m128i vx = _mm_loadl_epi64((const __m128i*) input);
117 vx = _mm_xor_si128(vx, vsign_mask);
118 vx = _mm_unpacklo_epi8(vx, vzero);
119
120 __m128 vy = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
121 vy = _mm_sub_ps(vy, vmagic_bias);
122 vy = _mm_mul_ps(vy, vscale);
123
124 if (batch & (4 * sizeof(int8_t))) {
125 _mm_storeu_ps(output, vy);
126 vy = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
127 vy = _mm_sub_ps(vy, vmagic_bias);
128 vy = _mm_mul_ps(vy, vscale);
129 output += 4;
130 }
131 if (batch & (2 * sizeof(int8_t))) {
132 _mm_storel_pi((__m64*) output, vy);
133 vy = _mm_movehl_ps(vy, vy);
134 output += 2;
135 }
136 if (batch & (1 * sizeof(int8_t))) {
137 _mm_store_ss(output, vy);
138 }
139 }
140 }