Debian Codegraph @

src/qs8-f32-vcvt/gen/qs8-f32-vcvt-sse2-u8.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_u8(
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 >= 8 * sizeof(int8_t); batch -= 8 * sizeof(int8_t)) {
40 __m128i vx = _mm_loadl_epi64((const __m128i*) input);
41 vx = _mm_xor_si128(vx, vsign_mask);
42 vx = _mm_unpacklo_epi8(vx, vzero);
43 input += 8;
44
45 __m128 vy_lo = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
46 __m128 vy_hi = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
47
48 vy_lo = _mm_sub_ps(vy_lo, vmagic_bias);
49 vy_hi = _mm_sub_ps(vy_hi, vmagic_bias);
50
51 vy_lo = _mm_mul_ps(vy_lo, vscale);
52 vy_hi = _mm_mul_ps(vy_hi, vscale);
53
54 _mm_storeu_ps(output, vy_lo);
55 _mm_storeu_ps(output + 4, vy_hi);
56 output += 8;
57 }
58 if XNN_UNLIKELY(batch != 0) {
59 assert(batch >= 1 * sizeof(int8_t));
60 assert(batch <= 7 * sizeof(int8_t));
61
62 __m128i vx = _mm_loadl_epi64((const __m128i*) input);
63 vx = _mm_xor_si128(vx, vsign_mask);
64 vx = _mm_unpacklo_epi8(vx, vzero);
65
66 __m128 vy = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
67 vy = _mm_sub_ps(vy, vmagic_bias);
68 vy = _mm_mul_ps(vy, vscale);
69
70 if (batch & (4 * sizeof(int8_t))) {
71 _mm_storeu_ps(output, vy);
72 vy = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
73 vy = _mm_sub_ps(vy, vmagic_bias);
74 vy = _mm_mul_ps(vy, vscale);
75 output += 4;
76 }
77 if (batch & (2 * sizeof(int8_t))) {
78 _mm_storel_pi((__m64*) output, vy);
79 vy = _mm_movehl_ps(vy, vy);
80 output += 2;
81 }
82 if (batch & (1 * sizeof(int8_t))) {
83 _mm_store_ss(output, vy);
84 }
85 }
86 }