1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vadd/avx512skx-mul32-ld128.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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 <immintrin.h>
13
14 #include <xnnpack/intrinsics-polyfill.h>
15 #include <xnnpack/vadd.h>
16
17
xnn_qu8_vadd_minmax_ukernel__avx512skx_mul32_ld128_x32(size_t n,const uint8_t * input_a,const uint8_t * input_b,uint8_t * output,const union xnn_qu8_add_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_vadd_minmax_ukernel__avx512skx_mul32_ld128_x32(
19 size_t n,
20 const uint8_t* input_a,
21 const uint8_t* input_b,
22 uint8_t* output,
23 const union xnn_qu8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25 const __m512i vbias = _mm512_load_si512(params->avx512.bias);
26 const __m512i va_multiplier = _mm512_load_si512(params->avx512.a_multiplier);
27 const __m512i vb_multiplier = _mm512_load_si512(params->avx512.b_multiplier);
28 const __m128i vshift = _mm_load_si128((const __m128i*) params->avx512.shift);
29 const __m512i voutput_zero_point = _mm512_load_si512(params->avx512.output_zero_point);
30 const __m256i voutput_min = _mm256_load_si256((const __m256i*) params->avx512.output_min);
31 const __m256i voutput_max = _mm256_load_si256((const __m256i*) params->avx512.output_max);
32
33 for (; n >= 32 * sizeof(uint8_t); n -= 32 * sizeof(uint8_t)) {
34 const __m512i va0123456789ABCDEF = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) input_a));
35 const __m512i vb0123456789ABCDEF = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) input_b));
36 const __m512i vaGHIJKLMNOPQRSTUV = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) (input_a + 16)));
37 const __m512i vbGHIJKLMNOPQRSTUV = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) (input_b + 16)));
38 input_a += 32;
39 input_b += 32;
40
41 __m512i vacc0123456789ABCDEF = _mm512_add_epi32(vbias, _mm512_mullo_epi32(va0123456789ABCDEF, va_multiplier));
42 __m512i vaccGHIJKLMNOPQRSTUV = _mm512_add_epi32(vbias, _mm512_mullo_epi32(vaGHIJKLMNOPQRSTUV, va_multiplier));
43
44 vacc0123456789ABCDEF = _mm512_add_epi32(vacc0123456789ABCDEF, _mm512_mullo_epi32(vb0123456789ABCDEF, vb_multiplier));
45 vaccGHIJKLMNOPQRSTUV = _mm512_add_epi32(vaccGHIJKLMNOPQRSTUV, _mm512_mullo_epi32(vbGHIJKLMNOPQRSTUV, vb_multiplier));
46
47 vacc0123456789ABCDEF = _mm512_sra_epi32(vacc0123456789ABCDEF, vshift);
48 vaccGHIJKLMNOPQRSTUV = _mm512_sra_epi32(vaccGHIJKLMNOPQRSTUV, vshift);
49
50 __m512i vout0123GHIJ4567KLMN89ABOPQRCDEFSTUV = _mm512_adds_epi16(_mm512_packs_epi32(vacc0123456789ABCDEF, vaccGHIJKLMNOPQRSTUV), voutput_zero_point);
51
52 __m256i vout0123456789ABCDEFGHIJKLMNOPQRSTUV = _mm256_permutevar8x32_epi32(_mm256_packus_epi16(_mm512_castsi512_si256(vout0123GHIJ4567KLMN89ABOPQRCDEFSTUV), _mm512_extracti32x8_epi32(vout0123GHIJ4567KLMN89ABOPQRCDEFSTUV, 1)), _mm256_set_epi32(7, 3, 5, 1, 6, 2, 4, 0));
53
54 vout0123456789ABCDEFGHIJKLMNOPQRSTUV = _mm256_max_epu8(vout0123456789ABCDEFGHIJKLMNOPQRSTUV, voutput_min);
55
56 vout0123456789ABCDEFGHIJKLMNOPQRSTUV = _mm256_min_epu8(vout0123456789ABCDEFGHIJKLMNOPQRSTUV, voutput_max);
57
58 _mm256_storeu_si256((__m256i*) output, vout0123456789ABCDEFGHIJKLMNOPQRSTUV);
59 output += 32;
60 }
61 if XNN_UNLIKELY(n != 0) {
62 do {
63 const __m512i va0123456789ABCDEF = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) input_a));
64 const __m512i vb0123456789ABCDEF = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) input_b));
65 input_a += 16;
66 input_b += 16;
67
68 __m512i vacc0123456789ABCDEF = _mm512_add_epi32(vbias, _mm512_mullo_epi32(va0123456789ABCDEF, va_multiplier));
69
70 vacc0123456789ABCDEF = _mm512_add_epi32(vacc0123456789ABCDEF, _mm512_mullo_epi32(vb0123456789ABCDEF, vb_multiplier));
71
72 vacc0123456789ABCDEF = _mm512_sra_epi32(vacc0123456789ABCDEF, vshift);
73
74 __m256i vout012389AB4567CDEF = _mm256_adds_epi16(_mm256_packs_epi32(_mm512_castsi512_si256(vacc0123456789ABCDEF), _mm512_extracti32x8_epi32(vacc0123456789ABCDEF, 1)), _mm512_castsi512_si256(voutput_zero_point));
75 __m128i vout0123456789ABCDEF = _mm_shuffle_epi32(_mm_packus_epi16(_mm256_castsi256_si128(vout012389AB4567CDEF), _mm256_extracti128_si256(vout012389AB4567CDEF, 1)), _MM_SHUFFLE(3, 1, 2, 0));
76 vout0123456789ABCDEF = _mm_max_epu8(vout0123456789ABCDEF, _mm256_castsi256_si128(voutput_min));
77 vout0123456789ABCDEF = _mm_min_epu8(vout0123456789ABCDEF, _mm256_castsi256_si128(voutput_max));
78
79 if XNN_LIKELY(n >= (16 * sizeof(uint8_t))) {
80 _mm_storeu_si128((__m128i*) output, vout0123456789ABCDEF);
81 output += 16;
82 n -= 16 * sizeof(uint8_t);
83 } else {
84 const __mmask16 vmask = _cvtu32_mask16((uint32_t) ((UINT32_C(1) << n) - UINT32_C(1)));
85 _mm_mask_storeu_epi8(output, vmask, vout0123456789ABCDEF);
86 n = 0;
87 }
88 } while (n != 0);
89 }
90 }
91