1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vcvt/sse4.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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/intrinsics-polyfill.h>
16 #include <xnnpack/vcvt.h>
17
18
xnn_qs8_vcvt_ukernel__avx_x8(size_t n,const int8_t * x,int8_t * y,const union xnn_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qs8_vcvt_ukernel__avx_x8(
20 size_t n,
21 const int8_t* x,
22 int8_t* y,
23 const union xnn_qs8_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 vinput_zero_point = _mm_load_si128((const __m128i*) params->ssse3.input_zero_point);
31 const __m128i vmultiplier = _mm_load_si128((const __m128i*) params->ssse3.multiplier);
32 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->ssse3.output_zero_point);
33 for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
34 __m128i vacc = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) x));
35 vacc = _mm_sub_epi16(vinput_zero_point, vacc);
36 vacc = _mm_slli_epi16(vacc, 7);
37 vacc = _mm_mulhrs_epi16(vacc, vmultiplier);
38 vacc = _mm_adds_epi16(vacc, voutput_zero_point);
39 x += 8;
40
41 const __m128i vy = _mm_packs_epi16(vacc, vacc);
42 _mm_storel_epi64((__m128i*) y, vy);
43 y += 8;
44 }
45 if XNN_UNLIKELY(n != 0) {
46 assert(n >= 1 * sizeof(int8_t));
47 assert(n <= 7 * sizeof(int8_t));
48
49 __m128i vacc = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) x));
50 vacc = _mm_sub_epi16(vinput_zero_point, vacc);
51 vacc = _mm_slli_epi16(vacc, 7);
52 vacc = _mm_mulhrs_epi16(vacc, vmultiplier);
53 vacc = _mm_adds_epi16(vacc, voutput_zero_point);
54
55 __m128i vy = _mm_packs_epi16(vacc, vacc);
56 if (n & (4 * sizeof(int8_t))) {
57 _mm_storeu_si32(y, vy);
58 vy = _mm_srli_epi64(vy, 32);
59 y += 4;
60 }
61 if (n & (2 * sizeof(int8_t))) {
62 _mm_storeu_si16(y, vy);
63 vy = _mm_srli_epi32(vy, 16);
64 y += 2;
65 }
66 if (n & (1 * sizeof(int8_t))) {
67 *y = (int8_t) _mm_extract_epi8(vy, 0);
68 }
69 }
70 }
71