Debian Codegraph @

src/f16-vbinary/gen/f16-vmaxc-avx512fp16-u64.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-vbinary/vopc-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/intrinsics-polyfill.h"
16 #include "xnnpack/vbinary.h"
17
18
19 void xnn_f16_vmaxc_ukernel__avx512fp16_u64(
20 size_t batch,
21 const xnn_float16* restrict input_a,
22 const xnn_float16* restrict input_b,
23 xnn_float16* restrict output,
24 const struct xnn_f16_default_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26 assert(batch != 0);
27 assert(batch % sizeof(uint16_t) == 0);
28 assert(input_a != NULL);
29 assert(input_b != NULL);
30 assert(output != NULL);
31
32 #if defined(__AVX512FP16__)
33 const uint16_t* a = (const uint16_t*) input_a;
34 const uint16_t* b = (const uint16_t*) input_b;
35 uint16_t* o = (uint16_t*) output;
36
37 const __m512h vb = _mm512_castsi512_ph(_mm512_set1_epi16(*b));
38
39
40 for (; batch >= 64 * sizeof(uint16_t); batch -= 64 * sizeof(uint16_t)) {
41 __m512h va0 = _mm512_loadu_ph(a);
42 __m512h va1 = _mm512_loadu_ph(a + 32);
43 a += 64;
44
45 __m512h vacc0 = _mm512_max_ph(va0, vb);
46 __m512h vacc1 = _mm512_max_ph(va1, vb);
47
48
49 _mm512_storeu_ph(o, vacc0);
50 _mm512_storeu_ph(o + 32, vacc1);
51 o += 64;
52 }
53 for (; batch >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) {
54 __m512h va = _mm512_loadu_ph(a);
55 a += 32;
56
57 __m512h vacc = _mm512_max_ph(va, vb);
58
59 _mm512_storeu_ph(o, vacc);
60 o += 32;
61 }
62 if XNN_UNLIKELY(batch != 0) {
63 assert(batch >= 1 * sizeof(uint16_t));
64 assert(batch <= 31 * sizeof(uint16_t));
65 // Prepare mask for valid 16-bit elements (depends on batch).
66 batch >>= XNN_LOG2_SIZEOF_HALF;
67 const __mmask32 vmask = _cvtu32_mask32((uint32_t) ((UINT32_C(1) << batch) - UINT32_C(1)));
68
69 __m512h va = _mm512_castsi512_ph(_mm512_maskz_loadu_epi16(vmask, a));
70
71 __m512h vacc = _mm512_maskz_max_ph(vmask, va, vb);
72
73 _mm512_mask_storeu_epi16(o, vmask, _mm512_castph_si512(vacc));
74 }
75 #endif // defined(__AVX512FP16__)
76 }