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 | |
Marat Dukhan | c409471 | 2021-04-02 10:03:16 -0700 | [diff] [blame] | 12 | #if defined(__GNUC__) || defined(__clang__) |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 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 | |
| 23 | void xnn_qs8_vaddc_minmax_ukernel__xop_mul32_ld32_x24( |
| 24 | size_t n, |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 25 | const int8_t* input_a, |
| 26 | const int8_t* input_b, |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 27 | int8_t* output, |
Marat Dukhan | 6e0fc39 | 2021-07-19 18:38:24 -0700 | [diff] [blame] | 28 | 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] | 29 | { |
Marat Dukhan | 49d9005 | 2021-07-19 19:59:30 -0700 | [diff] [blame] | 30 | 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] | 31 | const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 32 | const __m128i vshift = _mm_cvtsi32_si128((int) params->sse2.shift); |
| 33 | const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point); |
| 34 | const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min); |
| 35 | const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max); |
| 36 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 37 | __m128i vbias = _mm_cvtsi32_si128(params->sse2.b_multiplier[0] * (int32_t) *input_b); |
| 38 | vbias = _mm_shuffle_epi32(vbias, _MM_SHUFFLE(0, 0, 0, 0)); |
| 39 | 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] | 40 | for (; n >= 24 * sizeof(int8_t); n -= 24 * sizeof(int8_t)) { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 41 | const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a)); |
| 42 | const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4)); |
| 43 | const __m128i va89AB = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 8)); |
| 44 | const __m128i vaCDEF = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 12)); |
| 45 | const __m128i vaGHIJ = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 16)); |
| 46 | const __m128i vaKLMN = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 20)); |
| 47 | input_a += 24; |
| 48 | input_b += 24; |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 49 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 50 | __m128i vacc0123 = _mm_macc_epi32(va0123, va_multiplier, vbias); |
| 51 | __m128i vacc4567 = _mm_macc_epi32(va4567, va_multiplier, vbias); |
| 52 | __m128i vacc89AB = _mm_macc_epi32(va89AB, va_multiplier, vbias); |
| 53 | __m128i vaccCDEF = _mm_macc_epi32(vaCDEF, va_multiplier, vbias); |
| 54 | __m128i vaccGHIJ = _mm_macc_epi32(vaGHIJ, va_multiplier, vbias); |
| 55 | __m128i vaccKLMN = _mm_macc_epi32(vaKLMN, va_multiplier, vbias); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 56 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame] | 57 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 58 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
| 59 | vacc89AB = _mm_sra_epi32(_mm_add_epi32(vacc89AB, vrounding), vshift); |
| 60 | vaccCDEF = _mm_sra_epi32(_mm_add_epi32(vaccCDEF, vrounding), vshift); |
| 61 | vaccGHIJ = _mm_sra_epi32(_mm_add_epi32(vaccGHIJ, vrounding), vshift); |
| 62 | vaccKLMN = _mm_sra_epi32(_mm_add_epi32(vaccKLMN, vrounding), vshift); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 63 | |
| 64 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 65 | __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point); |
| 66 | __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point); |
| 67 | |
| 68 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 69 | vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min); |
| 70 | voutGHIJKLMN = _mm_max_epi16(voutGHIJKLMN, voutput_min); |
| 71 | |
| 72 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 73 | vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max); |
| 74 | voutGHIJKLMN = _mm_min_epi16(voutGHIJKLMN, voutput_max); |
| 75 | |
| 76 | const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF); |
| 77 | const __m128i voutGHIJKLMNGHIJKLMN = _mm_packs_epi16(voutGHIJKLMN, voutGHIJKLMN); |
| 78 | |
| 79 | _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF); |
| 80 | _mm_storel_epi64((__m128i*) (output + 16), voutGHIJKLMNGHIJKLMN); |
| 81 | output += 24; |
| 82 | } |
| 83 | if XNN_UNLIKELY(n != 0) { |
| 84 | do { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 85 | const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a)); |
| 86 | const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4)); |
| 87 | input_a += 8; |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 88 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 89 | __m128i vacc0123 = _mm_macc_epi32(va0123, va_multiplier, vbias); |
| 90 | __m128i vacc4567 = _mm_macc_epi32(va4567, va_multiplier, vbias); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 91 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame] | 92 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 93 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
Marat Dukhan | bb9225e | 2020-09-06 22:40:56 -0700 | [diff] [blame] | 94 | |
| 95 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 96 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 97 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 98 | |
| 99 | __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567); |
| 100 | |
| 101 | if XNN_LIKELY(n >= (8 * sizeof(int8_t))) { |
| 102 | _mm_storel_epi64((__m128i*) output, vout0123456701234567); |
| 103 | output += 8; |
| 104 | n -= 8 * sizeof(int8_t); |
| 105 | } else { |
| 106 | if (n & (4 * sizeof(int8_t))) { |
| 107 | *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567); |
| 108 | vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32); |
| 109 | output += 4; |
| 110 | } |
| 111 | if (n & (2 * sizeof(int8_t))) { |
| 112 | *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0); |
| 113 | vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16); |
| 114 | output += 2; |
| 115 | } |
| 116 | if (n & (1 * sizeof(int8_t))) { |
| 117 | *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0); |
| 118 | } |
| 119 | n = 0; |
| 120 | } |
| 121 | } while (n != 0); |
| 122 | } |
| 123 | } |