Debian Codegraph @

src/f16-rminmax/gen/f16-rminmax-neonfp16arith-u8.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-rminmax/neonfp16arith.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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 <arm_neon.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/reduce.h"
16
17
18 void xnn_f16_rminmax_ukernel__neonfp16arith_u8(
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)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(uint16_t) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const uint16_t* i = (const uint16_t*) input;
30 uint16_t* o = (uint16_t*) output;
31 float16x8_t vmin0 = vreinterpretq_f16_u16(vld1q_dup_u16(i));
32 float16x8_t vmax0 = vmin0;
33 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
34 const float16x8_t vt = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8;
35 vmin0 = vminq_f16(vmin0, vt);
36 vmax0 = vmaxq_f16(vmax0, vt);
37 }
38 float16x4_t vmin_lo = vmin_f16(vget_low_f16(vmin0), vget_high_f16(vmin0));
39 float16x4_t vmax_lo = vmax_f16(vget_low_f16(vmax0), vget_high_f16(vmax0));
40
41 if (XNN_UNLIKELY(batch != 0)) {
42 const float16x8_t vt = vreinterpretq_f16_u16(vld1q_u16(i));
43 float16x4_t vt_lo = vget_low_f16(vt);
44 if (batch & (4 * sizeof(uint16_t))) {
45 vmin_lo = vmin_f16(vmin_lo, vt_lo);
46 vmax_lo = vmax_f16(vmax_lo, vt_lo);
47 vt_lo = vget_high_f16(vt);
48 }
49 if (batch & (2 * sizeof(uint16_t))) {
50 vmin_lo = vmin_f16(vmin_lo, vext_f16(vmin_lo, vt_lo, 2));
51 vmax_lo = vmax_f16(vmax_lo, vext_f16(vmax_lo, vt_lo, 2));
52 vt_lo = vext_f16(vt_lo, vt_lo, 2);
53 }
54 if (batch & (1 * sizeof(uint16_t))) {
55 vmin_lo = vmin_f16(vmin_lo, vext_f16(vmin_lo, vt_lo, 1));
56 vmax_lo = vmax_f16(vmax_lo, vext_f16(vmax_lo, vt_lo, 1));
57 }
58 }
59 #if XNN_ARCH_ARM64 && defined(__GNUC__)
60 *((__fp16*) o) = vminv_f16(vmin_lo);
61 #else
62 vmin_lo = vpmin_f16(vmin_lo, vmin_lo);
63 vmin_lo = vpmin_f16(vmin_lo, vmin_lo);
64 vst1_lane_u16(o, vreinterpret_u16_f16(vmin_lo), 0);
65 #endif
66 #if XNN_ARCH_ARM64 && defined(__GNUC__)
67 *((__fp16*) o + 1) = vmaxv_f16(vmax_lo);
68 #else
69 vmax_lo = vpmax_f16(vmax_lo, vmax_lo);
70 vmax_lo = vpmax_f16(vmax_lo, vmax_lo);
71 vst1_lane_u16(o + 1, vreinterpret_u16_f16(vmax_lo), 0);
72 #endif
73 }