• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_2x8(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_2x8(
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   const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
34   float* o1 = (float*) ((uintptr_t) o0 + output_stride);
35 
36   const size_t input_increment = input_stride * 2 - channels;
37   const size_t output_increment = output_stride * 2 - channels;
38 
39   do {
40     if XNN_UNPREDICTABLE(rows < 2) {
41       i1 = i0;
42       o1 = o0;
43     }
44 
45     const float* w = weights;
46     size_t c = channels;
47     for (; c >= 8 * sizeof(float); c -= 8 * sizeof(float)) {
48       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
49       const float32x4_t vw4567 = vld1q_f32(w); w += 4;
50 
51       const float32x4_t vi0x0123 = vld1q_f32(i0); i0 += 4;
52       const float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
53       const float32x4_t vi1x0123 = vld1q_f32(i1); i1 += 4;
54       const float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
55 
56       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
57       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
58       float32x4_t vacc0x4567 = vmulq_f32(vi0x4567, vw4567);
59       const uint32x4_t vm0x4567 = vcltq_s32(vreinterpretq_s32_f32(vi0x4567), vmovq_n_s32(0));
60       float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
61       const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
62       float32x4_t vacc1x4567 = vmulq_f32(vi1x4567, vw4567);
63       const uint32x4_t vm1x4567 = vcltq_s32(vreinterpretq_s32_f32(vi1x4567), vmovq_n_s32(0));
64 
65       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
66       vacc0x4567 = vbslq_f32(vm0x4567, vacc0x4567, vi0x4567);
67       vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
68       vacc1x4567 = vbslq_f32(vm1x4567, vacc1x4567, vi1x4567);
69 
70       vst1q_f32(o0, vacc0x0123); o0 += 4;
71       vst1q_f32(o0, vacc0x4567); o0 += 4;
72       vst1q_f32(o1, vacc1x0123); o1 += 4;
73       vst1q_f32(o1, vacc1x4567); o1 += 4;
74     }
75     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
76       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
77 
78       const float32x4_t vi0x0123 = vld1q_f32(i0);
79       i0 += 4;
80       const float32x4_t vi1x0123 = vld1q_f32(i1);
81       i1 += 4;
82 
83       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
84       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
85       float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
86       const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
87 
88       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
89       vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
90 
91       vst1q_f32(o0, vacc0x0123); o0 += 4;
92       vst1q_f32(o1, vacc1x0123); o1 += 4;
93     }
94     if XNN_UNLIKELY(c != 0) {
95       const float32x4_t vw0123 = vld1q_f32(w); w += 4;
96 
97       const float32x4_t vi0x0123 = vld1q_f32(i0);
98       i0 = (const float*) ((uintptr_t) i0 + c);
99       const float32x4_t vi1x0123 = vld1q_f32(i1);
100       i1 = (const float*) ((uintptr_t) i1 + c);
101 
102       float32x4_t vacc0x0123 = vmulq_f32(vi0x0123, vw0123);
103       const uint32x4_t vm0x0123 = vcltq_s32(vreinterpretq_s32_f32(vi0x0123), vmovq_n_s32(0));
104       float32x4_t vacc1x0123 = vmulq_f32(vi1x0123, vw0123);
105       const uint32x4_t vm1x0123 = vcltq_s32(vreinterpretq_s32_f32(vi1x0123), vmovq_n_s32(0));
106 
107       vacc0x0123 = vbslq_f32(vm0x0123, vacc0x0123, vi0x0123);
108       vacc1x0123 = vbslq_f32(vm1x0123, vacc1x0123, vi1x0123);
109 
110       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
111       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
112       if (c & (2 * sizeof(float))) {
113         vst1_f32(o0, vacc0x01); o0 += 2;
114         vst1_f32(o1, vacc1x01); o1 += 2;
115 
116         vacc0x01 = vget_high_f32(vacc0x0123);
117         vacc1x01 = vget_high_f32(vacc1x0123);
118       }
119       if (c & (1 * sizeof(float))) {
120         vst1_lane_f32(o0, vacc0x01, 0); o0 += 1;
121         vst1_lane_f32(o1, vacc1x01, 0); o1 += 1;
122       }
123     }
124     i0 = (const float*) ((uintptr_t) i0 + input_increment);
125     o0 = (float*) ((uintptr_t) o0 + output_increment);
126     i1 = (const float*) ((uintptr_t) i1 + input_increment);
127     o1 = (float*) ((uintptr_t) o1 + output_increment);
128     rows = doz(rows, 2);
129   } while (rows != 0);
130 }
131