Debian Codegraph @

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

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