1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c8-neon-mull.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/gemm.h>
15 #include <xnnpack/math.h>
16
17
xnn_qs8_gemm_minmax_rndnu_ukernel_1x8c8__neon_mull(size_t mr,size_t nc,size_t kc,const int8_t * restrict a,size_t a_stride,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_gemm_minmax_rndnu_ukernel_1x8c8__neon_mull(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const int8_t* restrict a,
23 size_t a_stride,
24 const void* restrict w,
25 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
29 {
30 assert(mr != 0);
31 assert(mr <= 1);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(int8_t) == 0);
35 assert(a != NULL);
36 assert(w != NULL);
37 assert(c != NULL);
38
39 kc = round_up_po2(kc, 8 * sizeof(int8_t));
40 const int8_t* a0 = a;
41 int8_t* c0 = c;
42
43 do {
44 int32x4_t vacc0x0 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
45 int32x4_t vacc0x1 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
46 int32x4_t vacc0x2 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
47 int32x4_t vacc0x3 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
48 int32x4_t vacc0x4 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
49 int32x4_t vacc0x5 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
50 int32x4_t vacc0x6 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
51 int32x4_t vacc0x7 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t));
52
53 size_t k = kc;
54
55 // Handle 8 bytes at a time using MUL.
56 while (k != 0) {
57 const int8x8_t va0 = vld1_s8(a0); a0 += 8;
58
59 const int8x8_t vb0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
60 const int16x8_t vprod0x0 = vmull_s8(vb0, va0);
61 vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0);
62 const int8x8_t vb1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
63 const int16x8_t vprod0x1 = vmull_s8(vb1, va0);
64 vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1);
65 const int8x8_t vb2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
66 const int16x8_t vprod0x2 = vmull_s8(vb2, va0);
67 vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2);
68 const int8x8_t vb3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
69 const int16x8_t vprod0x3 = vmull_s8(vb3, va0);
70 vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3);
71 const int8x8_t vb4 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
72 const int16x8_t vprod0x4 = vmull_s8(vb4, va0);
73 vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4);
74 const int8x8_t vb5 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
75 const int16x8_t vprod0x5 = vmull_s8(vb5, va0);
76 vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5);
77 const int8x8_t vb6 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
78 const int16x8_t vprod0x6 = vmull_s8(vb6, va0);
79 vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6);
80 const int8x8_t vb7 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
81 const int16x8_t vprod0x7 = vmull_s8(vb7, va0);
82 vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7);
83
84 k -= 8 * sizeof(int8_t);
85 }
86
87 #if XNN_ARCH_ARM64
88 const int32x4_t vsum0x01 = vpaddq_s32(vacc0x0, vacc0x1);
89 const int32x4_t vsum0x23 = vpaddq_s32(vacc0x2, vacc0x3);
90 const int32x4_t vsum0x45 = vpaddq_s32(vacc0x4, vacc0x5);
91 const int32x4_t vsum0x67 = vpaddq_s32(vacc0x6, vacc0x7);
92
93 int32x4_t vacc0x0123 = vpaddq_s32(vsum0x01, vsum0x23);
94 int32x4_t vacc0x4567 = vpaddq_s32(vsum0x45, vsum0x67);
95 #else
96 const int32x2_t vpsum0x0 = vadd_s32(vget_low_s32(vacc0x0), vget_high_s32(vacc0x0));
97 const int32x2_t vpsum0x1 = vadd_s32(vget_low_s32(vacc0x1), vget_high_s32(vacc0x1));
98 const int32x2_t vpsum0x2 = vadd_s32(vget_low_s32(vacc0x2), vget_high_s32(vacc0x2));
99 const int32x2_t vpsum0x3 = vadd_s32(vget_low_s32(vacc0x3), vget_high_s32(vacc0x3));
100 const int32x2_t vsum0x01 = vpadd_s32(vpsum0x0, vpsum0x1);
101 const int32x2_t vsum0x23 = vpadd_s32(vpsum0x2, vpsum0x3);
102 int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23 );
103 const int32x2_t vpsum0x4 = vadd_s32(vget_low_s32(vacc0x4), vget_high_s32(vacc0x4));
104 const int32x2_t vpsum0x5 = vadd_s32(vget_low_s32(vacc0x5), vget_high_s32(vacc0x5));
105 const int32x2_t vpsum0x6 = vadd_s32(vget_low_s32(vacc0x6), vget_high_s32(vacc0x6));
106 const int32x2_t vpsum0x7 = vadd_s32(vget_low_s32(vacc0x7), vget_high_s32(vacc0x7));
107 const int32x2_t vsum0x45 = vpadd_s32(vpsum0x4, vpsum0x5);
108 const int32x2_t vsum0x67 = vpadd_s32(vpsum0x6, vpsum0x7);
109 int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67 );
110 #endif
111
112 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
113 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
114 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
115
116 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
117 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
118
119 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
120 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
121
122 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
123 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
124
125 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
126 #if XNN_ARCH_ARM64
127 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
128
129 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
130
131 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
132 #else
133 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
134
135 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
136
137 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
138 #endif
139
140 const int8x8_t voutput_min = vld1_dup_s8(¶ms->rndnu_neon.output_min);
141 vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
142
143 const int8x8_t voutput_max = vld1_dup_s8(¶ms->rndnu_neon.output_max);
144 vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
145
146 if (nc >= 8) {
147 vst1_s8(c0 + 0, vout0x01234567);
148
149 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
150
151 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
152
153 nc -= 8;
154 } else {
155 // Final case where not all of the 8 columns fit in the destination.
156 if (nc & 4) {
157 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
158 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
159 }
160 if (nc & 2) {
161 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
162 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
163 }
164 if (nc & 1) {
165 vst1_lane_s8(c0, vout0x01234567, 0);
166 }
167
168 nc = 0;
169 }
170 } while (nc != 0);
171 }
172