1 // Auto-generated file. Do not edit!
2 // Template: src/f32-hswish/neon.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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/hswish.h>
16
17
xnn_f32_hswish_ukernel__neon_x16(size_t n,const float * x,float * y,const union xnn_f32_hswish_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_hswish_ukernel__neon_x16(
19 size_t n,
20 const float* x,
21 float* y,
22 const union xnn_f32_hswish_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
23 {
24 assert(n != 0);
25 assert(n % sizeof(float) == 0);
26
27 const float32x4_t vsixth = vld1q_dup_f32(¶ms->scalar.sixth);
28 const float32x4_t vthree = vld1q_dup_f32(¶ms->scalar.three);
29 const int32x4_t vsix = vreinterpretq_s32_f32(vld1q_dup_f32(¶ms->scalar.six));
30 const int32x4_t vzero = vdupq_n_s32(0);
31
32 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
33 float32x4_t vx0123 = vld1q_f32(x); x += 4;
34 float32x4_t vx4567 = vld1q_f32(x); x += 4;
35 float32x4_t vx89AB = vld1q_f32(x); x += 4;
36 float32x4_t vxCDEF = vld1q_f32(x); x += 4;
37
38 float32x4_t vacc0123 = vaddq_f32(vx0123, vthree);
39 vx0123 = vmulq_f32(vx0123, vsixth);
40 float32x4_t vacc4567 = vaddq_f32(vx4567, vthree);
41 vx4567 = vmulq_f32(vx4567, vsixth);
42 float32x4_t vacc89AB = vaddq_f32(vx89AB, vthree);
43 vx89AB = vmulq_f32(vx89AB, vsixth);
44 float32x4_t vaccCDEF = vaddq_f32(vxCDEF, vthree);
45 vxCDEF = vmulq_f32(vxCDEF, vsixth);
46
47 vacc0123 = vreinterpretq_f32_s32(vmaxq_s32(vreinterpretq_s32_f32(vacc0123), vzero));
48 vacc4567 = vreinterpretq_f32_s32(vmaxq_s32(vreinterpretq_s32_f32(vacc4567), vzero));
49 vacc89AB = vreinterpretq_f32_s32(vmaxq_s32(vreinterpretq_s32_f32(vacc89AB), vzero));
50 vaccCDEF = vreinterpretq_f32_s32(vmaxq_s32(vreinterpretq_s32_f32(vaccCDEF), vzero));
51
52 vacc0123 = vreinterpretq_f32_s32(vminq_s32(vreinterpretq_s32_f32(vacc0123), vsix));
53 vacc4567 = vreinterpretq_f32_s32(vminq_s32(vreinterpretq_s32_f32(vacc4567), vsix));
54 vacc89AB = vreinterpretq_f32_s32(vminq_s32(vreinterpretq_s32_f32(vacc89AB), vsix));
55 vaccCDEF = vreinterpretq_f32_s32(vminq_s32(vreinterpretq_s32_f32(vaccCDEF), vsix));
56
57 vacc0123 = vmulq_f32(vacc0123, vx0123);
58 vacc4567 = vmulq_f32(vacc4567, vx4567);
59 vacc89AB = vmulq_f32(vacc89AB, vx89AB);
60 vaccCDEF = vmulq_f32(vaccCDEF, vxCDEF);
61
62 vst1q_f32(y, vacc0123); y += 4;
63 vst1q_f32(y, vacc4567); y += 4;
64 vst1q_f32(y, vacc89AB); y += 4;
65 vst1q_f32(y, vaccCDEF); y += 4;
66 }
67 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
68 float32x4_t vx = vld1q_f32(x); x += 4;
69 float32x4_t vacc = vaddq_f32(vx, vthree);
70 vx = vmulq_f32(vx, vsixth);
71 vacc = vreinterpretq_f32_s32(vmaxq_s32(vreinterpretq_s32_f32(vacc), vzero));
72 vacc = vreinterpretq_f32_s32(vminq_s32(vreinterpretq_s32_f32(vacc), vsix));
73 vacc = vmulq_f32(vacc, vx);
74 vst1q_f32(y, vacc); y += 4;
75 }
76 if XNN_UNLIKELY(n != 0) {
77 float32x4_t vx = vld1q_f32(x);
78 float32x4_t vacc = vaddq_f32(vx, vthree);
79 vx = vmulq_f32(vx, vsixth);
80 vacc = vreinterpretq_f32_s32(vmaxq_s32(vreinterpretq_s32_f32(vacc), vzero));
81 vacc = vreinterpretq_f32_s32(vminq_s32(vreinterpretq_s32_f32(vacc), vsix));
82 vacc = vmulq_f32(vacc, vx);
83
84 float32x2_t vacc_lo = vget_low_f32(vacc);
85 if (n & (2 * sizeof(float))) {
86 vst1_f32(y, vacc_lo); y += 2;
87 vacc_lo = vget_high_f32(vacc);
88 }
89 if (n & (1 * sizeof(float))) {
90 vst1_lane_f32(y, vacc_lo, 0);
91 }
92 }
93 }
94