Debian Codegraph @

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