Debian Codegraph @

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

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c8-neondot.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/gemm.h"
15 #include "xnnpack/intrinsics-polyfill.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x8c8__neondot_ld64(
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 int32x4_t vinit0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
49 const int32x4_t vinit0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
50 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x0123))));
51 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x0123))));
52 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vget_low_u32(vreinterpretq_u32_s32(vinit0x4567))));
53 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vget_high_u32(vreinterpretq_u32_s32(vinit0x4567))));
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 size_t k = kc;
64 do {
65 const int8x16_t va0c01234567 = vreinterpretq_s8_u64(vld1q_dup_u64((const void*) a0)); a0 += 8;
66
67 const int8x16_t vb01c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
68 const int8x16_t vb23c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
69 const int8x16_t vb45c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
70 const int8x16_t vb67c01234567 = vld1q_s8(w); w = (const int8_t*) w + 16;
71
72 vacc0x01 = vdotq_s32(vacc0x01, vb01c01234567, va0c01234567);
73 vacc0x23 = vdotq_s32(vacc0x23, vb23c01234567, va0c01234567);
74 vacc0x45 = vdotq_s32(vacc0x45, vb45c01234567, va0c01234567);
75 vacc0x67 = vdotq_s32(vacc0x67, vb67c01234567, va0c01234567);
76
77 k -= 8 * sizeof(int8_t);
78 } while (k != 0);
79 p -= 1 * sizeof(void*);
80 } while (p != 0);
81
82 #if XNN_ARCH_ARM64
83 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
84 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
85 #else
86 int32x4_t vacc0x0123 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)), vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)));
87 int32x4_t vacc0x4567 = vcombine_s32(vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)), vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)));
88 #endif
89
90 float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123);
91 float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567);
92
93 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4;
94 vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123);
95 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4;
96 vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567);
97
98 vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123);
99 vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567);
100
101 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
102 #if XNN_ARCH_ARM64
103 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
104
105 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
106 #else
107 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
108
109 int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567);
110 #endif
111 const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neonv8.output_min);
112 const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neonv8.output_max);
113
114 vout0x01234567 = vmax_s8(vout0x01234567, voutput_min);
115
116 vout0x01234567 = vmin_s8(vout0x01234567, voutput_max);
117
118 if (nc >= 8) {
119 // Main case where there the 8 columns fit in the destination.
120 vst1_s8(c0 + 0, vout0x01234567);
121
122 // Advance to the next 8 columns.
123 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
124
125 a = (const int8_t**restrict) ((uintptr_t) a - ks);
126
127 nc -= 8;
128 } else {
129 // Final case where not all of the 8 columns fit in the destination.
130 if (nc & 4) {
131 vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4;
132 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4);
133 }
134 if (nc & 2) {
135 vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2;
136 vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2);
137 }
138 if (nc & 1) {
139 vst1_lane_s8(c0, vout0x01234567, 0);
140 }
141
142 nc = 0;
143 }
144 } while (nc != 0);
145 }