Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 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 | #include <immintrin.h> |
| 13 | |
| 14 | #include <xnnpack/intrinsics-polyfill.h> |
| 15 | #include <xnnpack/vadd.h> |
| 16 | |
| 17 | |
| 18 | void xnn_qs8_vaddc_minmax_ukernel__sse41_mul32_ld32_x16( |
| 19 | size_t n, |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 20 | const int8_t* input_a, |
| 21 | const int8_t* input_b, |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 22 | int8_t* output, |
Marat Dukhan | 6e0fc39 | 2021-07-19 18:38:24 -0700 | [diff] [blame] | 23 | const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 24 | { |
Marat Dukhan | 49d9005 | 2021-07-19 19:59:30 -0700 | [diff] [blame] | 25 | const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse2.a_multiplier); |
Marat Dukhan | 947c298 | 2021-07-20 13:11:29 -0700 | [diff] [blame] | 26 | const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 27 | const __m128i vshift = _mm_cvtsi32_si128((int) params->sse2.shift); |
| 28 | const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point); |
| 29 | const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min); |
| 30 | const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max); |
| 31 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 32 | __m128i vbias = _mm_cvtsi32_si128(params->sse2.b_multiplier[0] * (int32_t) *input_b); |
| 33 | vbias = _mm_shuffle_epi32(vbias, _MM_SHUFFLE(0, 0, 0, 0)); |
| 34 | vbias = _mm_add_epi32(vbias, _mm_load_si128((const __m128i*) params->sse2.bias)); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 35 | for (; n >= 16 * sizeof(int8_t); n -= 16 * sizeof(int8_t)) { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 36 | const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a)); |
| 37 | const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4)); |
| 38 | const __m128i va89AB = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 8)); |
| 39 | const __m128i vaCDEF = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 12)); |
| 40 | input_a += 16; |
| 41 | input_b += 16; |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 42 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 43 | __m128i vacc0123 = _mm_add_epi32(vbias, _mm_mullo_epi32(va0123, va_multiplier)); |
| 44 | __m128i vacc4567 = _mm_add_epi32(vbias, _mm_mullo_epi32(va4567, va_multiplier)); |
| 45 | __m128i vacc89AB = _mm_add_epi32(vbias, _mm_mullo_epi32(va89AB, va_multiplier)); |
| 46 | __m128i vaccCDEF = _mm_add_epi32(vbias, _mm_mullo_epi32(vaCDEF, va_multiplier)); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 47 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame^] | 48 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 49 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
| 50 | vacc89AB = _mm_sra_epi32(_mm_add_epi32(vacc89AB, vrounding), vshift); |
| 51 | vaccCDEF = _mm_sra_epi32(_mm_add_epi32(vaccCDEF, vrounding), vshift); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 52 | |
| 53 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 54 | __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point); |
| 55 | |
| 56 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 57 | vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min); |
| 58 | |
| 59 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 60 | vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max); |
| 61 | |
| 62 | const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF); |
| 63 | |
| 64 | _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF); |
| 65 | output += 16; |
| 66 | } |
| 67 | if XNN_UNLIKELY(n != 0) { |
| 68 | do { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 69 | const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a)); |
| 70 | const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4)); |
| 71 | input_a += 8; |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 72 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 73 | __m128i vacc0123 = _mm_add_epi32(vbias, _mm_mullo_epi32(va0123, va_multiplier)); |
| 74 | __m128i vacc4567 = _mm_add_epi32(vbias, _mm_mullo_epi32(va4567, va_multiplier)); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 75 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame^] | 76 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 77 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 78 | |
| 79 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 80 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 81 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 82 | |
| 83 | __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567); |
| 84 | |
| 85 | if XNN_LIKELY(n >= (8 * sizeof(int8_t))) { |
| 86 | _mm_storel_epi64((__m128i*) output, vout0123456701234567); |
| 87 | output += 8; |
| 88 | n -= 8 * sizeof(int8_t); |
| 89 | } else { |
| 90 | if (n & (4 * sizeof(int8_t))) { |
| 91 | *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567); |
| 92 | vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32); |
| 93 | output += 4; |
| 94 | } |
| 95 | if (n & (2 * sizeof(int8_t))) { |
| 96 | *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0); |
| 97 | vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16); |
| 98 | output += 2; |
| 99 | } |
| 100 | if (n & (1 * sizeof(int8_t))) { |
| 101 | *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0); |
| 102 | } |
| 103 | n = 0; |
| 104 | } |
| 105 | } while (n != 0); |
| 106 | } |
| 107 | } |