Debian Codegraph @

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

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/MRx8c8-avxvnni.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 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 <immintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/gemm.h"
16 #include "xnnpack/intrinsics-polyfill.h"
17 #include "xnnpack/math.h"
18 #include "xnnpack/unaligned.h"
19 #include "xnnpack/prefetch.h"
20
21
22 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x8c8__avxvnniint8_prfm(
23 size_t mr,
24 size_t nc,
25 size_t kc,
26 size_t ks,
27 const int8_t** restrict a,
28 const void* restrict w,
29 int8_t* restrict c,
30 size_t cm_stride,
31 size_t cn_stride,
32 size_t a_offset,
33 const int8_t* zero,
34 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
35 {
36 assert(mr != 0);
37 assert(mr <= 1);
38 assert(nc != 0);
39 assert(kc != 0);
40 assert(kc % sizeof(int8_t) == 0);
41 assert(a != NULL);
42 assert(w != NULL);
43 assert(c != NULL);
44
45 kc = round_up_po2(kc, 8 * sizeof(int8_t));
46 int8_t* c0 = c;
47
48 const __m256 voutput_max_less_zero_point = _mm256_set1_ps((int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point);
49 const __m256i voutput_zero_point = _mm256_set1_epi32(params->fp32_scalar.output_zero_point);
50 const __m128i voutput_min = _mm_set1_epi8(params->fp32_scalar.output_min);
51 // XNN_FORCE_REALIZATION(voutput_max_less_zero_point);
52 // XNN_FORCE_REALIZATION(voutput_zero_point);
53 // XNN_FORCE_REALIZATION(voutput_min);
54 do {
55 __m256i vacc0x0123 = _mm256_cvtepu32_epi64(_mm_load_si128((const __m128i*) w));
56 __m256i vacc0x4567 = _mm256_cvtepu32_epi64(_mm_load_si128((const __m128i*) ((const int32_t*) w + 4)));
57 __m256i vacc1x0x0123 = _mm256_setzero_si256();
58 __m256i vacc1x0x4567 = _mm256_setzero_si256();
59 w = (const int32_t*) w + 8;
60
61 size_t p = ks;
62 do {
63 const int8_t* restrict a0 = a[0];
64 if XNN_UNPREDICTABLE(a0 != zero) {
65 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
66 }
67 a += 1;
68
69 size_t k = kc;
70 while (k >= 16 * sizeof(int8_t)) {
71 const __m256i va0x01234567 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(a0));
72 const __m256i va0x89ABCDEF = _mm256_set1_epi64x((int64_t) unaligned_load_u64(a0 + 8));
73 a0 += 16;
74
75 const __m256i vb01234567x0123 = _mm256_load_si256(w);
76 const __m256i vb89ABCDEFx0123 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
77 const __m256i vb01234567x4567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 64));
78 const __m256i vb89ABCDEFx4567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 96));
79 xnn_prefetch_to_l1((const int8_t*) w + 896);
80
81 vacc0x0123 = _mm256_dpbssd_epi32(vacc0x0123, va0x01234567, vb01234567x0123);
82 vacc0x4567 = _mm256_dpbssd_epi32(vacc0x4567, va0x01234567, vb89ABCDEFx0123);
83 xnn_prefetch_to_l1((const int8_t*) w + 960);
84 vacc1x0x0123 = _mm256_dpbssd_epi32(vacc1x0x0123, va0x89ABCDEF, vb01234567x4567);
85 vacc1x0x4567 = _mm256_dpbssd_epi32(vacc1x0x4567, va0x89ABCDEF, vb89ABCDEFx4567);
86
87 w = (const int8_t*) w + 128;
88 k -= 16 * sizeof(int8_t);
89 }
90
91 if (k != 0) {
92 const __m256i va0x01234567 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(a0));
93 a0 += 8;
94
95 const __m256i vb01234567x0123 = _mm256_load_si256(w);
96 const __m256i vb89ABCDEFx0123 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
97
98 vacc0x0123 = _mm256_dpbssd_epi32(vacc0x0123, va0x01234567, vb01234567x0123);
99 vacc0x4567 = _mm256_dpbssd_epi32(vacc0x4567, va0x01234567, vb89ABCDEFx0123);
100 xnn_prefetch_to_l1((const int8_t*) w + 960);
101
102 w = (const int8_t*) w + 64;
103 k -= 8 * sizeof(int8_t);
104 }
105
106 p -= 1 * sizeof(void*);
107 } while (p != 0);
108
109 vacc0x0123 = _mm256_add_epi32(vacc0x0123, vacc1x0x0123);
110 vacc0x4567 = _mm256_add_epi32(vacc0x4567, vacc1x0x4567);
111
112 // Add adjacent pairs
113 const __m256i vsum0x02134657 = _mm256_hadd_epi32(vacc0x0123, vacc0x4567);
114 __m256i vacc0x01234567 = _mm256_permute4x64_epi64(vsum0x02134657, _MM_SHUFFLE(3, 1, 2, 0));
115
116 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567);
117
118 const __m256 vscale01234567 = _mm256_load_ps(w);
119 w = (const float*) w + 8;
120 vout0x01234567 = _mm256_mul_ps(vout0x01234567, vscale01234567);
121
122 vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max_less_zero_point);
123
124 vacc0x01234567 = _mm256_cvtps_epi32(vout0x01234567);
125
126 vacc0x01234567 = _mm256_add_epi32(vacc0x01234567, voutput_zero_point);
127
128 vacc0x01234567 = _mm256_packs_epi32(vacc0x01234567, _mm256_castsi128_si256(_mm256_extracti128_si256(vacc0x01234567, 1)));
129 __m128i voutb0x01234567 = _mm256_castsi256_si128(_mm256_packs_epi16(vacc0x01234567, vacc0x01234567));
130
131 voutb0x01234567 = _mm_max_epi8(voutb0x01234567, voutput_min);
132
133 if (nc >= 8) {
134 _mm_storel_epi64((__m128i*) c0, voutb0x01234567);
135 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
136 a = (const int8_t**restrict) ((uintptr_t) a - ks);
137 nc -= 8;
138 } else {
139 if (nc & 4) {
140 _mm_storeu_si32(c0, voutb0x01234567);
141 c0 += 4;
142 voutb0x01234567 = _mm_srli_epi64(voutb0x01234567, 32);
143 }
144 if (nc & 2) {
145 unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(voutb0x01234567, 0));
146 c0 += 2;
147 voutb0x01234567 = _mm_srli_epi32(voutb0x01234567, 16);
148 }
149 if (nc & 1) {
150 *c0 = (int8_t) _mm_extract_epi8(voutb0x01234567, 0);
151 }
152 nc = 0;
153 }
154 } while (nc != 0);
155 }