Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-2x4c8-minmax-sse41-ld64.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx4c8-sse.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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 <smmintrin.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/gemm.h"
16 #include "xnnpack/math.h"
17
18
19 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_2x4c8__sse41_ld64(
20 size_t mr,
21 size_t nc,
22 size_t kc,
23 const int8_t* restrict a,
24 size_t a_stride,
25 const void* restrict w,
26 float* restrict c,
27 size_t cm_stride,
28 size_t cn_stride,
29 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
30 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32 assert(mr != 0);
33 assert(mr <= 2);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(kc % sizeof(int8_t) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
41 kc = round_up_po2(kc, 8 * sizeof(int8_t));
42 const int8_t* a0 = a;
43 float* c0 = c;
44 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
45 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
46 if XNN_UNPREDICTABLE(mr != 2) {
47 a1 = a0;
48 c1 = c0;
49 }
50
51 const __m128 vmin = _mm_set1_ps(params->scalar.min);
52 const __m128 vmax = _mm_set1_ps(params->scalar.max);
53 XNN_FORCE_REALIZATION(vmin);
54 XNN_FORCE_REALIZATION(vmax);
55
56
57 do {
58 const __m128i vksum = _mm_load_si128((const __m128i*) w);
59 const __m128i vinput_zero_point01 = _mm_loadu_si128((const __m128i*) &quantization_params[0]);
60 const __m128i vinput_zero_point0 = _mm_shuffle_epi32(vinput_zero_point01, _MM_SHUFFLE(0, 0, 0, 0));
61 const __m128i vinput_zero_point1 = _mm_shuffle_epi32(vinput_zero_point01, _MM_SHUFFLE(2, 2, 2, 2));
62 const __m128i vzero = _mm_setzero_si128();
63 const __m128i vinit0 = _mm_mullo_epi32(vksum, vinput_zero_point0);
64 const __m128i vinit1 = _mm_mullo_epi32(vksum, vinput_zero_point1);
65 __m128i vacc0x0 = _mm_blend_epi16(vinit0, vzero, 0xFC);
66 __m128i vacc0x1 = _mm_blend_epi16(vinit0, vzero, 0xF3);
67 __m128i vacc0x2 = _mm_blend_epi16(vinit0, vzero, 0xCF);
68 __m128i vacc0x3 = _mm_blend_epi16(vinit0, vzero, 0x3F);
69 __m128i vacc1x0 = _mm_blend_epi16(vinit1, vzero, 0xFC);
70 __m128i vacc1x1 = _mm_blend_epi16(vinit1, vzero, 0xF3);
71 __m128i vacc1x2 = _mm_blend_epi16(vinit1, vzero, 0xCF);
72 __m128i vacc1x3 = _mm_blend_epi16(vinit1, vzero, 0x3F);
73 w = (const int32_t*) w + 4;
74
75 size_t k = kc;
76
77
78 while (k >= 8 * sizeof(int8_t)) {
79 const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0);
80 const __m128i vxa0 = _mm_cvtepi8_epi16(va0);
81 a0 += 8;
82 const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1);
83 const __m128i vxa1 = _mm_cvtepi8_epi16(va1);
84 a1 += 8;
85
86 const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w);
87
88 const __m128i vxb0 = _mm_cvtepi8_epi16(vb0);
89
90 vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0));
91 vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0));
92 const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8));
93
94 const __m128i vxb1 = _mm_cvtepi8_epi16(vb1);
95
96 vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1));
97 vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1));
98 const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16));
99
100 const __m128i vxb2 = _mm_cvtepi8_epi16(vb2);
101
102 vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2));
103 vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2));
104 const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24));
105
106 const __m128i vxb3 = _mm_cvtepi8_epi16(vb3);
107
108 vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3));
109 vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3));
110
111 w = (const int8_t*) w + 32;
112 k -= 8 * sizeof(int8_t);
113 }
114
115 const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1);
116 const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3);
117 const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1);
118 const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3);
119
120 __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23);
121 __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23);
122
123 __m128 vout0x0123 = _mm_cvtepi32_ps(vacc0x0123);
124 __m128 vout1x0123 = _mm_cvtepi32_ps(vacc1x0123);
125
126 const __m128i vinput_scale01 = _mm_loadu_si128((const __m128i*) &quantization_params[0]);
127 const __m128 vinput_scale0 = _mm_castsi128_ps(_mm_shuffle_epi32(vinput_scale01, _MM_SHUFFLE(1, 1, 1, 1)));
128 const __m128 vinput_scale1 = _mm_castsi128_ps(_mm_shuffle_epi32(vinput_scale01, _MM_SHUFFLE(3, 3, 3, 3)));
129
130 vout0x0123 = _mm_mul_ps(vout0x0123, vinput_scale0);
131 vout1x0123 = _mm_mul_ps(vout1x0123, vinput_scale1);
132
133 const __m128 vfilter_output_scale0123 = _mm_load_ps((const float*) w);
134 vout0x0123 = _mm_mul_ps(vout0x0123, vfilter_output_scale0123);
135 vout1x0123 = _mm_mul_ps(vout1x0123, vfilter_output_scale0123);
136
137 const __m128 vbias0123 = _mm_load_ps((const float*) w + 4);
138 w = (const float*) w + 8;
139 vout0x0123 = _mm_add_ps(vout0x0123, vbias0123);
140 vout1x0123 = _mm_add_ps(vout1x0123, vbias0123);
141
142 vout0x0123 = _mm_max_ps(vout0x0123, vmin);
143 vout1x0123 = _mm_max_ps(vout1x0123, vmin);
144
145 vout0x0123 = _mm_min_ps(vout0x0123, vmax);
146 vout1x0123 = _mm_min_ps(vout1x0123, vmax);
147
148 if XNN_LIKELY(nc >= 4) {
149 _mm_storeu_ps(c0, vout0x0123);
150 _mm_storeu_ps(c1, vout1x0123);
151
152 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
153 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
154
155 c0 = (float*) ((uintptr_t) c0 + cn_stride);
156 c1 = (float*) ((uintptr_t) c1 + cn_stride);
157
158 nc -= 4;
159 } else {
160 if (nc & 2) {
161 _mm_storel_pi((__m64*) c0, vout0x0123);
162 vout0x0123 = _mm_unpackhi_ps(vout0x0123, vout0x0123);
163 c0 += 2;
164 _mm_storel_pi((__m64*) c1, vout1x0123);
165 vout1x0123 = _mm_unpackhi_ps(vout1x0123, vout1x0123);
166 c1 += 2;
167 }
168 if (nc & 1) {
169 _mm_store_ss(c0, vout0x0123);
170 _mm_store_ss(c1, vout1x0123);
171 }
172 nc = 0;
173 }
174 } while (nc != 0);
175 }