Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x4c8-minmax-sse41-ld128.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/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/igemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_1x4c8__sse41_ld128(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const int8_t** restrict a,
24 const void* restrict w,
25 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const int8_t* zero_data,
31 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
32 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
33 {
34 assert(mr != 0);
35 assert(mr <= 1);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(ks != 0);
39 assert(ks % (1 * sizeof(void*)) == 0);
40 assert(a_offset % 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 float* c0 = c;
47
48 const __m128 vmin = _mm_set1_ps(params->scalar.min);
49 const __m128 vmax = _mm_set1_ps(params->scalar.max);
50 XNN_FORCE_REALIZATION(vmin);
51 XNN_FORCE_REALIZATION(vmax);
52 __m128i vinput_zero_point = _mm_cvtsi32_si128(*((const int*) &quantization_params->zero_point));
53 vinput_zero_point = _mm_shuffle_epi32(vinput_zero_point, _MM_SHUFFLE(0, 0, 0, 0));
54 const __m128 vinput_scale = _mm_load1_ps(&quantization_params->inv_scale);
55
56
57 do {
58 const __m128i vksum = _mm_load_si128((const __m128i*) w);
59 const __m128i vzero = _mm_setzero_si128();
60 const __m128i vinit0 = _mm_mullo_epi32(vksum, vinput_zero_point);
61 __m128i vacc0x0 = _mm_blend_epi16(vinit0, vzero, 0xFC);
62 __m128i vacc0x1 = _mm_blend_epi16(vinit0, vzero, 0xF3);
63 __m128i vacc0x2 = _mm_blend_epi16(vinit0, vzero, 0xCF);
64 __m128i vacc0x3 = _mm_blend_epi16(vinit0, vzero, 0x3F);
65 w = (const int32_t*) w + 4;
66
67 size_t p = ks;
68 do {
69 const int8_t* restrict a0 = a[0];
70 if XNN_UNPREDICTABLE(a0 != zero) {
71 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
72 } else {
73 a0 = zero_data;
74 }
75 a += 1;
76
77 size_t k = 0;
78 while (k < kc) {
79 const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0);
80 const __m128i vxa0 = _mm_cvtepi8_epi16(va0);
81 a0 += 8;
82
83 const __m128i vb01 = _mm_load_si128((const __m128i*) w);
84 const __m128i vxb0 = _mm_cvtepi8_epi16(vb01);
85 const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8);
86
87 vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0));
88 vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1));
89 const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16));
90 const __m128i vxb2 = _mm_cvtepi8_epi16(vb23);
91 const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8);
92
93 vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2));
94 vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3));
95
96 w = (const void*) ((const int8_t*) w + 32);
97 k += 8 * sizeof(int8_t);
98 }
99 p -= 1 * sizeof(void*);
100 } while (p != 0);
101
102 const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1);
103 const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3);
104
105 __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23);
106
107 __m128 vout0x0123 = _mm_cvtepi32_ps(vacc0x0123);
108
109 vout0x0123 = _mm_mul_ps(vout0x0123, vinput_scale);
110
111 const __m128 vfilter_output_scale0123 = _mm_load_ps((const float*) w);
112 vout0x0123 = _mm_mul_ps(vout0x0123, vfilter_output_scale0123);
113
114 const __m128 vbias0123 = _mm_load_ps((const float*) w + 4);
115 w = (const float*) w + 8;
116 vout0x0123 = _mm_add_ps(vout0x0123, vbias0123);
117
118 vout0x0123 = _mm_max_ps(vout0x0123, vmin);
119
120 vout0x0123 = _mm_min_ps(vout0x0123, vmax);
121
122 if XNN_LIKELY(nc >= 4) {
123 _mm_storeu_ps(c0, vout0x0123);
124
125 a = (const int8_t**restrict) ((uintptr_t) a - ks);
126
127 c0 = (float*) ((uintptr_t) c0 + cn_stride);
128
129 nc -= 4;
130 } else {
131 if (nc & 2) {
132 _mm_storel_pi((__m64*) c0, vout0x0123);
133 vout0x0123 = _mm_unpackhi_ps(vout0x0123, vout0x0123);
134 c0 += 2;
135 }
136 if (nc & 1) {
137 _mm_store_ss(c0, vout0x0123);
138 }
139 nc = 0;
140 }
141 } while (nc != 0);
142 }