Debian Codegraph @

src/qu8-rsum/gen/qu8-rsum-sse2-u32-acc2.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qu8-rsum/sse2.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 <emmintrin.h>
12
13 #include "xnnpack/common.h"
14 #include "xnnpack/reduce.h"
15
16 void xnn_qu8_rsum_ukernel__sse2_u32_acc2(
17 size_t batch,
18 const uint8_t* input,
19 uint32_t* output,
20 const struct xnn_qs8_rsum_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
21 {
22 assert(batch != 0);
23 assert(input != NULL);
24 assert(output != NULL);
25 assert(params != NULL);
26
27 XNN_ALIGN(16) static const int8_t mask_table[32] = {
28 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
30 };
31
32 const __m128i vzero = _mm_setzero_si128();
33 __m128i vacc0 = _mm_setzero_si128();
34 __m128i vacc1 = _mm_setzero_si128();
35
36 for (; batch >= 32; batch -= 32) {
37 const __m128i vin0 = _mm_loadu_si128((const __m128i*) (input + 0));
38 const __m128i vin1 = _mm_loadu_si128((const __m128i*) (input + 16));
39 input += 32;
40 const __m128i vt0 = _mm_sad_epu8(vin0, vzero);
41 const __m128i vt1 = _mm_sad_epu8(vin1, vzero);
42 vacc0 = _mm_add_epi32(vacc0, vt0);
43 vacc1 = _mm_add_epi32(vacc1, vt1);
44 }
45 vacc0 = _mm_add_epi32(vacc0, vacc1);
46
47 for (; batch >= 16; batch -= 16) {
48 const __m128i vin = _mm_loadu_si128((const __m128i*) input);
49 input += 16;
50 const __m128i vt = _mm_sad_epu8(vin, vzero);
51 vacc0 = _mm_add_epi32(vacc0, vt);
52 }
53
54 if (XNN_UNLIKELY(batch != 0)) {
55 assert(batch >= 1 && batch <= 15);
56 const __m128i vmask = _mm_loadu_si128((const __m128i*) &mask_table[16 - batch]);
57 const __m128i vt = _mm_sad_epu8(_mm_and_si128(_mm_loadu_si128((const __m128i*) input), vmask), vzero);
58 vacc0 = _mm_add_epi32(vacc0, vt);
59 }
60
61 vacc0 = _mm_add_epi32(vacc0, _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(vacc0), _mm_castsi128_ps(vacc0))));
62 vacc0 = _mm_add_epi32(vacc0, _mm_shuffle_epi32(vacc0, _MM_SHUFFLE(1, 1, 1, 1)));
63
64 *output += (uint32_t)_mm_cvtsi128_si32(vacc0);
65 }