Debian Codegraph @

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