1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vaddc/sse-mul32-ld32.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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 #ifdef __GNUC__
13 #include <x86intrin.h>
14 #else
15 #include <immintrin.h>
16 #include <ammintrin.h>
17 #endif
18
19 #include <xnnpack/intrinsics-polyfill.h>
20 #include <xnnpack/vadd.h>
21
22
xnn_qs8_vaddc_minmax_ukernel__xop_mul32_ld32_x24(size_t n,const int8_t * input_x,const int8_t * input_y,int8_t * output,const union xnn_qs8_add_params params[restrict XNN_MIN_ELEMENTS (1)])23 void xnn_qs8_vaddc_minmax_ukernel__xop_mul32_ld32_x24(
24 size_t n,
25 const int8_t* input_x,
26 const int8_t* input_y,
27 int8_t* output,
28 const union xnn_qs8_add_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
29 {
30 const __m128i vx_multiplier = _mm_load_si128((const __m128i*) params->sse2.x_multiplier);
31 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->sse2.remainder_mask);
32 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->sse2.remainder_threshold);
33 const __m128i vshift = _mm_cvtsi32_si128((int) params->sse2.shift);
34 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
35 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
36 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
37
38 __m128i vzero_point_product = _mm_cvtsi32_si128(params->sse2.y_multiplier[0] * (int32_t) *input_y);
39 vzero_point_product = _mm_shuffle_epi32(vzero_point_product, _MM_SHUFFLE(0, 0, 0, 0));
40 vzero_point_product = _mm_add_epi32(vzero_point_product, _mm_load_si128((const __m128i*) params->sse2.zero_point_product));
41 for (; n >= 24 * sizeof(int8_t); n -= 24 * sizeof(int8_t)) {
42 const __m128i vx0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x));
43 const __m128i vx4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 4));
44 const __m128i vx89AB = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 8));
45 const __m128i vxCDEF = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 12));
46 const __m128i vxGHIJ = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 16));
47 const __m128i vxKLMN = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 20));
48 input_x += 24;
49 input_y += 24;
50
51 __m128i vacc0123 = _mm_macc_epi32(vx0123, vx_multiplier, vzero_point_product);
52 __m128i vacc4567 = _mm_macc_epi32(vx4567, vx_multiplier, vzero_point_product);
53 __m128i vacc89AB = _mm_macc_epi32(vx89AB, vx_multiplier, vzero_point_product);
54 __m128i vaccCDEF = _mm_macc_epi32(vxCDEF, vx_multiplier, vzero_point_product);
55 __m128i vaccGHIJ = _mm_macc_epi32(vxGHIJ, vx_multiplier, vzero_point_product);
56 __m128i vaccKLMN = _mm_macc_epi32(vxKLMN, vx_multiplier, vzero_point_product);
57
58 const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123));
59 const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567));
60 const __m128i vrem89AB = _mm_add_epi32(_mm_and_si128(vacc89AB, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc89AB));
61 const __m128i vremCDEF = _mm_add_epi32(_mm_and_si128(vaccCDEF, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccCDEF));
62 const __m128i vremGHIJ = _mm_add_epi32(_mm_and_si128(vaccGHIJ, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccGHIJ));
63 const __m128i vremKLMN = _mm_add_epi32(_mm_and_si128(vaccKLMN, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccKLMN));
64
65 vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
66 vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
67 vacc89AB = _mm_sub_epi32(_mm_sra_epi32(vacc89AB, vshift), _mm_cmpgt_epi32(vrem89AB, vremainder_threshold));
68 vaccCDEF = _mm_sub_epi32(_mm_sra_epi32(vaccCDEF, vshift), _mm_cmpgt_epi32(vremCDEF, vremainder_threshold));
69 vaccGHIJ = _mm_sub_epi32(_mm_sra_epi32(vaccGHIJ, vshift), _mm_cmpgt_epi32(vremGHIJ, vremainder_threshold));
70 vaccKLMN = _mm_sub_epi32(_mm_sra_epi32(vaccKLMN, vshift), _mm_cmpgt_epi32(vremKLMN, vremainder_threshold));
71
72 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
73 __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point);
74 __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point);
75
76 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
77 vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min);
78 voutGHIJKLMN = _mm_max_epi16(voutGHIJKLMN, voutput_min);
79
80 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
81 vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max);
82 voutGHIJKLMN = _mm_min_epi16(voutGHIJKLMN, voutput_max);
83
84 const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
85 const __m128i voutGHIJKLMNGHIJKLMN = _mm_packs_epi16(voutGHIJKLMN, voutGHIJKLMN);
86
87 _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF);
88 _mm_storel_epi64((__m128i*) (output + 16), voutGHIJKLMNGHIJKLMN);
89 output += 24;
90 }
91 if XNN_UNLIKELY(n != 0) {
92 do {
93 const __m128i vx0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x));
94 const __m128i vx4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 4));
95 input_x += 8;
96
97 __m128i vacc0123 = _mm_macc_epi32(vx0123, vx_multiplier, vzero_point_product);
98 __m128i vacc4567 = _mm_macc_epi32(vx4567, vx_multiplier, vzero_point_product);
99
100 const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123));
101 const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567));
102
103 vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
104 vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
105
106 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
107 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
108 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
109
110 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
111
112 if XNN_LIKELY(n >= (8 * sizeof(int8_t))) {
113 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
114 output += 8;
115 n -= 8 * sizeof(int8_t);
116 } else {
117 if (n & (4 * sizeof(int8_t))) {
118 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
119 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
120 output += 4;
121 }
122 if (n & (2 * sizeof(int8_t))) {
123 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
124 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
125 output += 2;
126 }
127 if (n & (1 * sizeof(int8_t))) {
128 *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0);
129 }
130 n = 0;
131 }
132 } while (n != 0);
133 }
134 }
135