Debian Codegraph @

src/f16-rsum/gen/f16-rsum-avx512fp16-u32.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-rsum/avx512fp16.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
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_f16_rsum_ukernel__avx512fp16_u32(
19 size_t batch,
20 const xnn_float16* input,
21 xnn_float16* output,
22 const struct xnn_f16_scale_params params[restrict XNN_MIN_ELEMENTS(1)])
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(uint16_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const uint16_t* i = (const uint16_t*) input;
30 uint16_t* o = (uint16_t*) output;
31 __m512h vacc0 = _mm512_setzero_ph();
32 for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) {
33 const __m512h vt = _mm512_loadu_ph(i);
34 i += 32;
35
36 vacc0 = _mm512_add_ph(vacc0, vt);
37 }
38 if XNN_UNLIKELY(batch != 0) {
39 assert(batch >= 1 * sizeof(uint16_t));
40 assert(batch <= 31 * sizeof(uint16_t));
41
42 // Prepare mask for valid elements (depends on batch).
43 batch >>= XNN_LOG2_SIZEOF_HALF;
44 const __mmask32 vmask = _cvtu32_mask32((uint32_t) ((UINT32_C(1) << batch) - UINT32_C(1)));
45
46 const __m512h vt = _mm512_castsi512_ph(_mm512_maskz_loadu_epi16(vmask, i));
47
48 vacc0 = _mm512_add_ph(vacc0, vt);
49 }
50
51 const __m256h vacc256 = _mm256_add_ph(_mm512_castph512_ph256(vacc0), _mm256_castpd_ph(_mm512_extractf64x4_pd(_mm512_castph_pd(vacc0), 1)));
52 __m128h vacc = _mm_add_ph(_mm256_castph256_ph128(vacc256), _mm_castps_ph(_mm256_extractf128_ps(_mm256_castph_ps(vacc256), 1)));
53 vacc = _mm_add_ph(vacc, _mm_castps_ph(_mm_movehl_ps(_mm_castph_ps(vacc), _mm_castph_ps(vacc))));
54 vacc = _mm_add_ph(vacc, _mm_castps_ph(_mm_movehdup_ps(_mm_castph_ps(vacc))));
55 vacc = _mm_add_sh(vacc, _mm_castsi128_ph(_mm_srli_epi32(_mm_castph_si128(vacc), 16)));
56
57 const __m128h vscale = _mm_castsi128_ph(_mm_set1_epi16(*(const uint16_t*) &params->scalar.scale));
58
59 vacc = _mm_mul_sh(vacc, vscale);
60 *((uint16_t*) o) = (uint16_t) _mm_extract_epi16(_mm_castph_si128(vacc), 0);
61 }