Debian Codegraph @

src/f32-rsum/gen/f32-rsum-avx-u32-acc4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-rsum/avx.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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/common.h"
15 #include "xnnpack/reduce.h"
16
17
18 void xnn_f32_rsum_ukernel__avx_u32_acc4(
19 size_t batch,
20 const float* input,
21 float* output,
22 const struct xnn_f32_scale_params params[restrict XNN_MIN_ELEMENTS(1)])
23 {
24 static const int32_t mask_table[14] = {-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0};
25
26 assert(batch != 0);
27 assert(batch % sizeof(float) == 0);
28 assert(input != NULL);
29 assert(output != NULL);
30
31 __m256 vacc0 = _mm256_setzero_ps();
32 __m256 vacc1 = _mm256_setzero_ps();
33 __m256 vacc2 = _mm256_setzero_ps();
34 __m256 vacc3 = _mm256_setzero_ps();
35 for (; batch >= 32 * sizeof(float); batch -= 32 * sizeof(float)) {
36 const __m256 vt0 = _mm256_loadu_ps(input);
37 const __m256 vt1 = _mm256_loadu_ps(input + 8);
38 const __m256 vt2 = _mm256_loadu_ps(input + 16);
39 const __m256 vt3 = _mm256_loadu_ps(input + 24);
40 input += 32;
41
42 vacc0 = _mm256_add_ps(vacc0, vt0);
43 vacc1 = _mm256_add_ps(vacc1, vt1);
44 vacc2 = _mm256_add_ps(vacc2, vt2);
45 vacc3 = _mm256_add_ps(vacc3, vt3);
46 }
47 vacc0 = _mm256_add_ps(vacc0, vacc1);
48 vacc2 = _mm256_add_ps(vacc2, vacc3);
49 vacc0 = _mm256_add_ps(vacc0, vacc2);
50 for (; batch >= 8 * sizeof(float); batch -= 8 * sizeof(float)) {
51 const __m256 vt = _mm256_loadu_ps(input);
52 input += 8;
53
54 vacc0 = _mm256_add_ps(vacc0, vt);
55 }
56 if XNN_UNLIKELY(batch != 0) {
57 assert(batch >= 1 * sizeof(float));
58 assert(batch <= 7 * sizeof(float));
59 const __m256i vmask = _mm256_loadu_si256((const __m256i*) ((uintptr_t) &mask_table[7] - batch));
60 const __m256 vt = _mm256_maskload_ps(input, vmask);
61 vacc0 = _mm256_add_ps(vacc0, vt);
62 }
63 __m128 vacc = _mm_add_ps(_mm256_castps256_ps128(vacc0), _mm256_extractf128_ps(vacc0, 1));
64 vacc = _mm_add_ps(vacc, _mm_movehl_ps(vacc, vacc));
65 vacc = _mm_add_ss(vacc, _mm_movehdup_ps(vacc));
66 vacc = _mm_mul_ss(vacc, _mm_load_ss(&params->scalar.scale));
67 *output += _mm_cvtss_f32(vacc);
68 }