Debian Codegraph @

src/f16-vbinary/gen/f16-vprelu-avx512fp16-u32.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_u32(
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 >= 32 * sizeof(uint16_t); batch -= 32 * sizeof(uint16_t)) {
39 const __m512h va = _mm512_loadu_ph(a);
40 a += 32;
41
42 const __mmask32 vsign = _mm512_cmp_ph_mask(va, vzero, _CMP_LT_OQ);
43 __m512h vacc = _mm512_mask_mul_ph(va, vsign, va, _mm512_loadu_ph(b));
44 b += 32;
45
46 _mm512_storeu_ph(o, vacc);
47 o += 32;
48 }
49 if XNN_UNLIKELY(batch != 0) {
50 assert(batch >= 1 * sizeof(uint16_t));
51 assert(batch <= 31 * sizeof(uint16_t));
52 // Prepare mask for valid 16-bit elements (depends on batch).
53 batch >>= XNN_LOG2_SIZEOF_HALF;
54 const __mmask32 vmask = _cvtu32_mask32((uint32_t) ((UINT32_C(1) << batch) - UINT32_C(1)));
55
56 const __m512h va = _mm512_castsi512_ph(_mm512_maskz_loadu_epi16(vmask, a));
57
58 const __mmask32 vsign = _mm512_cmp_ph_mask(va, vzero, _CMP_LT_OQ);
59 __m512h vacc = _mm512_mask_mul_ph(va, vsign, va, _mm512_loadu_ph(b));
60
61 _mm512_mask_storeu_epi16(o, vmask, _mm512_castph_si512(vacc));
62 }
63 #endif // defined(__AVX512FP16__)
64 }