blob: bf68c6584152c0061107ea481e5d7fd09d16063d [file] [log] [blame]
Marat Dukhanbb9225e2020-09-06 22:40:56 -07001// 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
Marat Dukhanc4094712021-04-02 10:03:16 -070012#if defined(__GNUC__) || defined(__clang__)
Marat Dukhanbb9225e2020-09-06 22:40:56 -070013 #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
23void xnn_qs8_vaddc_minmax_ukernel__xop_mul32_ld32_x8(
24 size_t n,
Marat Dukhan076bcfe2021-07-19 19:24:42 -070025 const int8_t* input_a,
26 const int8_t* input_b,
Marat Dukhanbb9225e2020-09-06 22:40:56 -070027 int8_t* output,
Marat Dukhan6e0fc392021-07-19 18:38:24 -070028 const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
Marat Dukhanbb9225e2020-09-06 22:40:56 -070029{
Marat Dukhan49d90052021-07-19 19:59:30 -070030 const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse2.a_multiplier);
Marat Dukhanbb9225e2020-09-06 22:40:56 -070031 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
Marat Dukhan49d90052021-07-19 19:59:30 -070038 __m128i vzero_point_product = _mm_cvtsi32_si128(params->sse2.b_multiplier[0] * (int32_t) *input_b);
Marat Dukhanbb9225e2020-09-06 22:40:56 -070039 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 >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
Marat Dukhan076bcfe2021-07-19 19:24:42 -070042 const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a));
43 const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4));
44 input_a += 8;
45 input_b += 8;
Marat Dukhanbb9225e2020-09-06 22:40:56 -070046
Marat Dukhan076bcfe2021-07-19 19:24:42 -070047 __m128i vacc0123 = _mm_macc_epi32(va0123, va_multiplier, vzero_point_product);
48 __m128i vacc4567 = _mm_macc_epi32(va4567, va_multiplier, vzero_point_product);
Marat Dukhanbb9225e2020-09-06 22:40:56 -070049
50 const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123));
51 const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567));
52
53 vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
54 vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
55
56 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
57
58 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
59
60 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
61
62 const __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
63
64 _mm_storel_epi64((__m128i*) output, vout0123456701234567);
65 output += 8;
66 }
67 if XNN_UNLIKELY(n != 0) {
68 {
Marat Dukhan076bcfe2021-07-19 19:24:42 -070069 const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a));
70 const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4));
Marat Dukhanbb9225e2020-09-06 22:40:56 -070071
Marat Dukhan076bcfe2021-07-19 19:24:42 -070072 __m128i vacc0123 = _mm_macc_epi32(va0123, va_multiplier, vzero_point_product);
73 __m128i vacc4567 = _mm_macc_epi32(va4567, va_multiplier, vzero_point_product);
Marat Dukhanbb9225e2020-09-06 22:40:56 -070074
75 const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123));
76 const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567));
77
78 vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold));
79 vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold));
80
81 __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
82 vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
83 vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
84
85 __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
86
87 if (n & (4 * sizeof(int8_t))) {
88 *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567);
89 vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32);
90 output += 4;
91 }
92 if (n & (2 * sizeof(int8_t))) {
93 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0);
94 vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16);
95 output += 2;
96 }
97 if (n & (1 * sizeof(int8_t))) {
98 *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0);
99 }
100 }
101 }
102}