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-vadd/gen/minmax-avx-mul32-ld32-x32.c b/src/qs8-vadd/gen/minmax-avx-mul32-ld32-x32.c
index 5303bef..994ffb1 100644
--- a/src/qs8-vadd/gen/minmax-avx-mul32-ld32-x32.c
+++ b/src/qs8-vadd/gen/minmax-avx-mul32-ld32-x32.c
@@ -22,14 +22,14 @@
int8_t* output,
const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
{
- const __m128i vbias = _mm_load_si128((const __m128i*) params->sse2.bias);
- const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse2.a_multiplier);
- const __m128i vb_multiplier = _mm_load_si128((const __m128i*) params->sse2.b_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 vbias = _mm_load_si128((const __m128i*) params->sse4_mul32.bias);
+ const __m128i va_multiplier = _mm_load_si128((const __m128i*) params->sse4_mul32.a_multiplier);
+ const __m128i vb_multiplier = _mm_load_si128((const __m128i*) params->sse4_mul32.b_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);
for (; n >= 32 * sizeof(int8_t); n -= 32 * sizeof(int8_t)) {
const __m128i va0123 = _mm_cvtepi8_epi32(_mm_loadu_si32(input_a));
@@ -78,23 +78,19 @@
vaccOPQR = _mm_sra_epi32(_mm_add_epi32(vaccOPQR, vrounding), vshift);
vaccSTUV = _mm_sra_epi32(_mm_add_epi32(vaccSTUV, 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);
- __m128i voutOPQRSTUV = _mm_adds_epi16(_mm_packs_epi32(vaccOPQR, vaccSTUV), 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);
+ const __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);
+ __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
+ __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV);
- 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);
+ vout0123456789ABCDEF = _mm_max_epi8(vout0123456789ABCDEF, voutput_min);
+ voutGHIJKLMNOPQRSTUV = _mm_max_epi8(voutGHIJKLMNOPQRSTUV, voutput_min);
- const __m128i vout0123456789ABCDEF = _mm_packs_epi16(vout01234567, vout89ABCDEF);
- const __m128i voutGHIJKLMNOPQRSTUV = _mm_packs_epi16(voutGHIJKLMN, voutOPQRSTUV);
+ 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);
@@ -118,11 +114,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);