1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f32-vcvt/sse4.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 <immintrin.h>
13
14 #include <xnnpack/common.h>
15 #include <xnnpack/unaligned.h>
16 #include <xnnpack/vcvt.h>
17
18
xnn_qs8_f32_vcvt_ukernel__sse41_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__sse41_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 vminus_zero_point = _mm_load_si128((const __m128i*) params->sse4.minus_zero_point);
31 const __m128 vscale = _mm_load_ps(params->sse4.scale);
32 for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
33 __m128i vx0123 = _mm_cvtepi8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(x)));
34 __m128i vx4567 = _mm_cvtepi8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(x + 4)));
35 x += 8;
36
37 vx0123 = _mm_add_epi32(vx0123, vminus_zero_point);
38 vx4567 = _mm_add_epi32(vx4567, vminus_zero_point);
39
40 __m128 vy0123 = _mm_cvtepi32_ps(vx0123);
41 __m128 vy4567 = _mm_cvtepi32_ps(vx4567);
42
43 vy0123 = _mm_mul_ps(vy0123, vscale);
44 vy4567 = _mm_mul_ps(vy4567, vscale);
45
46 _mm_storeu_ps(y, vy0123);
47 _mm_storeu_ps(y + 4, vy4567);
48 y += 8;
49 }
50 for (; n >= 4 * sizeof(int8_t); n -= 4 * sizeof(int8_t)) {
51 __m128i vx = _mm_cvtepi8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(x)));
52 vx = _mm_add_epi32(vx, vminus_zero_point);
53 x += 4;
54
55 __m128 vy = _mm_cvtepi32_ps(vx);
56 vy = _mm_mul_ps(vy, vscale);
57
58 _mm_storeu_ps(y, vy);
59 y += 4;
60 }
61 if XNN_UNLIKELY(n != 0) {
62 assert(n >= 1 * sizeof(int8_t));
63 assert(n <= 3 * sizeof(int8_t));
64
65 __m128i vx = _mm_cvtepi8_epi32(_mm_cvtsi32_si128((int) unaligned_load_s32(x)));
66 vx = _mm_add_epi32(vx, vminus_zero_point);
67
68 __m128 vy = _mm_cvtepi32_ps(vx);
69 vy = _mm_mul_ps(vy, vscale);
70
71 if (n & (2 * sizeof(int8_t))) {
72 _mm_storel_pi((__m64*) y, vy);
73 vy = _mm_movehl_ps(vy, vy);
74 y += 2;
75 }
76 if (n & (1 * sizeof(int8_t))) {
77 _mm_store_ss(y, vy);
78 }
79 }
80 }
81