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 | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 26 | const __m128i vremainder_mask = _mm_load_si128((const __m128i*) params->sse2.remainder_mask); |
| 27 | const __m128i vremainder_threshold = _mm_load_si128((const __m128i*) params->sse2.remainder_threshold); |
| 28 | const __m128i vshift = _mm_cvtsi32_si128((int) params->sse2.shift); |
| 29 | const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point); |
| 30 | const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min); |
| 31 | const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max); |
| 32 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame^] | 33 | __m128i vbias = _mm_cvtsi32_si128(params->sse2.b_multiplier[0] * (int32_t) *input_b); |
| 34 | vbias = _mm_shuffle_epi32(vbias, _MM_SHUFFLE(0, 0, 0, 0)); |
| 35 | 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] | 36 | for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 37 | const __m128i va01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) input_a)); |
| 38 | const __m128i va89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 8))); |
| 39 | const __m128i vaGHIJKLMN = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 16))); |
| 40 | const __m128i vaOPQRSTUV = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 24))); |
| 41 | input_a += 32; |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 42 | |
| 43 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 44 | __m128i vaprod01234567hi = _mm_mulhi_epu16(va01234567, va_multiplier_lo); |
| 45 | const __m128i vaprod01234567lo = _mm_mullo_epi16(va01234567, va_multiplier_lo); |
| 46 | __m128i vaprod89ABCDEFhi = _mm_mulhi_epu16(va89ABCDEF, va_multiplier_lo); |
| 47 | const __m128i vaprod89ABCDEFlo = _mm_mullo_epi16(va89ABCDEF, va_multiplier_lo); |
| 48 | __m128i vaprodGHIJKLMNhi = _mm_mulhi_epu16(vaGHIJKLMN, va_multiplier_lo); |
| 49 | const __m128i vaprodGHIJKLMNlo = _mm_mullo_epi16(vaGHIJKLMN, va_multiplier_lo); |
| 50 | __m128i vaprodOPQRSTUVhi = _mm_mulhi_epu16(vaOPQRSTUV, va_multiplier_lo); |
| 51 | const __m128i vaprodOPQRSTUVlo = _mm_mullo_epi16(vaOPQRSTUV, va_multiplier_lo); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 52 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 53 | vaprod01234567hi = _mm_add_epi16(vaprod01234567hi, _mm_mullo_epi16(va01234567, va_multiplier_hi)); |
| 54 | vaprod89ABCDEFhi = _mm_add_epi16(vaprod89ABCDEFhi, _mm_mullo_epi16(va89ABCDEF, va_multiplier_hi)); |
| 55 | vaprodGHIJKLMNhi = _mm_add_epi16(vaprodGHIJKLMNhi, _mm_mullo_epi16(vaGHIJKLMN, va_multiplier_hi)); |
| 56 | vaprodOPQRSTUVhi = _mm_add_epi16(vaprodOPQRSTUVhi, _mm_mullo_epi16(vaOPQRSTUV, va_multiplier_hi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 57 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 58 | vaprod01234567hi = _mm_sub_epi16(vaprod01234567hi, _mm_and_si128(_mm_srai_epi16(va01234567, 15), va_multiplier_lo)); |
| 59 | vaprod89ABCDEFhi = _mm_sub_epi16(vaprod89ABCDEFhi, _mm_and_si128(_mm_srai_epi16(va89ABCDEF, 15), va_multiplier_lo)); |
| 60 | vaprodGHIJKLMNhi = _mm_sub_epi16(vaprodGHIJKLMNhi, _mm_and_si128(_mm_srai_epi16(vaGHIJKLMN, 15), va_multiplier_lo)); |
| 61 | 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] | 62 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame^] | 63 | __m128i vacc0123 = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprod01234567lo, vaprod01234567hi)); |
| 64 | __m128i vacc4567 = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprod01234567lo, vaprod01234567hi)); |
| 65 | __m128i vacc89AB = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprod89ABCDEFlo, vaprod89ABCDEFhi)); |
| 66 | __m128i vaccCDEF = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprod89ABCDEFlo, vaprod89ABCDEFhi)); |
| 67 | __m128i vaccGHIJ = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprodGHIJKLMNlo, vaprodGHIJKLMNhi)); |
| 68 | __m128i vaccKLMN = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprodGHIJKLMNlo, vaprodGHIJKLMNhi)); |
| 69 | __m128i vaccOPQR = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprodOPQRSTUVlo, vaprodOPQRSTUVhi)); |
| 70 | __m128i vaccSTUV = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprodOPQRSTUVlo, vaprodOPQRSTUVhi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 71 | |
| 72 | const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123)); |
| 73 | const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567)); |
| 74 | const __m128i vrem89AB = _mm_add_epi32(_mm_and_si128(vacc89AB, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc89AB)); |
| 75 | const __m128i vremCDEF = _mm_add_epi32(_mm_and_si128(vaccCDEF, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccCDEF)); |
| 76 | const __m128i vremGHIJ = _mm_add_epi32(_mm_and_si128(vaccGHIJ, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccGHIJ)); |
| 77 | const __m128i vremKLMN = _mm_add_epi32(_mm_and_si128(vaccKLMN, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccKLMN)); |
| 78 | const __m128i vremOPQR = _mm_add_epi32(_mm_and_si128(vaccOPQR, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccOPQR)); |
| 79 | const __m128i vremSTUV = _mm_add_epi32(_mm_and_si128(vaccSTUV, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vaccSTUV)); |
| 80 | |
| 81 | vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold)); |
| 82 | vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold)); |
| 83 | vacc89AB = _mm_sub_epi32(_mm_sra_epi32(vacc89AB, vshift), _mm_cmpgt_epi32(vrem89AB, vremainder_threshold)); |
| 84 | vaccCDEF = _mm_sub_epi32(_mm_sra_epi32(vaccCDEF, vshift), _mm_cmpgt_epi32(vremCDEF, vremainder_threshold)); |
| 85 | vaccGHIJ = _mm_sub_epi32(_mm_sra_epi32(vaccGHIJ, vshift), _mm_cmpgt_epi32(vremGHIJ, vremainder_threshold)); |
| 86 | vaccKLMN = _mm_sub_epi32(_mm_sra_epi32(vaccKLMN, vshift), _mm_cmpgt_epi32(vremKLMN, vremainder_threshold)); |
| 87 | vaccOPQR = _mm_sub_epi32(_mm_sra_epi32(vaccOPQR, vshift), _mm_cmpgt_epi32(vremOPQR, vremainder_threshold)); |
| 88 | vaccSTUV = _mm_sub_epi32(_mm_sra_epi32(vaccSTUV, vshift), _mm_cmpgt_epi32(vremSTUV, vremainder_threshold)); |
| 89 | |
| 90 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 91 | __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point); |
| 92 | __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point); |
| 93 | __m128i voutOPQRSTUV = _mm_adds_epi16(_mm_packs_epi32(vaccOPQR, vaccSTUV), voutput_zero_point); |
| 94 | |
| 95 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 96 | vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min); |
| 97 | voutGHIJKLMN = _mm_max_epi16(voutGHIJKLMN, voutput_min); |
| 98 | voutOPQRSTUV = _mm_max_epi16(voutOPQRSTUV, voutput_min); |
| 99 | |
| 100 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 101 | vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max); |
| 102 | voutGHIJKLMN = _mm_min_epi16(voutGHIJKLMN, voutput_max); |
| 103 | voutOPQRSTUV = _mm_min_epi16(voutOPQRSTUV, voutput_max); |
| 104 | |
| 105 | const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF); |
| 106 | const __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV); |
| 107 | |
| 108 | _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF); |
| 109 | _mm_storeu_si128((__m128i*) (output + 16), voutGHIJKLMNOPQRSTUV); |
| 110 | output += 32; |
| 111 | } |
| 112 | if XNN_UNLIKELY(n != 0) { |
| 113 | do { |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 114 | const __m128i va01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) input_a)); |
| 115 | input_a += 8; |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 116 | |
| 117 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 118 | __m128i vaprod01234567hi = _mm_mulhi_epu16(va01234567, va_multiplier_lo); |
| 119 | const __m128i vaprod01234567lo = _mm_mullo_epi16(va01234567, va_multiplier_lo); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 120 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 121 | vaprod01234567hi = _mm_add_epi16(vaprod01234567hi, _mm_mullo_epi16(va01234567, va_multiplier_hi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 122 | |
Marat Dukhan | 076bcfe | 2021-07-19 19:24:42 -0700 | [diff] [blame] | 123 | 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] | 124 | |
Marat Dukhan | a842fef | 2021-07-19 21:07:40 -0700 | [diff] [blame^] | 125 | __m128i vacc0123 = _mm_add_epi32(vbias, _mm_unpacklo_epi16(vaprod01234567lo, vaprod01234567hi)); |
| 126 | __m128i vacc4567 = _mm_add_epi32(vbias, _mm_unpackhi_epi16(vaprod01234567lo, vaprod01234567hi)); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 127 | |
| 128 | const __m128i vrem0123 = _mm_add_epi32(_mm_and_si128(vacc0123, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc0123)); |
| 129 | const __m128i vrem4567 = _mm_add_epi32(_mm_and_si128(vacc4567, vremainder_mask), _mm_cmpgt_epi32(_mm_setzero_si128(), vacc4567)); |
| 130 | |
| 131 | vacc0123 = _mm_sub_epi32(_mm_sra_epi32(vacc0123, vshift), _mm_cmpgt_epi32(vrem0123, vremainder_threshold)); |
| 132 | vacc4567 = _mm_sub_epi32(_mm_sra_epi32(vacc4567, vshift), _mm_cmpgt_epi32(vrem4567, vremainder_threshold)); |
| 133 | |
| 134 | __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point); |
| 135 | vout01234567 = _mm_max_epi16(vout01234567, voutput_min); |
| 136 | vout01234567 = _mm_min_epi16(vout01234567, voutput_max); |
| 137 | |
| 138 | __m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567); |
| 139 | |
| 140 | if XNN_LIKELY(n >= (8 * sizeof(int8_t))) { |
| 141 | _mm_storel_epi64((__m128i*) output, vout0123456701234567); |
| 142 | output += 8; |
Marat Dukhan | ba7b279 | 2020-09-02 14:26:45 -0700 | [diff] [blame] | 143 | n -= 8 * sizeof(int8_t); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 144 | } else { |
| 145 | if (n & (4 * sizeof(int8_t))) { |
| 146 | *((uint32_t*) output) = (uint32_t) _mm_cvtsi128_si32(vout0123456701234567); |
| 147 | vout0123456701234567 = _mm_srli_epi64(vout0123456701234567, 32); |
| 148 | output += 4; |
| 149 | } |
| 150 | if (n & (2 * sizeof(int8_t))) { |
| 151 | *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(vout0123456701234567, 0); |
| 152 | vout0123456701234567 = _mm_srli_epi32(vout0123456701234567, 16); |
| 153 | output += 2; |
| 154 | } |
| 155 | if (n & (1 * sizeof(int8_t))) { |
| 156 | *output = (int8_t) _mm_extract_epi8(vout0123456701234567, 0); |
Marat Dukhan | 0270d9f | 2020-08-11 00:56:46 -0700 | [diff] [blame] | 157 | } |
| 158 | n = 0; |
| 159 | } |
| 160 | } while (n != 0); |
| 161 | } |
| 162 | } |