1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vadd/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 #include <immintrin.h>
13
14 #include <xnnpack/intrinsics-polyfill.h>
15 #include <xnnpack/vadd.h>
16
17
xnn_qs8_vadd_minmax_ukernel__sse41_mul32_ld32_x8(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)])18 void xnn_qs8_vadd_minmax_ukernel__sse41_mul32_ld32_x8(
19 size_t n,
20 const int8_t* input_x,
21 const int8_t* input_y,
22 int8_t* output,
23 const union xnn_qs8_add_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
24 {
25 const __m128i vzero_point_product = _mm_load_si128((const __m128i*) params->sse2.zero_point_product);
26 const __m128i vx_multiplier = _mm_load_si128((const __m128i*) params->sse2.x_multiplier);
27 const __m128i vy_multiplier = _mm_load_si128((const __m128i*) params->sse2.y_multiplier);
28 const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->sse2.remainder_mask);
29 const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->sse2.remainder_threshold);
30 const __m128i vshift = _mm_cvtsi32_si128((int) params->sse2.shift);
31 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
32 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
33 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
34
35 for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
36 const __m128i vx0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x));
37 const __m128i vy0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_y));
38 const __m128i vx4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 4));
39 const __m128i vy4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_y + 4));
40 input_x += 8;
41 input_y += 8;
42
43 __m128i vacc0123 = _mm_add_epi32(vzero_point_product, _mm_mullo_epi32(vx0123, vx_multiplier));
44 __m128i vacc4567 = _mm_add_epi32(vzero_point_product, _mm_mullo_epi32(vx4567, vx_multiplier));
45
46 vacc0123 = _mm_add_epi32(vacc0123, _mm_mullo_epi32(vy0123, vy_multiplier));
47 vacc4567 = _mm_add_epi32(vacc4567, _mm_mullo_epi32(vy4567, vy_multiplier));
48
49 const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123));
50 const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567));
51
52 vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
53 vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
54
55 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
56
57 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
58
59 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
60
61 const __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
62
63 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
64 output += 8;
65 }
66 if XNN_UNLIKELY(n != 0) {
67 {
68 const __m128i vx0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x));
69 const __m128i vy0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_y));
70 const __m128i vx4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_x + 4));
71 const __m128i vy4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_y + 4));
72
73 __m128i vacc0123 = _mm_add_epi32(vzero_point_product, _mm_mullo_epi32(vx0123, vx_multiplier));
74 __m128i vacc4567 = _mm_add_epi32(vzero_point_product, _mm_mullo_epi32(vx4567, vx_multiplier));
75
76 vacc0123 = _mm_add_epi32(vacc0123, _mm_mullo_epi32(vy0123, vy_multiplier));
77 vacc4567 = _mm_add_epi32(vacc4567, _mm_mullo_epi32(vy4567, vy_multiplier));
78
79 const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123));
80 const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567));
81
82 vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
83 vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
84
85 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
86 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
87 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
88
89 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
90
91 if (n & (4 * sizeof(int8_t))) {
92 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
93 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
94 output += 4;
95 }
96 if (n & (2 * sizeof(int8_t))) {
97 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
98 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
99 output += 2;
100 }
101 if (n & (1 * sizeof(int8_t))) {
102 *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0);
103 }
104 }
105 }
106 }
107