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-avx-mul16-ld64-x32.c b/src/qs8-vaddc/gen/minmax-avx-mul16-ld64-x32.c
index 8755b62..a04d2c0 100644
--- a/src/qs8-vaddc/gen/minmax-avx-mul16-ld64-x32.c
+++ b/src/qs8-vaddc/gen/minmax-avx-mul16-ld64-x32.c
@@ -21,17 +21,17 @@
int8_t* output,
const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
{
- const __m128i va_multiplier_lo = _mm_load_si128((const __m128i*) params->sse2.a_multiplier_lo);
- const __m128i va_multiplier_hi = _mm_load_si128((const __m128i*) params->sse2.a_multiplier_hi);
- 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 vbias = _mm_add_epi32(
+ _mm_shuffle_epi32(_mm_cvtsi32_si128(params->sse4_mul16.b_multiplier * (int32_t) *input_b), _MM_SHUFFLE(0, 0, 0, 0)),
+ _mm_load_si128((const __m128i*) params->sse4_mul16.bias));
+ const __m128i va_multiplier_lo = _mm_load_si128((const __m128i*) params->sse4_mul16.a_multiplier_lo);
+ const __m128i va_multiplier_hi = _mm_load_si128((const __m128i*) params->sse4_mul16.a_multiplier_hi);
+ const __m128i vrounding = _mm_load_si128((const __m128i*) params->sse4_mul16.rounding);
+ const __m128i vshift = _mm_cvtsi32_si128((int) params->sse4_mul16.shift);
+ const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->sse4_mul16.output_zero_point);
+ const __m128i voutput_min = _mm_load_si128((const __m128i*) params->sse4_mul16.output_min);
+ const __m128i voutput_max = _mm_load_si128((const __m128i*) params->sse4_mul16.output_max);
- __m128i vbias = _mm_cvtsi32_si128(params->sse2.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));
for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) {
const __m128i va01234567 = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) input_a));
const __m128i va89ABCDEF = _mm_cvtepi8_epi16(_mm_loadl_epi64((const __m128i*) (input_a + 8)));
@@ -82,18 +82,15 @@
__m128i voutGHIJKLMN = _mm_adds_epi16(_mm_packs_epi32(vaccGHIJ, vaccKLMN), voutput_zero_point);
__m128i voutOPQRSTUV = _mm_adds_epi16(_mm_packs_epi32(vaccOPQR, vaccSTUV), voutput_zero_point);
- vout01234567 = _mm_max_epi16(vout01234567, voutput_min);
- vout89ABCDEF = _mm_max_epi16(vout89ABCDEF, voutput_min);
- voutGHIJKLMN = _mm_max_epi16(voutGHIJKLMN, voutput_min);
- voutOPQRSTUV = _mm_max_epi16(voutOPQRSTUV, voutput_min);
- vout01234567 = _mm_min_epi16(vout01234567, voutput_max);
- vout89ABCDEF = _mm_min_epi16(vout89ABCDEF, voutput_max);
- voutGHIJKLMN = _mm_min_epi16(voutGHIJKLMN, voutput_max);
- voutOPQRSTUV = _mm_min_epi16(voutOPQRSTUV, voutput_max);
+ __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
+ __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV);
- const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
- const __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV);
+ vout0123456789ABCDEF = _mm_max_epi8(vout0123456789ABCDEF, voutput_min);
+ voutGHIJKLMNOPQRSTUV = _mm_max_epi8(voutGHIJKLMNOPQRSTUV, voutput_min);
+
+ vout0123456789ABCDEF = _mm_min_epi8(vout0123456789ABCDEF, voutput_max);
+ voutGHIJKLMNOPQRSTUV = _mm_min_epi8(voutGHIJKLMNOPQRSTUV, voutput_max);
_mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF);
_mm_storeu_si128((__m128i*) (output + 16), voutGHIJKLMNOPQRSTUV);
@@ -119,10 +116,10 @@
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);
__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);