Debian Codegraph @

src/f16-vclamp/gen/f16-vclamp-neonfp16arith-u16.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-vclamp/neonfp16arith.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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/vunary.h"
16
17
18 void xnn_f16_vclamp_ukernel__neonfp16arith_u16(
19 size_t batch,
20 const xnn_float16* restrict input,
21 xnn_float16* restrict output,
22 const union xnn_f16_minmax_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 const uint16_t* i = (const uint16_t*) input;
30 uint16_t* o = (uint16_t*) output;
31
32 #if XNN_ARCH_ARM64
33 const uint16x8x2_t vminmax = vld2q_dup_u16((const uint16_t*) &params->scalar.min);
34 const float16x8_t vmin = vreinterpretq_f16_u16(vminmax.val[0]);
35 const float16x8_t vmax = vreinterpretq_f16_u16(vminmax.val[1]);
36 #else
37 // vld2_dup is to work around aarch32 clang bug with vld1q_dup
38 const uint16x4x2_t vminmax = vld2_dup_u16((const uint16_t*) &params->scalar.min);
39 const float16x8_t vmin = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[0], vminmax.val[0]));
40 const float16x8_t vmax = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[1], vminmax.val[1]));
41 #endif
42
43 for (; batch >= 16 * sizeof(uint16_t); batch -= 16 * sizeof(uint16_t)) {
44 float16x8_t vacc01234567 = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8;
45 float16x8_t vacc89ABCDEF = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8;
46
47 vacc01234567 = vmaxq_f16(vacc01234567, vmin);
48 vacc89ABCDEF = vmaxq_f16(vacc89ABCDEF, vmin);
49
50 vacc01234567 = vminq_f16(vacc01234567, vmax);
51 vacc89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
52
53 vst1q_u16(o, vreinterpretq_u16_f16(vacc01234567)); o += 8;
54 vst1q_u16(o, vreinterpretq_u16_f16(vacc89ABCDEF)); o += 8;
55 }
56 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
57 float16x8_t vacc = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8;
58 vacc = vmaxq_f16(vacc, vmin);
59 vacc = vminq_f16(vacc, vmax);
60 vst1q_u16(o, vreinterpretq_u16_f16(vacc)); o += 8;
61 }
62 if XNN_UNLIKELY(batch != 0) {
63 if (batch & (4 * sizeof(uint16_t))) {
64 float16x4_t vacc = vreinterpret_f16_u16(vld1_u16(i)); i += 4;
65 vacc = vmax_f16(vacc, vget_low_f16(vmin));
66 vacc = vmin_f16(vacc, vget_low_f16(vmax));
67 vst1_u16(o, vreinterpret_u16_f16(vacc)); o += 4;
68 }
69 if (batch & (2 * sizeof(uint16_t))) {
70 float16x4_t vacc = vreinterpret_f16_u32(vld1_dup_u32((const void*) i)); i += 2;
71 vacc = vmax_f16(vacc, vget_low_f16(vmin));
72 vacc = vmin_f16(vacc, vget_low_f16(vmax));
73 vst1_lane_u32((void*) o, vreinterpret_u32_f16(vacc), 0); o += 2;
74 }
75 if (batch & (1 * sizeof(uint16_t))) {
76 float16x4_t vacc = vreinterpret_f16_u16(vld1_dup_u16(i));
77 vacc = vmax_f16(vacc, vget_low_f16(vmin));
78 vacc = vmin_f16(vacc, vget_low_f16(vmax));
79 vst1_lane_u16(o, vreinterpret_u16_f16(vacc), 0);
80 }
81 }
82 }