Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-1x4c8-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_1x4c8__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 <= 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 vb0 = _mm_loadl_epi64((const __m128i*) w);
72
73 const __m128i vxb0 = _mm_cvtepi8_epi16(vb0);
74
75 vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0));
76 const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8));
77
78 const __m128i vxb1 = _mm_cvtepi8_epi16(vb1);
79
80 vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1));
81 const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16));
82
83 const __m128i vxb2 = _mm_cvtepi8_epi16(vb2);
84
85 vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2));
86 const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24));
87
88 const __m128i vxb3 = _mm_cvtepi8_epi16(vb3);
89
90 vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3));
91
92 w = (const int8_t*) w + 32;
93 k -= 8 * sizeof(int8_t);
94 }
95
96 const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1);
97 const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3);
98
99 __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23);
100
101 __m128 vout0x0123 = _mm_cvtepi32_ps(vacc0x0123);
102
103 const __m128 vinput_scale0 = _mm_load1_ps(&quantization_params[0].inv_scale);
104
105 vout0x0123 = _mm_mul_ps(vout0x0123, vinput_scale0);
106
107 const __m128 vfilter_output_scale0123 = _mm_load_ps((const float*) w);
108 vout0x0123 = _mm_mul_ps(vout0x0123, vfilter_output_scale0123);
109
110 const __m128 vbias0123 = _mm_load_ps((const float*) w + 4);
111 w = (const float*) w + 8;
112 vout0x0123 = _mm_add_ps(vout0x0123, vbias0123);
113
114 vout0x0123 = _mm_max_ps(vout0x0123, vmin);
115
116 vout0x0123 = _mm_min_ps(vout0x0123, vmax);
117
118 if XNN_LIKELY(nc >= 4) {
119 _mm_storeu_ps(c0, vout0x0123);
120
121 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
122
123 c0 = (float*) ((uintptr_t) c0 + cn_stride);
124
125 nc -= 4;
126 } else {
127 if (nc & 2) {
128 _mm_storel_pi((__m64*) c0, vout0x0123);
129 vout0x0123 = _mm_unpackhi_ps(vout0x0123, vout0x0123);
130 c0 += 2;
131 }
132 if (nc & 1) {
133 _mm_store_ss(c0, vout0x0123);
134 }
135 nc = 0;
136 }
137 } while (nc != 0);
138 }