1 // Auto-generated file. Do not edit!
2 // Template: src/f16-prelu/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/math.h>
15 #include <xnnpack/prelu.h>
16
17
xnn_f16_prelu_ukernel__neonfp16arith_2x8(size_t rows,size_t channels,const void * restrict input,size_t input_stride,const void * restrict weights,void * restrict output,size_t output_stride)18 void xnn_f16_prelu_ukernel__neonfp16arith_2x8(
19 size_t rows,
20 size_t channels,
21 const void* restrict input,
22 size_t input_stride,
23 const void* restrict weights,
24 void* restrict output,
25 size_t output_stride) XNN_DISABLE_TSAN
26 {
27 assert(rows != 0);
28 assert(channels != 0);
29 assert(channels % sizeof(__fp16) == 0);
30
31 const __fp16* i0 = (const __fp16*) input;
32 __fp16* o0 = (__fp16*) output;
33
34 const __fp16* i1 = (const __fp16*) ((uintptr_t) i0 + input_stride);
35 __fp16* o1 = (__fp16*) ((uintptr_t) o0 + output_stride);
36 if XNN_UNPREDICTABLE(rows < 2) {
37 i1 = i0;
38 o1 = o0;
39 }
40
41 const size_t input_increment = input_stride * 2 - channels;
42 const size_t output_increment = output_stride * 2 - channels;
43
44 do {
45 const __fp16* w = (const __fp16*) weights;
46 size_t c = channels;
47 for (; c >= 8 * sizeof(__fp16); c -= 8 * sizeof(__fp16)) {
48 const float16x8_t vw01234567 = vld1q_f16(w); w += 8;
49
50 const float16x8_t vi0x001234567 = vld1q_f16(i0); i0 += 8;
51 const float16x8_t vi1x001234567 = vld1q_f16(i1); i1 += 8;
52
53 float16x8_t vacc0x001234567 = vmulq_f16(vi0x001234567, vw01234567);
54 const uint16x8_t vm0x001234567 = vcltq_s16(vreinterpretq_s16_f16(vi0x001234567), vmovq_n_s16(0));
55 float16x8_t vacc1x001234567 = vmulq_f16(vi1x001234567, vw01234567);
56 const uint16x8_t vm1x001234567 = vcltq_s16(vreinterpretq_s16_f16(vi1x001234567), vmovq_n_s16(0));
57
58 vacc0x001234567 = vbslq_f16(vm0x001234567, vacc0x001234567, vi0x001234567);
59 vacc1x001234567 = vbslq_f16(vm1x001234567, vacc1x001234567, vi1x001234567);
60
61 vst1q_f16(o0, vacc0x001234567); o0 += 8;
62 vst1q_f16(o1, vacc1x001234567); o1 += 8;
63 }
64 if XNN_UNLIKELY(c != 0) {
65 const float16x8_t vw01234567 = vld1q_f16(w); w += 8;
66
67 const float16x8_t vi0x01234567 = vld1q_f16(i0);
68 i0 = (const __fp16*) ((uintptr_t) i0 + c);
69 const float16x8_t vi1x01234567 = vld1q_f16(i1);
70 i1 = (const __fp16*) ((uintptr_t) i1 + c);
71
72 float16x8_t vacc0x01234567 = vmulq_f16(vi0x01234567, vw01234567);
73 const uint16x8_t vm0x01234567 = vcltq_s16(vreinterpretq_s16_f16(vi0x01234567), vmovq_n_s16(0));
74 float16x8_t vacc1x01234567 = vmulq_f16(vi1x01234567, vw01234567);
75 const uint16x8_t vm1x01234567 = vcltq_s16(vreinterpretq_s16_f16(vi1x01234567), vmovq_n_s16(0));
76
77 vacc0x01234567 = vbslq_f16(vm0x01234567, vacc0x01234567, vi0x01234567);
78 vacc1x01234567 = vbslq_f16(vm1x01234567, vacc1x01234567, vi1x01234567);
79
80 float16x4_t vacc0x0123 = vget_low_f16(vacc0x01234567);
81 float16x4_t vacc1x0123 = vget_low_f16(vacc1x01234567);
82 if (c & (4 * sizeof(__fp16))) {
83 vst1_f16(o0, vacc0x0123); o0 += 4;
84 vst1_f16(o1, vacc1x0123); o1 += 4;
85
86 vacc0x0123 = vget_high_f16(vacc0x01234567);
87 vacc1x0123 = vget_high_f16(vacc1x01234567);
88 }
89 if (c & (2 * sizeof(__fp16))) {
90 vst1_lane_u32(__builtin_assume_aligned(o0, 1), vreinterpret_u32_f16(vacc0x0123), 0); o0 += 2;
91 vacc0x0123 = vext_f16(vacc0x0123, vacc0x0123, 2);
92 vst1_lane_u32(__builtin_assume_aligned(o1, 1), vreinterpret_u32_f16(vacc1x0123), 0); o1 += 2;
93 vacc1x0123 = vext_f16(vacc1x0123, vacc1x0123, 2);
94 }
95 if (c & (1 * sizeof(__fp16))) {
96 vst1_lane_f16(o0, vacc0x0123, 0); o0 += 1;
97 vst1_lane_f16(o1, vacc1x0123, 0); o1 += 1;
98 }
99 }
100 i0 = (const __fp16*) ((uintptr_t) i0 + input_increment);
101 o0 = (__fp16*) ((uintptr_t) o0 + output_increment);
102 i1 = (const __fp16*) ((uintptr_t) i1 + input_increment);
103 o1 = (__fp16*) ((uintptr_t) o1 + output_increment);
104 if XNN_UNPREDICTABLE(rows < 4) {
105 i1 = i0;
106 o1 = o0;
107 }
108 rows = doz(rows, 2);
109 } while (rows != 0);
110 }
111