Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 1 | // Auto-generated file. Do not edit! |
| 2 | // Template: src/qs8-vaddc/sse-mul16-ld64.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 <smmintrin.h> |
| 13 | |
| 14 | #include <xnnpack/vadd.h> |
| 15 | |
| 16 | |
| 17 | void xnn_qs8_vaddc_minmax_ukernel__sse41_mul16_ld64_x32( |
| 18 | size_t n, |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 19 | const int8_t* input_a, |
| 20 | const int8_t* input_b, |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 21 | int8_t* output, |
Marat Dukhan | 6e0fc39 | 2021-07-19 18:38:24 -0700 | [diff] [blame] | 22 | const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 23 | { |
Marat Dukhan | 49d9005 | 2021-07-19 19:59:30 -0700 | [diff] [blame] | 24 | const __m128i va_multiplier_lo = _mm_load_si128((const __m128i*) params->sse2.a_multiplier_lo); |
| 25 | const __m128i va_multiplier_hi = _mm_load_si128((const __m128i*) params->sse2.a_multiplier_hi); |
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 | 0270d9f | 2020-08-11 00:56:46 -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 | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 35 | for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 36 | const __m128i va01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) input_a)); |
| 37 | const __m128i va89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 8))); |
| 38 | const __m128i vaGHIJKLMN = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 16))); |
| 39 | const __m128i vaOPQRSTUV = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 24))); |
| 40 | input_a += 32; |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 41 | |
| 42 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 43 | __m128i vaprod01234567hi = _mm_mulhi_epu16(va01234567, va_multiplier_lo); |
| 44 | const __m128i vaprod01234567lo = _mm_mullo_epi16(va01234567, va_multiplier_lo); |
| 45 | __m128i vaprod89ABCDEFhi = _mm_mulhi_epu16(va89ABCDEF, va_multiplier_lo); |
| 46 | const __m128i vaprod89ABCDEFlo = _mm_mullo_epi16(va89ABCDEF, va_multiplier_lo); |
| 47 | __m128i vaprodGHIJKLMNhi = _mm_mulhi_epu16(vaGHIJKLMN, va_multiplier_lo); |
| 48 | const __m128i vaprodGHIJKLMNlo = _mm_mullo_epi16(vaGHIJKLMN, va_multiplier_lo); |
| 49 | __m128i vaprodOPQRSTUVhi = _mm_mulhi_epu16(vaOPQRSTUV, va_multiplier_lo); |
| 50 | const __m128i vaprodOPQRSTUVlo = _mm_mullo_epi16(vaOPQRSTUV, va_multiplier_lo); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 51 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 52 | vaprod01234567hi = _mm_add_epi16(vaprod01234567hi, _mm_mullo_epi16(va01234567, va_multiplier_hi)); |
| 53 | vaprod89ABCDEFhi = _mm_add_epi16(vaprod89ABCDEFhi, _mm_mullo_epi16(va89ABCDEF, va_multiplier_hi)); |
| 54 | vaprodGHIJKLMNhi = _mm_add_epi16(vaprodGHIJKLMNhi, _mm_mullo_epi16(vaGHIJKLMN, va_multiplier_hi)); |
| 55 | vaprodOPQRSTUVhi = _mm_add_epi16(vaprodOPQRSTUVhi, _mm_mullo_epi16(vaOPQRSTUV, va_multiplier_hi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 56 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 57 | vaprod01234567hi = _mm_sub_epi16(vaprod01234567hi, _mm_and_si128(_mm_srai_epi16(va01234567, 15), va_multiplier_lo)); |
| 58 | vaprod89ABCDEFhi = _mm_sub_epi16(vaprod89ABCDEFhi, _mm_and_si128(_mm_srai_epi16(va89ABCDEF, 15), va_multiplier_lo)); |
| 59 | vaprodGHIJKLMNhi = _mm_sub_epi16(vaprodGHIJKLMNhi, _mm_and_si128(_mm_srai_epi16(vaGHIJKLMN, 15), va_multiplier_lo)); |
| 60 | vaprodOPQRSTUVhi = _mm_sub_epi16(vaprodOPQRSTUVhi, _mm_and_si128(_mm_srai_epi16(vaOPQRSTUV, 15), va_multiplier_lo)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 61 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 62 | __m128i vacc0123 = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprod01234567lo, vaprod01234567hi)); |
| 63 | __m128i vacc4567 = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprod01234567lo, vaprod01234567hi)); |
| 64 | __m128i vacc89AB = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprod89ABCDEFlo, vaprod89ABCDEFhi)); |
| 65 | __m128i vaccCDEF = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprod89ABCDEFlo, vaprod89ABCDEFhi)); |
| 66 | __m128i vaccGHIJ = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprodGHIJKLMNlo, vaprodGHIJKLMNhi)); |
| 67 | __m128i vaccKLMN = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprodGHIJKLMNlo, vaprodGHIJKLMNhi)); |
| 68 | __m128i vaccOPQR = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprodOPQRSTUVlo, vaprodOPQRSTUVhi)); |
| 69 | __m128i vaccSTUV = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprodOPQRSTUVlo, vaprodOPQRSTUVhi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 70 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame^] | 71 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 72 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
| 73 | vacc89AB = _mm_sra_epi32(_mm_add_epi32(vacc89AB, vrounding), vshift); |
| 74 | vaccCDEF = _mm_sra_epi32(_mm_add_epi32(vaccCDEF, vrounding), vshift); |
| 75 | vaccGHIJ = _mm_sra_epi32(_mm_add_epi32(vaccGHIJ, vrounding), vshift); |
| 76 | vaccKLMN = _mm_sra_epi32(_mm_add_epi32(vaccKLMN, vrounding), vshift); |
| 77 | vaccOPQR = _mm_sra_epi32(_mm_add_epi32(vaccOPQR, vrounding), vshift); |
| 78 | vaccSTUV = _mm_sra_epi32(_mm_add_epi32(vaccSTUV, vrounding), vshift); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 79 | |
| 80 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 81 | __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point); |
| 82 | __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point); |
| 83 | __m128i voutOPQRSTUV = _mm_adds_epi16(_mm_packs_epi32(vaccOPQR, vaccSTUV), voutput_zero_point); |
| 84 | |
| 85 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 86 | vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min); |
| 87 | voutGHIJKLMN = _mm_max_epi16(voutGHIJKLMN, voutput_min); |
| 88 | voutOPQRSTUV = _mm_max_epi16(voutOPQRSTUV, voutput_min); |
| 89 | |
| 90 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 91 | vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max); |
| 92 | voutGHIJKLMN = _mm_min_epi16(voutGHIJKLMN, voutput_max); |
| 93 | voutOPQRSTUV = _mm_min_epi16(voutOPQRSTUV, voutput_max); |
| 94 | |
| 95 | const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF); |
| 96 | const __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV); |
| 97 | |
| 98 | _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF); |
| 99 | _mm_storeu_si128((__m128i*) (output + 16), voutGHIJKLMNOPQRSTUV); |
| 100 | output += 32; |
| 101 | } |
| 102 | if XNN_UNLIKELY(n != 0) { |
| 103 | do { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 104 | const __m128i va01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) input_a)); |
| 105 | input_a += 8; |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 106 | |
| 107 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 108 | __m128i vaprod01234567hi = _mm_mulhi_epu16(va01234567, va_multiplier_lo); |
| 109 | const __m128i vaprod01234567lo = _mm_mullo_epi16(va01234567, va_multiplier_lo); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 110 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 111 | vaprod01234567hi = _mm_add_epi16(vaprod01234567hi, _mm_mullo_epi16(va01234567, va_multiplier_hi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 112 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 113 | vaprod01234567hi = _mm_sub_epi16(vaprod01234567hi, _mm_and_si128(_mm_srai_epi16(va01234567, 15), va_multiplier_lo)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 114 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame] | 115 | __m128i vacc0123 = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprod01234567lo, vaprod01234567hi)); |
| 116 | __m128i vacc4567 = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprod01234567lo, vaprod01234567hi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 117 | |
Marat Dukhan | 8a04565 | 2021-07-20 14:07:21 -0700 | [diff] [blame^] | 118 | vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift); |
| 119 | vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 120 | |
| 121 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 122 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 123 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 124 | |
| 125 | __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567); |
| 126 | |
| 127 | if XNN_LIKELY(n >= (8 * sizeof(int8_t))) { |
| 128 | _mm_storel_epi64((__m128i*) output, vout0123456701234567); |
| 129 | output += 8; |
Marat Dukhan | ba7b279 | 2020-09-02 14:26:45 -0700 | [diff] [blame] | 130 | n -= 8 * sizeof(int8_t); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 131 | } else { |
| 132 | if (n & (4 * sizeof(int8_t))) { |
| 133 | *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567); |
| 134 | vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32); |
| 135 | output += 4; |
| 136 | } |
| 137 | if (n & (2 * sizeof(int8_t))) { |
| 138 | *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0); |
| 139 | vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16); |
| 140 | output += 2; |
| 141 | } |
| 142 | if (n & (1 * sizeof(int8_t))) { |
| 143 | *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 144 | } |
| 145 | n = 0; |
| 146 | } |
| 147 | } while (n != 0); |
| 148 | } |
| 149 | } |