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