blob: f1d9da0b70f02ce6c57328857ec92a199a17e0a3 [file] [log] [blame]
XNNPACK Teamb455b122019-09-27 18:10:33 -07001/*
2 * Copyright 2019 Google LLC
3 *
4 * This source code is licensed under the BSD-style license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#include <assert.h>
9
10#include <arm_neon.h>
11
12#include <xnnpack/pad.h>
13
14
15void xnn_x32_pad_x2__neon(
16 size_t m,
17 size_t n,
18 size_t l,
19 size_t r,
20 uint32_t c,
21 const void* x,
22 size_t x_stride,
23 void* y,
24 size_t y_stride)
25{
26 assert(m <= 2);
27 assert(l % 4 == 0);
28 assert(n % 4 == 0);
29 assert(r % 4 == 0);
30
31 const uint32_t* x0 = x;
32 uint32_t* y0 = y;
33
34 const uint32_t* x1 = (const uint32_t*) ((uintptr_t) x0 + x_stride);
35 uint32_t* y1 = (uint32_t*) ((uintptr_t) y0 + y_stride);
36 if (m != 2) {
37 x1 = x0;
38 y1 = y0;
39 }
40 const uint32x4_t vc = vmovq_n_u32(c);
41
42 /* Pre-pad input channels */
43 for (; l >= 16; l -= 16) {
44 vst1q_u32(y0, vc); y0 += 4;
45 vst1q_u32(y1, vc); y1 += 4;
46 }
47 if (l & 8) {
48 vst1_u32(y0, vget_low_u32(vc)); y0 += 2;
49 vst1_u32(y1, vget_low_u32(vc)); y1 += 2;
50 }
51 if (l & 4) {
52 vst1q_lane_u32(y0, vc, 0); y0 += 1;
53 vst1q_lane_u32(y1, vc, 0); y1 += 1;
54 }
55
56 /* Copy input channels */
57 for (; n >= 16; n -= 16) {
58 const uint32x4_t vt0 = vld1q_u32(x0); x0 += 4;
59 const uint32x4_t vt1 = vld1q_u32(x1); x1 += 4;
60 vst1q_u32(y0, vt0); y0 += 4;
61 vst1q_u32(y1, vt1); y1 += 4;
62 }
63 if (n != 0) {
64 const uint32x4_t vt0 = vld1q_u32(x0); x0 += 4;
65 const uint32x4_t vt1 = vld1q_u32(x1); x1 += 4;
66 uint32x2_t vt0lo = vget_low_u32(vt0);
67 uint32x2_t vt1lo = vget_low_u32(vt1);
68 if (n & 8) {
69 vst1_u32(y0, vt0lo); y0 += 2;
70 vst1_u32(y1, vt1lo); y1 += 2;
71 vt0lo = vget_high_u32(vt0);
72 vt1lo = vget_high_u32(vt1);
73 }
74 if (n & 4) {
75 vst1_lane_u32(y0, vt0lo, 0); y0 += 1;
76 vst1_lane_u32(y1, vt1lo, 0); y1 += 1;
77 }
78 }
79
80 /* Post-pad input channels */
81 for (; r >= 16; r -= 16) {
82 vst1q_u32(y0, vc); y0 += 4;
83 vst1q_u32(y1, vc); y1 += 4;
84 }
85 if (r & 8) {
86 vst1_u32(y0, vget_low_u32(vc)); y0 += 2;
87 vst1_u32(y1, vget_low_u32(vc)); y1 += 2;
88 }
89 if (r & 4) {
90 vst1q_lane_u32(y0, vc, 0);
91 vst1q_lane_u32(y1, vc, 0);
92 }
93}