blob: d09e595ce51b2c9ed5d81f0e42091a25a95572eb [file] [log] [blame]
Marat Dukhan1268a242020-10-24 00:36:32 -07001// Auto-generated file. Do not edit!
Marat Dukhanc581e482020-10-24 01:28:11 -07002// Template: src/f32-dwconv2d-chw/3x3p1-neon.c.in
Marat Dukhan1268a242020-10-24 00:36:32 -07003// 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/dwconv.h>
15#include <xnnpack/math.h>
16
17
18void xnn_f32_dwconv2d_chw_ukernel_3x3p1__neonfma_1x4(
19 size_t input_height,
20 size_t input_width,
21 const float* input,
22 const float* weights,
23 const float* zero,
24 float* output,
25 uint32_t padding_top,
26 const union xnn_f32_chw_params params[restrict XNN_MIN_ELEMENTS(1)])
27{
28 assert(input_height != 0);
29 assert(input_width != 0);
30 assert(input_width % sizeof(float) == 0);
31 assert(padding_top == 1);
32
33 const uint32x4_t vmask = vld1q_u32(params->neon.mask);
34 const float32x4_t vmax = vld1q_dup_f32(&params->neon.max);
35 const float32x4_t vmin = vld1q_dup_f32(&params->neon.min);
36
37 const float32x4_t vw0123 = vld1q_f32(weights);
38 const float32x4_t vw4567 = vld1q_f32(weights + 4);
39 const float32x2_t vw89 = vld1_f32(weights + 8);
40
41 const size_t input_decrement = round_up_po2(input_width, 4 * sizeof(float));
42
43 const float* i0 = zero;
44 const float* i1 = input;
45 const float* i2 = (const float*) ((uintptr_t) i1 + input_width);
46
47 float* o0 = output;
48
49 size_t output_height = input_height;
50 do {
51 if XNN_UNPREDICTABLE(output_height < 2) {
52 i2 = zero;
53 }
54
55 float32x4_t vi0x0123 = vmovq_n_f32(0.0f);
56 float32x4_t vi1x0123 = vmovq_n_f32(0.0f);
57 float32x4_t vi2x0123 = vmovq_n_f32(0.0f);
58
59 float32x4_t vi0x4567 = vld1q_f32(i0); i0 += 4;
60 float32x4_t vi1x4567 = vld1q_f32(i1); i1 += 4;
61 float32x4_t vi2x4567 = vld1q_f32(i2); i2 += 4;
62
63 size_t w = input_width;
64 for (; w > 4 * sizeof(float); w -= 4 * sizeof(float)) {
Marat Dukhanc581e482020-10-24 01:28:11 -070065 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -070066
67 const float32x4_t vi0x89AB = vld1q_f32(i0); i0 += 4;
68 const float32x4_t vi1x89AB = vld1q_f32(i1); i1 += 4;
69 const float32x4_t vi2x89AB = vld1q_f32(i2); i2 += 4;
70
Marat Dukhanc581e482020-10-24 01:28:11 -070071 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -070072
Marat Dukhanc581e482020-10-24 01:28:11 -070073 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -070074
75 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
76
77 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
78 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
79 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
80
Marat Dukhanc581e482020-10-24 01:28:11 -070081 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -070082
Marat Dukhanc581e482020-10-24 01:28:11 -070083 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -070084
Marat Dukhanc581e482020-10-24 01:28:11 -070085 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -070086
87 vi0x0123 = vi0x4567;
88 vi1x0123 = vi1x4567;
89 vi2x0123 = vi2x4567;
90
91 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vi0x89AB, 1);
92 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vi1x89AB, 1);
93 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vi2x89AB, 1);
94
Marat Dukhanc581e482020-10-24 01:28:11 -070095 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -070096
Marat Dukhanc581e482020-10-24 01:28:11 -070097 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -070098
99 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
100
101 vi0x4567 = vi0x89AB;
102 vi1x4567 = vi1x89AB;
103 vi2x4567 = vi2x89AB;
104
105
106 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
107
108 vo0 = vminq_f32(vo0, vmax);
109
110 vst1q_f32(o0, vo0); o0 += 4;
111 }
112 // Always process the last block of 1..4 pixels.
113 assert(w >= 1 * sizeof(float));
114 assert(w <= 4 * sizeof(float));
115 {
Marat Dukhanc581e482020-10-24 01:28:11 -0700116 float32x4_t vo0p0 = vdupq_lane_f32(vget_low_f32(vw0123), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -0700117
118 vi0x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi0x4567)));
119 vi1x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi1x4567)));
120 vi2x4567 = vreinterpretq_f32_u32(vandq_u32(vmask, vreinterpretq_u32_f32(vi2x4567)));
121
Marat Dukhanc581e482020-10-24 01:28:11 -0700122 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x4567, vget_high_f32(vw0123), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -0700123
Marat Dukhanc581e482020-10-24 01:28:11 -0700124 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x4567, vget_low_f32(vw4567), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -0700125
126 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x4567, vw89, 0);
127
128 const float32x4_t vi0x3456 = vextq_f32(vi0x0123, vi0x4567, 3);
129 const float32x4_t vi1x3456 = vextq_f32(vi1x0123, vi1x4567, 3);
130 const float32x4_t vi2x3456 = vextq_f32(vi2x0123, vi2x4567, 3);
131
Marat Dukhanc581e482020-10-24 01:28:11 -0700132 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x3456, vget_low_f32(vw0123), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -0700133
Marat Dukhanc581e482020-10-24 01:28:11 -0700134 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x3456, vget_low_f32(vw4567), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -0700135
Marat Dukhanc581e482020-10-24 01:28:11 -0700136 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x3456, vget_high_f32(vw4567), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -0700137
138 const float32x4_t vzero = vmovq_n_f32(0.0f);
139 const float32x4_t vi0x5678 = vextq_f32(vi0x4567, vzero, 1);
140 const float32x4_t vi1x5678 = vextq_f32(vi1x4567, vzero, 1);
141 const float32x4_t vi2x5678 = vextq_f32(vi2x4567, vzero, 1);
142
Marat Dukhanc581e482020-10-24 01:28:11 -0700143 vo0p0 = vfmaq_lane_f32(vo0p0, vi0x5678, vget_high_f32(vw0123), 1);
Marat Dukhan1268a242020-10-24 00:36:32 -0700144
Marat Dukhanc581e482020-10-24 01:28:11 -0700145 vo0p0 = vfmaq_lane_f32(vo0p0, vi1x5678, vget_high_f32(vw4567), 0);
Marat Dukhan1268a242020-10-24 00:36:32 -0700146
147 vo0p0 = vfmaq_lane_f32(vo0p0, vi2x5678, vw89, 1);
148
149
150 float32x4_t vo0 = vmaxq_f32(vo0p0, vmin);
151
152 vo0 = vminq_f32(vo0, vmax);
153
154 if XNN_LIKELY(w == 4 * sizeof(float)) {
155 vst1q_f32(o0, vo0); o0 += 4;
156 } else {
157 float32x2_t vo0_lo = vget_low_f32(vo0);
158 if (w & (2 * sizeof(float))) {
159 vst1_f32(o0, vo0_lo); o0 += 2;
160
161 vo0_lo = vget_high_f32(vo0);
162 }
163 if (w & (1 * sizeof(float))) {
164 vst1_lane_f32(o0, vo0_lo, 0); o0 += 1;
165 }
166 }
167 }
168
169 i0 = (const float*) ((uintptr_t) i1 - input_decrement);
170 i1 = (const float*) ((uintptr_t) i2 - input_decrement);
171 i2 = (const float*) ((uintptr_t) i1 + input_width);
172
173
174 } while (--output_height != 0);
175}