Debian Codegraph @

src/f16-velu/gen/f16-velu-neonfp16arith-rr1-p3-u8.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-velu/neonfp16arith-rr1-p3.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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_velu_ukernel__neonfp16arith_rr1_p3_u8(
19 size_t batch,
20 const xnn_float16* input,
21 xnn_float16* output,
22 const struct xnn_f16_elu_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 float16x8_t vsat_cutoff = vreinterpretq_f16_u16(vmovq_n_u16(UINT16_C(0xC829))); // -0x1.0A4p+3h
30 const float16x8_t vmagic_bias = vreinterpretq_f16_u16(vmovq_n_u16(UINT16_C(0x660F))); // 0x1.83Cp+10h
31 const float16x8_t vlog2e = vreinterpretq_f16_u16(vmovq_n_u16(UINT16_C(0x3DC5))); // 0x1.714p+0h
32 const float16x8_t vminus_ln2 = vreinterpretq_f16_u16(vmovq_n_u16(UINT16_C(0xB98C))); // -0x1.62E430p-1h
33 const float16x8_t vc3 = vreinterpretq_f16_u16(vmovq_n_u16(UINT16_C(0x315B))); // 0x1.56Cp-3h
34 const float16x8_t vc2 = vreinterpretq_f16_u16(vmovq_n_u16(UINT16_C(0x3808))); // 0x1.020p-1h
35
36 XNN_FORCE_REALIZATION(vsat_cutoff);
37 XNN_FORCE_REALIZATION(vmagic_bias);
38 XNN_FORCE_REALIZATION(vlog2e);
39 XNN_FORCE_REALIZATION(vminus_ln2);
40 XNN_FORCE_REALIZATION(vc3);
41 XNN_FORCE_REALIZATION(vc2);
42
43 const float16x8_t vprescale = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.prescale));
44 const float16x8_t vminus_alpha = vnegq_f16(vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.alpha)));
45 const float16x8_t vbeta = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) &params->scalar.beta));
46
47 const uint16_t* i = (const uint16_t*) input;
48 uint16_t* o = (uint16_t*) output;
49 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
50 float16x8_t vx = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8;
51 float16x8_t vz = vmulq_f16(vx, vprescale);
52 vz = vmaxq_f16(vz, vsat_cutoff);
53
54 float16x8_t vn = vfmaq_f16(vmagic_bias, vz, vlog2e);
55 float16x8_t vs = vreinterpretq_f16_s16(vshlq_n_s16(vreinterpretq_s16_f16(vn), 10));
56 vn = vsubq_f16(vn, vmagic_bias);
57 float16x8_t vt = vfmaq_f16(vz, vn, vminus_ln2);
58
59 float16x8_t vp = vfmaq_f16(vc2, vc3, vt);
60 vp = vmulq_f16(vp, vt);
61 vt = vmulq_f16(vt, vs);
62 vs = vfmsq_f16(vminus_alpha, vs, vminus_alpha);
63 vp = vfmaq_f16(vt, vp, vt);
64 float16x8_t ve = vfmsq_f16(vs, vp, vminus_alpha);
65
66 const uint16x8_t vm = vcltq_s16(vreinterpretq_s16_f16(vx), vmovq_n_s16(0));
67 vx = vmulq_f16(vx, vbeta);
68 const float16x8_t vy = vbslq_f16(vm, ve, vx);
69 vst1q_u16(o, vreinterpretq_u16_f16(vy)); o += 8;
70 }
71 if XNN_UNLIKELY(batch != 0) {
72 float16x8_t vx = vreinterpretq_f16_u16(vld1q_u16(i)); i += 8;
73 float16x8_t vz = vmulq_f16(vx, vprescale);
74 vz = vmaxq_f16(vz, vsat_cutoff);
75
76 float16x8_t vn = vfmaq_f16(vmagic_bias, vz, vlog2e);
77 float16x8_t vs = vreinterpretq_f16_s16(vshlq_n_s16(vreinterpretq_s16_f16(vn), 10));
78 vn = vsubq_f16(vn, vmagic_bias);
79 float16x8_t vt = vfmaq_f16(vz, vn, vminus_ln2);
80
81 float16x8_t vp = vfmaq_f16(vc2, vc3, vt);
82 vp = vmulq_f16(vp, vt);
83 vt = vmulq_f16(vt, vs);
84 vs = vfmsq_f16(vminus_alpha, vs, vminus_alpha);
85 vp = vfmaq_f16(vt, vp, vt);
86 float16x8_t ve = vfmsq_f16(vs, vp, vminus_alpha);
87
88 const uint16x8_t vm = vcltq_s16(vreinterpretq_s16_f16(vx), vmovq_n_s16(0));
89 vx = vmulq_f16(vx, vbeta);
90 float16x8_t vy = vbslq_f16(vm, ve, vx);
91 float16x4_t vy_lo = vget_low_f16(vy);
92 if (batch & (4 * sizeof(uint16_t))) {
93 vst1_u16(o, vreinterpret_u16_f16(vy_lo)); o += 4;
94 vy_lo = vget_high_f16(vy);
95 }
96 if (batch & (2 * sizeof(uint16_t))) {
97 vst1_lane_u32((void*) o, vreinterpret_u32_f16(vy_lo), 0); o += 2;
98 vy_lo = vext_f16(vy_lo, vy_lo, 2);
99 }
100 if (batch & (1 * sizeof(uint16_t))) {
101 vst1_lane_u16(o, vreinterpret_u16_f16(vy_lo), 0);
102 }
103 }
104 }