blob: 3c316223132b15a23d1eb4a0b79e0a9610bf40e6 [file] [log] [blame]
Marat Dukhane9c4b962021-04-02 16:56:55 -07001// 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
18void xnn_qs8_vadd_minmax_ukernel__avx_mul32_ld32_x32(
19 size_t n,
Marat Dukhan076bcfe2021-07-19 19:24:42 -070020 const int8_t* input_a,
21 const int8_t* input_b,
Marat Dukhane9c4b962021-04-02 16:56:55 -070022 int8_t* output,
Marat Dukhan6c7b9e82021-07-22 13:14:07 -070023 const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN XNN_DISABLE_MSAN
Marat Dukhane9c4b962021-04-02 16:56:55 -070024{
Marat Dukhan7679b1e2021-07-20 18:32:23 -070025 const __m128i vbias = _mm_load_si128((const __m128i*) params->sse4_mul32.bias);
26 const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse4_mul32.a_multiplier);
27 const __m128i vb_multiplier = _mm_load_si128((const __m128i*) params->sse4_mul32.b_multiplier);
28 const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse4_mul32.rounding);
29 const __m128i vshift = _mm_loadu_si32(params->sse4_mul32.shift);
30 const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse4_mul32.output_zero_point);
31 const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse4_mul32.output_min);
32 const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse4_mul32.output_max);
Marat Dukhane9c4b962021-04-02 16:56:55 -070033
34 for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) {
Marat Dukhan076bcfe2021-07-19 19:24:42 -070035 const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a));
36 const __m128i vb0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b));
37 const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4));
38 const __m128i vb4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 4));
39 const __m128i va89AB = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 8));
40 const __m128i vb89AB = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 8));
41 const __m128i vaCDEF = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 12));
42 const __m128i vbCDEF = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 12));
43 const __m128i vaGHIJ = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 16));
44 const __m128i vbGHIJ = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 16));
45 const __m128i vaKLMN = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 20));
46 const __m128i vbKLMN = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 20));
47 const __m128i vaOPQR = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 24));
48 const __m128i vbOPQR = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 24));
49 const __m128i vaSTUV = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 28));
50 const __m128i vbSTUV = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 28));
51 input_a += 32;
52 input_b += 32;
Marat Dukhane9c4b962021-04-02 16:56:55 -070053
Marat Dukhana842fef2021-07-19 21:07:40 -070054 __m128i vacc0123 = _mm_add_epi32(vbias, _mm_mullo_epi32(va0123, va_multiplier));
55 __m128i vacc4567 = _mm_add_epi32(vbias, _mm_mullo_epi32(va4567, va_multiplier));
56 __m128i vacc89AB = _mm_add_epi32(vbias, _mm_mullo_epi32(va89AB, va_multiplier));
57 __m128i vaccCDEF = _mm_add_epi32(vbias, _mm_mullo_epi32(vaCDEF, va_multiplier));
58 __m128i vaccGHIJ = _mm_add_epi32(vbias, _mm_mullo_epi32(vaGHIJ, va_multiplier));
59 __m128i vaccKLMN = _mm_add_epi32(vbias, _mm_mullo_epi32(vaKLMN, va_multiplier));
60 __m128i vaccOPQR = _mm_add_epi32(vbias, _mm_mullo_epi32(vaOPQR, va_multiplier));
61 __m128i vaccSTUV = _mm_add_epi32(vbias, _mm_mullo_epi32(vaSTUV, va_multiplier));
Marat Dukhane9c4b962021-04-02 16:56:55 -070062
Marat Dukhan076bcfe2021-07-19 19:24:42 -070063 vacc0123 = _mm_add_epi32(vacc0123, _mm_mullo_epi32(vb0123, vb_multiplier));
64 vacc4567 = _mm_add_epi32(vacc4567, _mm_mullo_epi32(vb4567, vb_multiplier));
65 vacc89AB = _mm_add_epi32(vacc89AB, _mm_mullo_epi32(vb89AB, vb_multiplier));
66 vaccCDEF = _mm_add_epi32(vaccCDEF, _mm_mullo_epi32(vbCDEF, vb_multiplier));
67 vaccGHIJ = _mm_add_epi32(vaccGHIJ, _mm_mullo_epi32(vbGHIJ, vb_multiplier));
68 vaccKLMN = _mm_add_epi32(vaccKLMN, _mm_mullo_epi32(vbKLMN, vb_multiplier));
69 vaccOPQR = _mm_add_epi32(vaccOPQR, _mm_mullo_epi32(vbOPQR, vb_multiplier));
70 vaccSTUV = _mm_add_epi32(vaccSTUV, _mm_mullo_epi32(vbSTUV, vb_multiplier));
Marat Dukhane9c4b962021-04-02 16:56:55 -070071
Marat Dukhan8a045652021-07-20 14:07:21 -070072 vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift);
73 vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift);
74 vacc89AB = _mm_sra_epi32(_mm_add_epi32(vacc89AB, vrounding), vshift);
75 vaccCDEF = _mm_sra_epi32(_mm_add_epi32(vaccCDEF, vrounding), vshift);
76 vaccGHIJ = _mm_sra_epi32(_mm_add_epi32(vaccGHIJ, vrounding), vshift);
77 vaccKLMN = _mm_sra_epi32(_mm_add_epi32(vaccKLMN, vrounding), vshift);
78 vaccOPQR = _mm_sra_epi32(_mm_add_epi32(vaccOPQR, vrounding), vshift);
79 vaccSTUV = _mm_sra_epi32(_mm_add_epi32(vaccSTUV, vrounding), vshift);
Marat Dukhane9c4b962021-04-02 16:56:55 -070080
Marat Dukhan7679b1e2021-07-20 18:32:23 -070081 const __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
82 const __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point);
83 const __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point);
84 const __m128i voutOPQRSTUV = _mm_adds_epi16(_mm_packs_epi32(vaccOPQR, vaccSTUV), voutput_zero_point);
Marat Dukhane9c4b962021-04-02 16:56:55 -070085
Marat Dukhan7679b1e2021-07-20 18:32:23 -070086 __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
87 __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV);
Marat Dukhane9c4b962021-04-02 16:56:55 -070088
Marat Dukhan7679b1e2021-07-20 18:32:23 -070089 vout0123456789ABCDEF = _mm_max_epi8(vout0123456789ABCDEF, voutput_min);
90 voutGHIJKLMNOPQRSTUV = _mm_max_epi8(voutGHIJKLMNOPQRSTUV, voutput_min);
Marat Dukhane9c4b962021-04-02 16:56:55 -070091
Marat Dukhan7679b1e2021-07-20 18:32:23 -070092 vout0123456789ABCDEF = _mm_min_epi8(vout0123456789ABCDEF, voutput_max);
93 voutGHIJKLMNOPQRSTUV = _mm_min_epi8(voutGHIJKLMNOPQRSTUV, voutput_max);
Marat Dukhane9c4b962021-04-02 16:56:55 -070094
95 _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF);
96 _mm_storeu_si128((__m128i*) (output + 16), voutGHIJKLMNOPQRSTUV);
97 output += 32;
98 }
99 if XNN_UNLIKELY(n != 0) {
100 do {
Marat Dukhan076bcfe2021-07-19 19:24:42 -0700101 const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a));
102 const __m128i vb0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b));
103 const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4));
104 const __m128i vb4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_b + 4));
105 input_a += 8;
106 input_b += 8;
Marat Dukhane9c4b962021-04-02 16:56:55 -0700107
Marat Dukhana842fef2021-07-19 21:07:40 -0700108 __m128i vacc0123 = _mm_add_epi32(vbias, _mm_mullo_epi32(va0123, va_multiplier));
109 __m128i vacc4567 = _mm_add_epi32(vbias, _mm_mullo_epi32(va4567, va_multiplier));
Marat Dukhane9c4b962021-04-02 16:56:55 -0700110
Marat Dukhan076bcfe2021-07-19 19:24:42 -0700111 vacc0123 = _mm_add_epi32(vacc0123, _mm_mullo_epi32(vb0123, vb_multiplier));
112 vacc4567 = _mm_add_epi32(vacc4567, _mm_mullo_epi32(vb4567, vb_multiplier));
Marat Dukhane9c4b962021-04-02 16:56:55 -0700113
Marat Dukhan8a045652021-07-20 14:07:21 -0700114 vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift);
115 vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift);
Marat Dukhane9c4b962021-04-02 16:56:55 -0700116
Marat Dukhan7679b1e2021-07-20 18:32:23 -0700117 const __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
Marat Dukhane9c4b962021-04-02 16:56:55 -0700118
119 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
Marat Dukhan7679b1e2021-07-20 18:32:23 -0700120 vout0123456701234567 = _mm_max_epi8(vout0123456701234567, voutput_min);
121 vout0123456701234567 = _mm_min_epi8(vout0123456701234567, voutput_max);
Marat Dukhane9c4b962021-04-02 16:56:55 -0700122
123 if XNN_LIKELY(n >= (8 * sizeof(int8_t))) {
124 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
125 output += 8;
126 n -= 8 * sizeof(int8_t);
127 } else {
128 if (n & (4 * sizeof(int8_t))) {
129 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
130 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
131 output += 4;
132 }
133 if (n & (2 * sizeof(int8_t))) {
134 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
135 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
136 output += 2;
137 }
138 if (n & (1 * sizeof(int8_t))) {
139 *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0);
140 }
141 n = 0;
142 }
143 } while (n != 0);
144 }
145}