• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/s8-ibilinear/neon.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 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/common.h>
15 #include <xnnpack/ibilinear.h>
16 
17 
xnn_u8_ibilinear_ukernel__neon_c8(size_t output_pixels,size_t channels,const uint8_t ** restrict input,size_t input_offset,const int16_t * restrict weights,uint8_t * restrict output,size_t output_increment)18 void xnn_u8_ibilinear_ukernel__neon_c8(
19     size_t output_pixels,
20     size_t channels,
21     const uint8_t**restrict input,
22     size_t input_offset,
23     const int16_t*restrict weights,
24     uint8_t*restrict output,
25     size_t output_increment) XNN_OOB_READS
26 {
27   assert(output_pixels != 0);
28   assert(channels != 0);
29 
30   do {
31     const uint8_t* i0 = (const uint8_t*) ((uintptr_t) input[0] + input_offset);
32     const uint8_t* i1 = (const uint8_t*) ((uintptr_t) input[1] + input_offset);
33     const uint8_t* i2 = (const uint8_t*) ((uintptr_t) input[2] + input_offset);
34     const uint8_t* i3 = (const uint8_t*) ((uintptr_t) input[3] + input_offset);
35     input += 4;
36 
37     #if XNN_ARCH_ARM64
38       const int16x8_t valphah = vld1q_dup_s16(weights); weights += 1;
39     #else
40       const int16x4_t valphah = vld1_dup_s16(weights); weights += 1;
41     #endif
42     const int32x4_t valphav = vmovl_s16(vld1_dup_s16(weights)); weights += 1;
43 
44     size_t c = channels;
45     for (; c >= 8 * sizeof(uint8_t); c -= 8 * sizeof(uint8_t)) {
46       const uint8x8_t vtl01234567 = vld1_u8(i0); i0 += 8;
47       const uint8x8_t vtr01234567 = vld1_u8(i1); i1 += 8;
48       const uint8x8_t vbl01234567 = vld1_u8(i2); i2 += 8;
49       const uint8x8_t vbr01234567 = vld1_u8(i3); i3 += 8;
50 
51       const int16x8_t vtd01234567 = vreinterpretq_s16_u16(vsubl_u8(vtr01234567, vtl01234567));
52       const int16x8_t vbd01234567 = vreinterpretq_s16_u16(vsubl_u8(vbr01234567, vbl01234567));
53       const int16x8_t vdl01234567 = vreinterpretq_s16_u16(vsubl_u8(vbl01234567, vtl01234567));
54       const int16x8_t vxtl01234567 = vreinterpretq_s16_u16(vmovl_u8(vtl01234567));
55 
56       const int16x8_t vdd01234567 = vsubq_s16(vbd01234567, vtd01234567);
57 
58       #if XNN_ARCH_ARM64
59         const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), vget_low_s16(valphah));
60         const int32x4_t vt4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vtd01234567, valphah);
61 
62         const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), vget_low_s16(valphah));
63         const int32x4_t vd4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vdd01234567, valphah);
64       #else  // !XNN_ARCH_ARM64
65         const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), valphah);
66         const int32x4_t vt4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vget_high_s16(vtd01234567), valphah);
67 
68         const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), valphah);
69         const int32x4_t vd4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vget_high_s16(vdd01234567), valphah);
70       #endif  // !XNN_ARCH_ARM64
71 
72       const int32x4_t vacc0123 = vmlaq_s32(vshlq_n_s32(vt0123, 11), vd0123, valphav);
73       const int32x4_t vacc4567 = vmlaq_s32(vshlq_n_s32(vt4567, 11), vd4567, valphav);
74 
75       #if XNN_ARCH_ARM64
76         const int16x8_t vacc01234567 = vuzp2q_s16(vreinterpretq_s16_s32(vacc0123), vreinterpretq_s16_s32(vacc4567));
77       #else  // !XNN_ARCH_ARM64
78         const int16x8_t vacc01234567 = vcombine_s16(vshrn_n_s32(vacc0123, 16), vshrn_n_s32(vacc4567, 16));
79       #endif  // !XNN_ARCH_ARM64
80 
81       const uint8x8_t vo01234567 = vrshrn_n_u16(vreinterpretq_u16_s16(vacc01234567), 6);
82 
83       vst1_u8(output, vo01234567); output += 8;
84     }
85     if XNN_UNLIKELY(c != 0) {
86       const uint8x8_t vtl01234567 = vld1_u8(i0);
87       const uint8x8_t vtr01234567 = vld1_u8(i1);
88       const uint8x8_t vbl01234567 = vld1_u8(i2);
89       const uint8x8_t vbr01234567 = vld1_u8(i3);
90 
91       const int16x8_t vtd01234567 = vreinterpretq_s16_u16(vsubl_u8(vtr01234567, vtl01234567));
92       const int16x8_t vbd01234567 = vreinterpretq_s16_u16(vsubl_u8(vbr01234567, vbl01234567));
93       const int16x8_t vdl01234567 = vreinterpretq_s16_u16(vsubl_u8(vbl01234567, vtl01234567));
94       const int16x8_t vxtl01234567 = vreinterpretq_s16_u16(vmovl_u8(vtl01234567));
95 
96       const int16x8_t vdd01234567 = vsubq_s16(vbd01234567, vtd01234567);
97 
98       #if XNN_ARCH_ARM64
99         const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), vget_low_s16(valphah));
100         const int32x4_t vt4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vtd01234567, valphah);
101 
102         const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), vget_low_s16(valphah));
103         const int32x4_t vd4567 = vmlal_high_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vdd01234567, valphah);
104       #else  // !XNN_ARCH_ARM64
105         const int32x4_t vt0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vxtl01234567), 11), vget_low_s16(vtd01234567), valphah);
106         const int32x4_t vt4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vxtl01234567), 11), vget_high_s16(vtd01234567), valphah);
107 
108         const int32x4_t vd0123 = vmlal_s16(vshll_n_s16(vget_low_s16(vdl01234567), 11), vget_low_s16(vdd01234567), valphah);
109         const int32x4_t vd4567 = vmlal_s16(vshll_n_s16(vget_high_s16(vdl01234567), 11), vget_high_s16(vdd01234567), valphah);
110       #endif  // !XNN_ARCH_ARM64
111 
112       const int32x4_t vacc0123 = vmlaq_s32(vshlq_n_s32(vt0123, 11), vd0123, valphav);
113       const int32x4_t vacc4567 = vmlaq_s32(vshlq_n_s32(vt4567, 11), vd4567, valphav);
114 
115       #if XNN_ARCH_ARM64
116         const int16x8_t vacc01234567 = vuzp2q_s16(vreinterpretq_s16_s32(vacc0123), vreinterpretq_s16_s32(vacc4567));
117       #else  // !XNN_ARCH_ARM64
118         const int16x8_t vacc01234567 = vcombine_s16(vshrn_n_s32(vacc0123, 16), vshrn_n_s32(vacc4567, 16));
119       #endif  // !XNN_ARCH_ARM64
120 
121       uint8x8_t vo01234567 = vrshrn_n_u16(vreinterpretq_u16_s16(vacc01234567), 6);
122 
123       if (c & (4 * sizeof(uint8_t))) {
124         vst1_lane_u32((void*) output, vreinterpret_u32_u8(vo01234567), 0); output += 4;
125         vo01234567 = vext_u8(vo01234567, vo01234567, 4);
126       }
127       if (c & (2 * sizeof(uint8_t))) {
128         vst1_lane_u16((void*) output, vreinterpret_u16_u8(vo01234567), 0); output += 2;
129         vo01234567 = vext_u8(vo01234567, vo01234567, 2);
130       }
131       if (c & (1 * sizeof(uint8_t))) {
132         vst1_lane_u8(output, vo01234567, 0); output += 1;
133       }
134     }
135 
136     output = (uint8_t*) ((uintptr_t) output + output_increment);
137   } while (--output_pixels != 0);
138 }
139