xref: /aosp_15_r20/external/XNNPACK/src/f32-prelu/gen/neon-1x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-prelu/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/math.h>
15 #include <xnnpack/prelu.h>
16 
17 
xnn_f32_prelu_ukernel__neon_1x16(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride)18 void xnn_f32_prelu_ukernel__neon_1x16(
19     size_t rows,
20     size_t channels,
21     const float*restrict input,
22     size_t input_stride,
23     const float*restrict weights,
24     float*restrict output,
25     size_t output_stride) XNN_OOB_READS
26 {
27   assert(rows != 0);
28   assert(channels != 0);
29   assert(channels % sizeof(float) == 0);
30 
31   const float* i0 = input;
32   float* o0 = output;
33 
34   const size_t input_increment = input_stride * 1 - channels;
35   const size_t output_increment = output_stride * 1 - channels;
36 
37   do {
38 
39     const float* w = weights;
40     size_t c = channels;
41     for (; c >= 16 * sizeof(float); c -= 16 * sizeof(float)) {
42       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
43       const float32x4_t vw4567 = vld1q_f32(w); w += 4;
44       const float32x4_t vw89AB = vld1q_f32(w); w += 4;
45       const float32x4_t vwCDEF = vld1q_f32(w); w += 4;
46 
47       const float32x4_t vi0x0123 = vld1q_f32(i0); i0 += 4;
48       const float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
49       const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
50       const float32x4_t vi0xCDEF = vld1q_f32(i0); i0 += 4;
51 
52       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
53       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
54       float32x4_t vacc0x4567 = vmulq_f32(vi0x4567, vw4567);
55       const uint32x4_t vm0x4567 = vcltq_s32(vreinterpretq_s32_f32(vi0x4567), vmovq_n_s32(0));
56       float32x4_t vacc0x89AB = vmulq_f32(vi0x89AB, vw89AB);
57       const uint32x4_t vm0x89AB = vcltq_s32(vreinterpretq_s32_f32(vi0x89AB), vmovq_n_s32(0));
58       float32x4_t vacc0xCDEF = vmulq_f32(vi0xCDEF, vwCDEF);
59       const uint32x4_t vm0xCDEF = vcltq_s32(vreinterpretq_s32_f32(vi0xCDEF), vmovq_n_s32(0));
60 
61       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
62       vacc0x4567 = vbslq_f32(vm0x4567, vacc0x4567, vi0x4567);
63       vacc0x89AB = vbslq_f32(vm0x89AB, vacc0x89AB, vi0x89AB);
64       vacc0xCDEF = vbslq_f32(vm0xCDEF, vacc0xCDEF, vi0xCDEF);
65 
66       vst1q_f32(o0, vacc0x0123); o0 += 4;
67       vst1q_f32(o0, vacc0x4567); o0 += 4;
68       vst1q_f32(o0, vacc0x89AB); o0 += 4;
69       vst1q_f32(o0, vacc0xCDEF); o0 += 4;
70     }
71     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
72       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
73 
74       const float32x4_t vi0x0123 = vld1q_f32(i0);
75       i0 += 4;
76 
77       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
78       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
79 
80       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
81 
82       vst1q_f32(o0, vacc0x0123); o0 += 4;
83     }
84     if XNN_UNLIKELY(c != 0) {
85       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
86 
87       const float32x4_t vi0x0123 = vld1q_f32(i0);
88       i0 = (const float*) ((uintptr_t) i0 + c);
89 
90       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
91       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
92 
93       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
94 
95       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
96       if (c & (2 * sizeof(float))) {
97         vst1_f32(o0, vacc0x01); o0 += 2;
98 
99         vacc0x01 = vget_high_f32(vacc0x0123);
100       }
101       if (c & (1 * sizeof(float))) {
102         vst1_lane_f32(o0, vacc0x01, 0); o0 += 1;
103       }
104     }
105     i0 = (const float*) ((uintptr_t) i0 + input_increment);
106     o0 = (float*) ((uintptr_t) o0 + output_increment);
107     rows = doz(rows, 1);
108   } while (rows != 0);
109 }
110