Debian Codegraph @

src/f16-rminmax/gen/f16-rmax-avx512fp16-u32.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_u32(
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 for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) {
33 const __m512h vt = _mm512_loadu_ph(i);
34 i += 32;
35
36 vmax0 = _mm512_max_ph(vmax0, 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 vmax0 = _mm512_mask_max_ph(vmax0, vmask, vmax0, vt);
49 }
50 __m256h vmax256 = _mm256_max_ph(_mm512_castph512_ph256(vmax0), _mm256_castpd_ph(_mm512_extractf64x4_pd(_mm512_castph_pd(vmax0), 1)));
51 __m128h vmax = _mm_max_ph(_mm256_castph256_ph128(vmax256), _mm_castps_ph(_mm256_extractf128_ps(_mm256_castph_ps(vmax256), 1)));
52 vmax = _mm_max_ph(vmax, _mm_castps_ph(_mm_movehl_ps(_mm_castph_ps(vmax), _mm_castph_ps(vmax))));
53 vmax = _mm_max_ph(vmax, _mm_castps_ph(_mm_movehdup_ps(_mm_castph_ps(vmax))));
54 vmax = _mm_max_sh(vmax, _mm_castsi128_ph(_mm_srli_epi32(_mm_castph_si128(vmax), 16)));
55
56 *((uint16_t*) output) = (uint16_t) _mm_extract_epi16(_mm_castph_si128(vmax), 0);
57 #endif // defined(__AVX512FP16__)
58 }