Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x4c8-minmax-sse41-ld128.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_1x4c8__sse41_ld128(
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 <= 1);
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
45 const __m128 vmin = _mm_set1_ps(params->scalar.min);
46 const __m128 vmax = _mm_set1_ps(params->scalar.max);
47 XNN_FORCE_REALIZATION(vmin);
48 XNN_FORCE_REALIZATION(vmax);
49
50
51 do {
52 const __m128i vksum = _mm_load_si128((const __m128i*) w);
53 __m128i vinput_zero_point0 = _mm_cvtsi32_si128(*((const int*) &quantization_params[0].zero_point));
54 vinput_zero_point0 = _mm_shuffle_epi32(vinput_zero_point0, _MM_SHUFFLE(0, 0, 0, 0));
55 const __m128i vzero = _mm_setzero_si128();
56 const __m128i vinit0 = _mm_mullo_epi32(vksum, vinput_zero_point0);
57 __m128i vacc0x0 = _mm_blend_epi16(vinit0, vzero, 0xFC);
58 __m128i vacc0x1 = _mm_blend_epi16(vinit0, vzero, 0xF3);
59 __m128i vacc0x2 = _mm_blend_epi16(vinit0, vzero, 0xCF);
60 __m128i vacc0x3 = _mm_blend_epi16(vinit0, vzero, 0x3F);
61 w = (const int32_t*) w + 4;
62
63 size_t k = kc;
64
65
66 while (k >= 8 * sizeof(int8_t)) {
67 const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0);
68 const __m128i vxa0 = _mm_cvtepi8_epi16(va0);
69 a0 += 8;
70
71 const __m128i vb01 = _mm_load_si128((const __m128i*) w);
72
73 const __m128i vxbm1 = _mm_unpackhi_epi8(vb01, vb01);
74 const __m128i vxb0 = _mm_cvtepi8_epi16(vb01);
75 const __m128i vxb1 = _mm_srai_epi16(vxbm1, 8);
76
77 vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0));
78 vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1));
79 const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16));
80
81 const __m128i vxbm3 = _mm_unpackhi_epi8(vb23, vb23);
82 const __m128i vxb2 = _mm_cvtepi8_epi16(vb23);
83 const __m128i vxb3 = _mm_srai_epi16(vxbm3, 8);
84
85 vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2));
86 vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3));
87
88 w = (const int8_t*) w + 32;
89 k -= 8 * sizeof(int8_t);
90 }
91
92 const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1);
93 const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3);
94
95 __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23);
96
97 __m128 vout0x0123 = _mm_cvtepi32_ps(vacc0x0123);
98
99 const __m128 vinput_scale0 = _mm_load1_ps(&quantization_params[0].inv_scale);
100
101 vout0x0123 = _mm_mul_ps(vout0x0123, vinput_scale0);
102
103 const __m128 vfilter_output_scale0123 = _mm_load_ps((const float*) w);
104 vout0x0123 = _mm_mul_ps(vout0x0123, vfilter_output_scale0123);
105
106 const __m128 vbias0123 = _mm_load_ps((const float*) w + 4);
107 w = (const float*) w + 8;
108 vout0x0123 = _mm_add_ps(vout0x0123, vbias0123);
109
110 vout0x0123 = _mm_max_ps(vout0x0123, vmin);
111
112 vout0x0123 = _mm_min_ps(vout0x0123, vmax);
113
114 if XNN_LIKELY(nc >= 4) {
115 _mm_storeu_ps(c0, vout0x0123);
116
117 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
118
119 c0 = (float*) ((uintptr_t) c0 + cn_stride);
120
121 nc -= 4;
122 } else {
123 if (nc & 2) {
124 _mm_storel_pi((__m64*) c0, vout0x0123);
125 vout0x0123 = _mm_unpackhi_ps(vout0x0123, vout0x0123);
126 c0 += 2;
127 }
128 if (nc & 1) {
129 _mm_store_ss(c0, vout0x0123);
130 }
131 nc = 0;
132 }
133 } while (nc != 0);
134 }