Debian Codegraph @

src/qu8-f32-vcvt/gen/qu8-f32-vcvt-sse2-u16.c

raw
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_qu8_f32_vcvt_ukernel__sse2_u16(
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 vmagic_exp = _mm_set1_epi16(UINT16_C(0x4B00));
31 const __m128 vmagic_bias = _mm_set1_ps((float) (INT32_C(0x00800000) + (int32_t) params->scalar.zero_point));
32 const __m128 vscale = _mm_set1_ps(params->scalar.scale);
33 const __m128i vzero = _mm_setzero_si128();
34 XNN_FORCE_REALIZATION(vmagic_exp);
35 XNN_FORCE_REALIZATION(vmagic_bias);
36 XNN_FORCE_REALIZATION(vscale);
37 for (; batch >= 16 * sizeof(uint8_t); batch -= 16 * sizeof(uint8_t)) {
38 __m128i vx01234567 = _mm_loadl_epi64((const __m128i*) input);
39 __m128i vx89ABCDEF = _mm_loadl_epi64((const __m128i*) (input + 8));
40 input += 16;
41
42
43 vx01234567 = _mm_unpacklo_epi8(vx01234567, vzero);
44 vx89ABCDEF = _mm_unpacklo_epi8(vx89ABCDEF, vzero);
45
46 __m128 vy0123 = _mm_castsi128_ps(_mm_unpacklo_epi16(vx01234567, vmagic_exp));
47 __m128 vy4567 = _mm_castsi128_ps(_mm_unpackhi_epi16(vx01234567, vmagic_exp));
48 __m128 vy89AB = _mm_castsi128_ps(_mm_unpacklo_epi16(vx89ABCDEF, vmagic_exp));
49 __m128 vyCDEF = _mm_castsi128_ps(_mm_unpackhi_epi16(vx89ABCDEF, vmagic_exp));
50
51 vy0123 = _mm_sub_ps(vy0123, vmagic_bias);
52 vy4567 = _mm_sub_ps(vy4567, vmagic_bias);
53 vy89AB = _mm_sub_ps(vy89AB, vmagic_bias);
54 vyCDEF = _mm_sub_ps(vyCDEF, vmagic_bias);
55
56 vy0123 = _mm_mul_ps(vy0123, vscale);
57 vy4567 = _mm_mul_ps(vy4567, vscale);
58 vy89AB = _mm_mul_ps(vy89AB, vscale);
59 vyCDEF = _mm_mul_ps(vyCDEF, vscale);
60
61 _mm_storeu_ps(output, vy0123);
62 _mm_storeu_ps(output + 4, vy4567);
63 _mm_storeu_ps(output + 8, vy89AB);
64 _mm_storeu_ps(output + 12, vyCDEF);
65 output += 16;
66 }
67 for (; batch >= 8 * sizeof(uint8_t); batch -= 8 * sizeof(uint8_t)) {
68 __m128i vx = _mm_loadl_epi64((const __m128i*) input);
69 vx = _mm_unpacklo_epi8(vx, vzero);
70 input += 8;
71
72 __m128 vy_lo = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
73 __m128 vy_hi = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
74
75 vy_lo = _mm_sub_ps(vy_lo, vmagic_bias);
76 vy_hi = _mm_sub_ps(vy_hi, vmagic_bias);
77
78 vy_lo = _mm_mul_ps(vy_lo, vscale);
79 vy_hi = _mm_mul_ps(vy_hi, vscale);
80
81 _mm_storeu_ps(output, vy_lo);
82 _mm_storeu_ps(output + 4, vy_hi);
83 output += 8;
84 }
85 if XNN_UNLIKELY(batch != 0) {
86 assert(batch >= 1 * sizeof(uint8_t));
87 assert(batch <= 7 * sizeof(uint8_t));
88
89 __m128i vx = _mm_loadl_epi64((const __m128i*) input);
90 vx = _mm_unpacklo_epi8(vx, vzero);
91
92 __m128 vy = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
93 vy = _mm_sub_ps(vy, vmagic_bias);
94 vy = _mm_mul_ps(vy, vscale);
95
96 if (batch & (4 * sizeof(uint8_t))) {
97 _mm_storeu_ps(output, vy);
98 vy = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
99 vy = _mm_sub_ps(vy, vmagic_bias);
100 vy = _mm_mul_ps(vy, vscale);
101 output += 4;
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 }