Optimize QS8 VADD[C] microkernels for SSE4/AVX/XOP/AVX2
Use microkernel-specific parameters to remove some operations
PiperOrigin-RevId: 385914437
diff --git a/src/qs8-vaddc/gen/minmax-xop-mul32-ld32-x24.c b/src/qs8-vaddc/gen/minmax-xop-mul32-ld32-x24.c
index a688ddf..8beb90a 100644
--- a/src/qs8-vaddc/gen/minmax-xop-mul32-ld32-x24.c
+++ b/src/qs8-vaddc/gen/minmax-xop-mul32-ld32-x24.c
@@ -27,16 +27,16 @@
int8_t* output,
const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
{
- const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse2.a_multiplier);
- const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse2.rounding);
- const __m128i vshift = _mm_cvtsi32_si128((int) params->sse2.shift);
- const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse2.output_zero_point);
- const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse2.output_min);
- const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse2.output_max);
+ const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse4_mul32.a_multiplier);
+ const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse4_mul32.rounding);
+ const __m128i vshift = _mm_loadu_si32(params->sse4_mul32.shift);
+ const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse4_mul32.output_zero_point);
+ const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse4_mul32.output_min);
+ const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse4_mul32.output_max);
- __m128i vbias = _mm_cvtsi32_si128(params->sse2.b_multiplier[0] * (int32_t) *input_b);
+ __m128i vbias = _mm_cvtsi32_si128(params->sse4_mul32.b_multiplier[0] * (int32_t) *input_b);
vbias = _mm_shuffle_epi32(vbias, _MM_SHUFFLE(0, 0, 0, 0));
- vbias = _mm_add_epi32(vbias, _mm_load_si128((const __m128i*) params->sse2.bias));
+ vbias = _mm_add_epi32(vbias, _mm_load_si128((const __m128i*) params->sse4_mul32.bias));
for (; n >= 24 * sizeof(int8_t); n -= 24 * sizeof(int8_t)) {
const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a));
const __m128i va4567 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a + 4));
@@ -61,20 +61,18 @@
vaccGHIJ = _mm_sra_epi32(_mm_add_epi32(vaccGHIJ, vrounding), vshift);
vaccKLMN = _mm_sra_epi32(_mm_add_epi32(vaccKLMN, vrounding), vshift);
- __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
- __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point);
- __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point);
+ const __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
+ const __m128i vout89ABCDEF = _mm_adds_epi16(_mm_packs_epi32(vacc89AB, vaccCDEF), voutput_zero_point);
+ const __m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point);
- vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
- vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min);
- voutGHIJKLMN = _mm_max_epi16(voutGHIJKLMN, voutput_min);
+ __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
+ __m128i voutGHIJKLMNGHIJKLMN = _mm_packs_epi16(voutGHIJKLMN, voutGHIJKLMN);
- vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
- vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max);
- voutGHIJKLMN = _mm_min_epi16(voutGHIJKLMN, voutput_max);
+ vout0123456789ABCDEF = _mm_max_epi8(vout0123456789ABCDEF, voutput_min);
+ voutGHIJKLMNGHIJKLMN = _mm_max_epi8(voutGHIJKLMNGHIJKLMN, voutput_min);
- const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
- const __m128i voutGHIJKLMNGHIJKLMN = _mm_packs_epi16(voutGHIJKLMN, voutGHIJKLMN);
+ vout0123456789ABCDEF = _mm_min_epi8(vout0123456789ABCDEF, voutput_max);
+ voutGHIJKLMNGHIJKLMN = _mm_min_epi8(voutGHIJKLMNGHIJKLMN, voutput_max);
_mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF);
_mm_storel_epi64((__m128i*) (output + 16), voutGHIJKLMNGHIJKLMN);
@@ -92,11 +90,11 @@
vacc0123 = _mm_sra_epi32(_mm_add_epi32(vacc0123, vrounding), vshift);
vacc4567 = _mm_sra_epi32(_mm_add_epi32(vacc4567, vrounding), vshift);
- __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
- vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
- vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
+ const __m128i vout01234567 = _mm_adds_epi16(_mm_packs_epi32(vacc0123, vacc4567), voutput_zero_point);
__m128i vout0123456701234567 = _mm_packs_epi16(vout01234567, vout01234567);
+ vout0123456701234567 = _mm_max_epi8(vout0123456701234567, voutput_min);
+ vout0123456701234567 = _mm_min_epi8(vout0123456701234567, voutput_max);
if XNN_LIKELY(n >= (8 * sizeof(int8_t))) {
_mm_storel_epi64((__m128i*) output, vout0123456701234567);