blob: 8c87cd3d1b3cd419f26bd0562115667fe9dbbaf5 [file] [log] [blame]
Marat Dukhan779b2532021-06-29 14:14:13 -07001// Auto-generated file. Do not edit!
2// Template: src/qs8-igemm/scalar.c.in
3// Generator: tools/xngen
4//
5// Copyright 2021 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#include <math.h>
12
13#include <xnnpack/math.h>
14#include <xnnpack/gemm.h>
15
16
17void xnn_qs8_igemm_minmax_fp32_ukernel_3x2__scalar_lrint(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const int8_t**restrict a,
23 const void*restrict w,
24 int8_t*restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const int8_t* zero,
29 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30{
31 assert(mr != 0);
32 assert(mr <= 3);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(ks != 0);
36 assert(ks % (3 * sizeof(void*)) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
41 int8_t* c0 = c;
42 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr < 2) {
44 c1 = c0;
45 }
46 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
47 if XNN_UNPREDICTABLE(mr <= 2) {
48 c2 = c1;
49 }
50
51 do {
52 int32_t vacc0x0 = ((const int32_t*) w)[0];
53 int32_t vacc0x1 = ((const int32_t*) w)[1];
54 int32_t vacc1x0 = vacc0x0;
55 int32_t vacc1x1 = vacc0x1;
56 int32_t vacc2x0 = vacc0x0;
57 int32_t vacc2x1 = vacc0x1;
Marat Dukhan927d4742021-07-15 13:42:49 -070058 w = (const void*) ((const int32_t*) w + 2);
Marat Dukhan779b2532021-06-29 14:14:13 -070059
60 size_t p = ks;
61 do {
62 const int8_t* restrict a0 = a[0];
63 assert(a0 != NULL);
64 if XNN_UNPREDICTABLE(a0 != zero) {
65 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
66 }
67 const int8_t* restrict a1 = a[1];
68 assert(a1 != NULL);
69 if XNN_UNPREDICTABLE(a1 != zero) {
70 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
71 }
72 const int8_t* restrict a2 = a[2];
73 assert(a2 != NULL);
74 if XNN_UNPREDICTABLE(a2 != zero) {
75 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
76 }
77 a += 3;
78
79 size_t k = kc;
80 do {
81 const int32_t va0 = (int32_t) *a0++;
82 const int32_t va1 = (int32_t) *a1++;
83 const int32_t va2 = (int32_t) *a2++;
84
Marat Dukhan927d4742021-07-15 13:42:49 -070085 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
86 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
87 w = (const void*) ((const int8_t*) w + 2);
Marat Dukhan779b2532021-06-29 14:14:13 -070088
89 vacc0x0 += va0 * vb0;
90 vacc0x1 += va0 * vb1;
91 vacc1x0 += va1 * vb0;
92 vacc1x1 += va1 * vb1;
93 vacc2x0 += va2 * vb0;
94 vacc2x1 += va2 * vb1;
95
96 k -= sizeof(int8_t);
97 } while (k != 0);
98 p -= 3 * sizeof(void*);
99 } while (p != 0);
100
101 float vfpacc0x0 = (float) vacc0x0;
102 float vfpacc0x1 = (float) vacc0x1;
103 float vfpacc1x0 = (float) vacc1x0;
104 float vfpacc1x1 = (float) vacc1x1;
105 float vfpacc2x0 = (float) vacc2x0;
106 float vfpacc2x1 = (float) vacc2x1;
107
108 const float vscale = params->fp32_scalar_lrint.scale;
109 vfpacc0x0 *= vscale;
110 vfpacc0x1 *= vscale;
111 vfpacc1x0 *= vscale;
112 vfpacc1x1 *= vscale;
113 vfpacc2x0 *= vscale;
114 vfpacc2x1 *= vscale;
115
116 long vrndacc0x0 = lrintf(vfpacc0x0);
117 long vrndacc0x1 = lrintf(vfpacc0x1);
118 long vrndacc1x0 = lrintf(vfpacc1x0);
119 long vrndacc1x1 = lrintf(vfpacc1x1);
120 long vrndacc2x0 = lrintf(vfpacc2x0);
121 long vrndacc2x1 = lrintf(vfpacc2x1);
122
123 const long voutput_min_less_zero_point = params->fp32_scalar_lrint.output_min_less_zero_point;
124 vrndacc0x0 = XNN_UNPREDICTABLE(vrndacc0x0 < voutput_min_less_zero_point) ? voutput_min_less_zero_point : vrndacc0x0;
125 vrndacc0x1 = XNN_UNPREDICTABLE(vrndacc0x1 < voutput_min_less_zero_point) ? voutput_min_less_zero_point : vrndacc0x1;
126 vrndacc1x0 = XNN_UNPREDICTABLE(vrndacc1x0 < voutput_min_less_zero_point) ? voutput_min_less_zero_point : vrndacc1x0;
127 vrndacc1x1 = XNN_UNPREDICTABLE(vrndacc1x1 < voutput_min_less_zero_point) ? voutput_min_less_zero_point : vrndacc1x1;
128 vrndacc2x0 = XNN_UNPREDICTABLE(vrndacc2x0 < voutput_min_less_zero_point) ? voutput_min_less_zero_point : vrndacc2x0;
129 vrndacc2x1 = XNN_UNPREDICTABLE(vrndacc2x1 < voutput_min_less_zero_point) ? voutput_min_less_zero_point : vrndacc2x1;
130
131 const long voutput_max_less_zero_point = params->fp32_scalar_lrint.output_max_less_zero_point;
132 vrndacc0x0 = XNN_UNPREDICTABLE(vrndacc0x0 > voutput_max_less_zero_point) ? voutput_max_less_zero_point : vrndacc0x0;
133 vrndacc0x1 = XNN_UNPREDICTABLE(vrndacc0x1 > voutput_max_less_zero_point) ? voutput_max_less_zero_point : vrndacc0x1;
134 vrndacc1x0 = XNN_UNPREDICTABLE(vrndacc1x0 > voutput_max_less_zero_point) ? voutput_max_less_zero_point : vrndacc1x0;
135 vrndacc1x1 = XNN_UNPREDICTABLE(vrndacc1x1 > voutput_max_less_zero_point) ? voutput_max_less_zero_point : vrndacc1x1;
136 vrndacc2x0 = XNN_UNPREDICTABLE(vrndacc2x0 > voutput_max_less_zero_point) ? voutput_max_less_zero_point : vrndacc2x0;
137 vrndacc2x1 = XNN_UNPREDICTABLE(vrndacc2x1 > voutput_max_less_zero_point) ? voutput_max_less_zero_point : vrndacc2x1;
138
139 const int32_t voutput_zero_point = params->fp32_scalar_lrint.output_zero_point;
140 int32_t vout0x0 = (int32_t) vrndacc0x0 + voutput_zero_point;
141 int32_t vout0x1 = (int32_t) vrndacc0x1 + voutput_zero_point;
142 int32_t vout1x0 = (int32_t) vrndacc1x0 + voutput_zero_point;
143 int32_t vout1x1 = (int32_t) vrndacc1x1 + voutput_zero_point;
144 int32_t vout2x0 = (int32_t) vrndacc2x0 + voutput_zero_point;
145 int32_t vout2x1 = (int32_t) vrndacc2x1 + voutput_zero_point;
146
147 if XNN_LIKELY(nc >= 2) {
148 c2[0] = (int8_t) vout2x0;
149 c2[1] = (int8_t) vout2x1;
150 c1[0] = (int8_t) vout1x0;
151 c1[1] = (int8_t) vout1x1;
152 c0[0] = (int8_t) vout0x0;
153 c0[1] = (int8_t) vout0x1;
154
155 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
156 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
157 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
158
159 a = (const int8_t**restrict) ((uintptr_t) a - ks);
160 nc -= 2;
161 } else {
162 if (nc & 1) {
163 c2[0] = (int8_t) vout2x0;
164 c1[0] = (int8_t) vout1x0;
165 c0[0] = (int8_t) vout0x0;
166 }
167
168 nc = 0;
169 }
170 } while (nc != 0);
171}