Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x4c8-minmax-avx-ld64.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_ld64(
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 vb0 = _mm_loadl_epi64((const __m128i*) w);
87 const __m128i vxb0 = _mm_cvtepi8_epi16(vb0);
88
89 vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0));
90 const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8));
91 const __m128i vxb1 = _mm_cvtepi8_epi16(vb1);
92
93 vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1));
94 const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16));
95 const __m128i vxb2 = _mm_cvtepi8_epi16(vb2);
96
97 vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2));
98 const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24));
99 const __m128i vxb3 = _mm_cvtepi8_epi16(vb3);
100
101 vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3));
102
103 w = (const void*) ((const int8_t*) w + 32);
104 k += 8 * sizeof(int8_t);
105 }
106 p -= 1 * sizeof(void*);
107 } while (p != 0);
108
109 const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1);
110 const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3);
111
112 __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23);
113
114 __m128 vout0x0123 = _mm_cvtepi32_ps(vacc0x0123);
115
116 vout0x0123 = _mm_mul_ps(vout0x0123, vinput_scale);
117
118 const __m128 vfilter_output_scale0123 = _mm_load_ps((const float*) w);
119 vout0x0123 = _mm_mul_ps(vout0x0123, vfilter_output_scale0123);
120
121 const __m128 vbias0123 = _mm_load_ps((const float*) w + 4);
122 w = (const float*) w + 8;
123 vout0x0123 = _mm_add_ps(vout0x0123, vbias0123);
124
125 vout0x0123 = _mm_max_ps(vout0x0123, vmin);
126
127 vout0x0123 = _mm_min_ps(vout0x0123, vmax);
128
129 if XNN_LIKELY(nc >= 4) {
130 _mm_storeu_ps(c0, vout0x0123);
131
132 a = (const int8_t**restrict) ((uintptr_t) a - ks);
133
134 c0 = (float*) ((uintptr_t) c0 + cn_stride);
135
136 nc -= 4;
137 } else {
138 if (nc & 2) {
139 _mm_storel_pi((__m64*) c0, vout0x0123);
140 vout0x0123 = _mm_unpackhi_ps(vout0x0123, vout0x0123);
141 c0 += 2;
142 }
143 if (nc & 1) {
144 _mm_store_ss(c0, vout0x0123);
145 }
146 nc = 0;
147 }
148 } while (nc != 0);
149 }