Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-1x8c8-minmax-fp32-neoni8mm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c8-neoni8mm.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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/igemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x8c8__neoni8mm(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 size_t ks,
24 const int8_t** restrict a,
25 const void* restrict w,
26 int8_t* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 size_t a_offset,
30 const int8_t* zero,
31 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
32 {
33 assert(mr != 0);
34 assert(mr <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(ks != 0);
38 assert(ks % (1 * sizeof(void*)) == 0);
39 assert(a_offset % sizeof(int8_t) == 0);
40 assert(a != NULL);
41 assert(w != NULL);
42 assert(c != NULL);
43
44 kc = round_up_po2(kc, 8 * sizeof(int8_t));
45 int8_t* c0 = c;
46
47 do {
48 const uint64x2x2_t vbias01x0123 = vld2q_dup_u64(w); w = (const int32_t*) w + 4;
49 const uint64x2x2_t vbias01x4567 = vld2q_dup_u64(w); w = (const int32_t*) w + 4;
50 int32x4_t vacc01x01 = vreinterpretq_s32_u64(vbias01x0123.val[0]);
51 int32x4_t vacc01x23 = vreinterpretq_s32_u64(vbias01x0123.val[1]);
52 int32x4_t vacc01x45 = vreinterpretq_s32_u64(vbias01x4567.val[0]);
53 int32x4_t vacc01x67 = vreinterpretq_s32_u64(vbias01x4567.val[1]);
54
55 size_t p = ks;
56 do {
57 const int8_t* restrict a0 = a[0];
58 if XNN_UNPREDICTABLE(a0 != zero) {
59 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
60 }
61 a += 1;
62
63 uint64x2x2_t va01x0123456789ABCDEF;
64 va01x0123456789ABCDEF.val[0] = vdupq_n_u64(0);
65 va01x0123456789ABCDEF.val[1] = vdupq_n_u64(0);
66
67 // Inner accumulation loop along the 8 columns.
68 size_t k = kc;
69 // 2x partial unrolled loop to load 8 bytes at a time.
70 while (k >= 16 * sizeof(int8_t)) {
71 // Load a 1x16 block of activations.
72 va01x0123456789ABCDEF = vld2q_lane_u64((const void*) a0, va01x0123456789ABCDEF, 0); a0 += 16;
73
74 // Load a 16x8 block of weights.
75 const int8x16_t vb01x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
76 const int8x16_t vb23x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
77 const int8x16_t vb45x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
78 const int8x16_t vb67x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
79 const int8x16_t vb01x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
80 const int8x16_t vb23x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
81 const int8x16_t vb45x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
82 const int8x16_t vb67x89ABCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
83
84 // Multiply-accumulate: 1x16 * 16x8 --> 1x8.
85 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb01x01234567);
86 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb23x01234567);
87 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb45x01234567);
88 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[0]), vb67x01234567);
89 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb01x89ABCDEF);
90 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb23x89ABCDEF);
91 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb45x89ABCDEF);
92 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x0123456789ABCDEF.val[1]), vb67x89ABCDEF);
93
94 k -= 16 * sizeof(int8_t);
95 }
96 // Handle up to 8 final positions of `k`
97 if XNN_UNLIKELY(k != 0) {
98 // Load a 1x8 block of activations.
99 uint64x2_t va01x01234567 = vld1q_dup_u64((const void*) a0); a0 += 8;
100
101 // Load a 16x8 block of weights.
102 const int8x16_t vb01x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
103 const int8x16_t vb23x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
104 const int8x16_t vb45x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
105 const int8x16_t vb67x01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
106
107 // Multiply-accumulate: 1x4 * 4x8 --> 1x8.
108 vacc01x01 = vmmlaq_s32(vacc01x01, vreinterpretq_s8_u64(va01x01234567), vb01x01234567);
109 vacc01x23 = vmmlaq_s32(vacc01x23, vreinterpretq_s8_u64(va01x01234567), vb23x01234567);
110 vacc01x45 = vmmlaq_s32(vacc01x45, vreinterpretq_s8_u64(va01x01234567), vb45x01234567);
111 vacc01x67 = vmmlaq_s32(vacc01x67, vreinterpretq_s8_u64(va01x01234567), vb67x01234567);
112 }
113
114 p -= 1 * sizeof(void*);
115 } while (p != 0);
116
117 int32x4_t vacc0x0123 = vcombine_s32(vget_low_s32(vacc01x01), vget_low_s32(vacc01x23));
118 int32x4_t vacc0x4567 = vcombine_s32(vget_low_s32(vacc01x45), vget_low_s32(vacc01x67));
119
120 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
121 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
122
123 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4;
124 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
125 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4;
126 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
127
128 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
129 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
130
131 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
132 #if XNN_ARCH_ARM64
133 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
134
135 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
136 #else
137 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
138
139 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
140 #endif
141 const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neonv8.output_min);
142 const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neonv8.output_max);
143
144 vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
145
146 vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
147
148 if (nc >= 8) {
149 vst1_s8(c0, vout0x01234567);
150
151 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
152
153 a = (const int8_t**restrict) ((uintptr_t) a - ks);
154
155 nc -= 8;
156 } else {
157 if (nc & 4) {
158 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
159 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
160 }
161 if (nc & 2) {
162 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
163 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
164 }
165 if (nc & 1) {
166 vst1_lane_s8(c0, vout0x01234567, 0);
167 }
168
169 nc = 0;
170 }
171 } while (nc != 0);
172 }