Debian Codegraph @

src/f16-rminmax/gen/f16-rmax-avx512fp16-u96-acc3.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-rminmax/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_rmax_ukernel__avx512fp16_u96_acc3(
19 size_t batch,
20 const xnn_float16* input,
21 xnn_float16* output,
22 const struct xnn_f16_default_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 #if defined(__AVX512FP16__)
30 const uint16_t* i = (const uint16_t*) input;
31 __m512h vmax0 = _mm512_castsi512_ph(_mm512_set1_epi16(*i));
32 __m512h vmax1 = vmax0;
33 __m512h vmax2 = vmax0;
34 for (; batch >= 96 * sizeof(uint16_t); batch -= 96 * sizeof(uint16_t)) {
35 const __m512h vt0 = _mm512_loadu_ph(i);
36 const __m512h vt1 = _mm512_loadu_ph((i + 32));
37 const __m512h vt2 = _mm512_loadu_ph((i + 64));
38 i += 96;
39
40 vmax0 = _mm512_max_ph(vmax0, vt0);
41 vmax1 = _mm512_max_ph(vmax1, vt1);
42 vmax2 = _mm512_max_ph(vmax2, vt2);
43 }
44 vmax0 = _mm512_max_ph(vmax0, vmax1);
45 vmax0 = _mm512_max_ph(vmax0, vmax2);
46 for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) {
47 const __m512h vt = _mm512_loadu_ph(i);
48 i += 32;
49
50 vmax0 = _mm512_max_ph(vmax0, vt);
51 }
52 if XNN_UNLIKELY(batch != 0) {
53 assert(batch >= 1 * sizeof(uint16_t));
54 assert(batch <= 31 * sizeof(uint16_t));
55
56 // Prepare mask for valid elements (depends on batch).
57 batch >>= XNN_LOG2_SIZEOF_HALF;
58 const __mmask32 vmask = _cvtu32_mask32((uint32_t) ((UINT32_C(1) << batch) - UINT32_C(1)));
59
60 const __m512h vt = _mm512_castsi512_ph(_mm512_maskz_loadu_epi16(vmask, i));
61
62 vmax0 = _mm512_mask_max_ph(vmax0, vmask, vmax0, vt);
63 }
64 __m256h vmax256 = _mm256_max_ph(_mm512_castph512_ph256(vmax0), _mm256_castpd_ph(_mm512_extractf64x4_pd(_mm512_castph_pd(vmax0), 1)));
65 __m128h vmax = _mm_max_ph(_mm256_castph256_ph128(vmax256), _mm_castps_ph(_mm256_extractf128_ps(_mm256_castph_ps(vmax256), 1)));
66 vmax = _mm_max_ph(vmax, _mm_castps_ph(_mm_movehl_ps(_mm_castph_ps(vmax), _mm_castph_ps(vmax))));
67 vmax = _mm_max_ph(vmax, _mm_castps_ph(_mm_movehdup_ps(_mm_castph_ps(vmax))));
68 vmax = _mm_max_sh(vmax, _mm_castsi128_ph(_mm_srli_epi32(_mm_castph_si128(vmax), 16)));
69
70 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(_mm_castph_si128(vmax), 0);
71 #endif // defined(__AVX512FP16__)
72 }