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
xnn_qs8_f32_vcvt_ukernel__sse2_x8(size_t n,const int8_t * x,float * y,const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qs8_f32_vcvt_ukernel__sse2_x8(
20 size_t n,
21 const int8_t* x,
22 float* y,
23 const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(int8_t) == 0);
27 assert(x != NULL);
28 assert(y != NULL);
29
30 const __m128i vsign_mask = _mm_load_si128((const __m128i*) params->sse2.sign_mask);
31 const __m128i vmagic_exp = _mm_load_si128((const __m128i*) params->sse2.magic_exp);
32 const __m128 vmagic_bias = _mm_load_ps(params->sse2.magic_bias);
33 const __m128 vscale = _mm_load_ps(params->sse2.scale);
34 const __m128i vzero = _mm_setzero_si128();
35 for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
36 __m128i vx = _mm_loadl_epi64((const __m128i*) x);
37 vx = _mm_xor_si128(vx, vsign_mask);
38 vx = _mm_unpacklo_epi8(vx, vzero);
39 x += 8;
40
41 __m128 vy_lo = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
42 __m128 vy_hi = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
43
44 vy_lo = _mm_sub_ps(vy_lo, vmagic_bias);
45 vy_hi = _mm_sub_ps(vy_hi, vmagic_bias);
46
47 vy_lo = _mm_mul_ps(vy_lo, vscale);
48 vy_hi = _mm_mul_ps(vy_hi, vscale);
49
50 _mm_storeu_ps(y, vy_lo);
51 _mm_storeu_ps(y + 4, vy_hi);
52 y += 8;
53 }
54 if XNN_UNLIKELY(n != 0) {
55 assert(n >= 1 * sizeof(int8_t));
56 assert(n <= 7 * sizeof(int8_t));
57
58 __m128i vx = _mm_loadl_epi64((const __m128i*) x);
59 vx = _mm_xor_si128(vx, vsign_mask);
60 vx = _mm_unpacklo_epi8(vx, vzero);
61
62 __m128 vy = _mm_castsi128_ps(_mm_unpacklo_epi16(vx, vmagic_exp));
63 vy = _mm_sub_ps(vy, vmagic_bias);
64 vy = _mm_mul_ps(vy, vscale);
65
66 if (n & (4 * sizeof(int8_t))) {
67 _mm_storeu_ps(y, vy);
68 vy = _mm_castsi128_ps(_mm_unpackhi_epi16(vx, vmagic_exp));
69 vy = _mm_sub_ps(vy, vmagic_bias);
70 vy = _mm_mul_ps(vy, vscale);
71 y += 4;
72 }
73 if (n & (2 * sizeof(int8_t))) {
74 _mm_storel_pi((__m64*) y, vy);
75 vy = _mm_movehl_ps(vy, vy);
76 y += 2;
77 }
78 if (n & (1 * sizeof(int8_t))) {
79 _mm_store_ss(y, vy);
80 }
81 }
82 }
83