Debian Codegraph @

src/qu8-rsum/gen/qu8-rsum-avx2-u32.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qu8-rsum/avx2.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 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 #include <assert.h>
10
11 #include <immintrin.h>
12
13 #include "xnnpack/common.h"
14 #include "xnnpack/reduce.h"
15
16
17 void xnn_qu8_rsum_ukernel__avx2_u32(
18 size_t batch,
19 const uint8_t* input,
20 uint32_t* output,
21 const struct xnn_qs8_rsum_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
22 {
23 assert(batch != 0);
24 assert(input != NULL);
25 assert(output != NULL);
26 assert(params != NULL);
27
28 XNN_ALIGN(16) static const int8_t mask_table[32] = {
29 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31 };
32
33 const __m256i vzero = _mm256_setzero_si256();
34 __m256i vacc0 = _mm256_setzero_si256();
35
36 for (; batch >= 32; batch -= 32) {
37 const __m256i vin0 = _mm256_loadu_si256((const __m256i*) (input + 0));
38 input += 32;
39 const __m256i vt0 = _mm256_sad_epu8(vin0, vzero);
40 vacc0 = _mm256_add_epi32(vacc0, vt0);
41 }
42
43 __m128i vacc = _mm_add_epi32(_mm256_castsi256_si128(vacc0), _mm256_extractf128_si256(vacc0, 1));
44
45 for (; batch >= 16; batch -= 16) {
46 const __m128i vin = _mm_loadu_si128((const __m128i*) input);
47 input += 16;
48 const __m128i vt = _mm_sad_epu8(vin, _mm_setzero_si128());
49 vacc = _mm_add_epi32(vacc, vt);
50 }
51
52 if (XNN_UNLIKELY(batch != 0)) {
53 assert(batch >= 1 && batch <= 15);
54 const __m128i vmask = _mm_loadu_si128((const __m128i*) &mask_table[16 - batch]);
55 const __m128i vt = _mm_sad_epu8(_mm_and_si128(_mm_loadu_si128((const __m128i*) input), vmask), _mm_setzero_si128());
56 vacc = _mm_add_epi32(vacc, vt);
57 }
58
59 vacc = _mm_hadd_epi32(vacc, vacc);
60 vacc = _mm_hadd_epi32(vacc, vacc);
61 *output += (uint32_t)_mm_cvtsi128_si32(vacc);
62 }
63
64
65