Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 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 | |
| 18 | void xnn_qs8_vadd_minmax_ukernel__avx_mul32_ld32_x32( |
| 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 | e9c4b96 | 2021-04-02 16:56:55 -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 | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 24 | { |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 25 | 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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 33 | |
| 34 | for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 35 | 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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 53 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 54 | __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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 62 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 63 | 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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 71 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame] | 72 | 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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 80 | |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 81 | 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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 85 | |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 86 | __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF); |
| 87 | __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 88 | |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 89 | vout0123456789ABCDEF = _mm_max_epi8(vout0123456789ABCDEF, voutput_min); |
| 90 | voutGHIJKLMNOPQRSTUV = _mm_max_epi8(voutGHIJKLMNOPQRSTUV, voutput_min); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 91 | |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 92 | vout0123456789ABCDEF = _mm_min_epi8(vout0123456789ABCDEF, voutput_max); |
| 93 | voutGHIJKLMNOPQRSTUV = _mm_min_epi8(voutGHIJKLMNOPQRSTUV, voutput_max); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 94 | |
| 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 Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 101 | 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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 107 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 108 | __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 Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 110 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 111 | vacc0123 = _mm_add_epi32(vacc0123, _mm_mullo_epi32(vb0123, vb_multiplier)); |
| 112 | vacc4567 = _mm_add_epi32(vacc4567, _mm_mullo_epi32(vb4567, vb_multiplier)); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 113 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame] | 114 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 115 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 116 | |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 117 | const __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 118 | |
| 119 | __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567); |
Marat Dukhan | 7679b1e | 2021-07-20 18:32:23 -0700 | [diff] [blame^] | 120 | vout0123456701234567 = _mm_max_epi8(vout0123456701234567, voutput_min); |
| 121 | vout0123456701234567 = _mm_min_epi8(vout0123456701234567, voutput_max); |
Marat Dukhan | e9c4b96 | 2021-04-02 16:56:55 -0700 | [diff] [blame] | 122 | |
| 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 | } |