| 1 |
// 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 |
|
| 12 |
#include "xnnpack/math.h" |
| 13 |
#include "xnnpack/gemm.h" |
| 14 |
|
| 15 |
|
| 16 |
void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_2x4__scalar( |
| 17 |
size_t mr, |
| 18 |
size_t nc, |
| 19 |
size_t kc, |
| 20 |
size_t ks, |
| 21 |
const int8_t** restrict a, |
| 22 |
const void* restrict w, |
| 23 |
float* restrict c, |
| 24 |
size_t cm_stride, |
| 25 |
size_t cn_stride, |
| 26 |
size_t a_offset, |
| 27 |
const int8_t* zero, |
| 28 |
const int8_t* zero_data, |
| 29 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], |
| 30 |
const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) |
| 31 |
{ |
| 32 |
assert(mr != 0); |
| 33 |
assert(mr <= 2); |
| 34 |
assert(nc != 0); |
| 35 |
assert(kc != 0); |
| 36 |
assert(ks != 0); |
| 37 |
assert(ks % (2 * sizeof(void*)) == 0); |
| 38 |
assert(a != NULL); |
| 39 |
assert(w != NULL); |
| 40 |
assert(c != NULL); |
| 41 |
|
| 42 |
float* c0 = c; |
| 43 |
float* c1 = (float*) ((uintptr_t) c0 + cm_stride); |
| 44 |
if XNN_UNPREDICTABLE(mr != 2) { |
| 45 |
c1 = c0; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
do { |
| 50 |
const int32_t vksum0 = ((const int32_t*) w)[0]; |
| 51 |
const int32_t vksum1 = ((const int32_t*) w)[1]; |
| 52 |
const int32_t vksum2 = ((const int32_t*) w)[2]; |
| 53 |
const int32_t vksum3 = ((const int32_t*) w)[3]; |
| 54 |
const int32_t vinput_zero_point = quantization_params->zero_point; |
| 55 |
int32_t vacc0x0 = vksum0 * vinput_zero_point; |
| 56 |
int32_t vacc0x1 = vksum1 * vinput_zero_point; |
| 57 |
int32_t vacc0x2 = vksum2 * vinput_zero_point; |
| 58 |
int32_t vacc0x3 = vksum3 * vinput_zero_point; |
| 59 |
int32_t vacc1x0 = vksum0 * vinput_zero_point; |
| 60 |
int32_t vacc1x1 = vksum1 * vinput_zero_point; |
| 61 |
int32_t vacc1x2 = vksum2 * vinput_zero_point; |
| 62 |
int32_t vacc1x3 = vksum3 * vinput_zero_point; |
| 63 |
w = (const void*) ((const int32_t*) w + 4); |
| 64 |
|
| 65 |
size_t p = ks; |
| 66 |
do { |
| 67 |
const int8_t* restrict a0 = a[0]; |
| 68 |
assert(a0 != NULL); |
| 69 |
if XNN_UNPREDICTABLE(a0 != zero) { |
| 70 |
a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); |
| 71 |
} else { |
| 72 |
a0 = zero_data; |
| 73 |
} |
| 74 |
const int8_t* restrict a1 = a[1]; |
| 75 |
assert(a1 != NULL); |
| 76 |
if XNN_UNPREDICTABLE(a1 != zero) { |
| 77 |
a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); |
| 78 |
} else { |
| 79 |
a1 = zero_data; |
| 80 |
} |
| 81 |
a += 2; |
| 82 |
|
| 83 |
size_t k = kc; |
| 84 |
do { |
| 85 |
const int32_t va0 = (int32_t) *a0++; |
| 86 |
const int32_t va1 = (int32_t) *a1++; |
| 87 |
|
| 88 |
const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; |
| 89 |
const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; |
| 90 |
const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; |
| 91 |
const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; |
| 92 |
w = (const void*) ((const int8_t*) w + 4); |
| 93 |
|
| 94 |
vacc0x0 += va0 * vb0; |
| 95 |
vacc0x1 += va0 * vb1; |
| 96 |
vacc0x2 += va0 * vb2; |
| 97 |
vacc0x3 += va0 * vb3; |
| 98 |
vacc1x0 += va1 * vb0; |
| 99 |
vacc1x1 += va1 * vb1; |
| 100 |
vacc1x2 += va1 * vb2; |
| 101 |
vacc1x3 += va1 * vb3; |
| 102 |
|
| 103 |
k -= sizeof(int8_t); |
| 104 |
} while (k != 0); |
| 105 |
p -= 2 * sizeof(void*); |
| 106 |
} while (p != 0); |
| 107 |
|
| 108 |
float vout0x0 = (float) vacc0x0; |
| 109 |
float vout0x1 = (float) vacc0x1; |
| 110 |
float vout0x2 = (float) vacc0x2; |
| 111 |
float vout0x3 = (float) vacc0x3; |
| 112 |
float vout1x0 = (float) vacc1x0; |
| 113 |
float vout1x1 = (float) vacc1x1; |
| 114 |
float vout1x2 = (float) vacc1x2; |
| 115 |
float vout1x3 = (float) vacc1x3; |
| 116 |
|
| 117 |
const float vinput_scale = quantization_params->inv_scale; |
| 118 |
vout0x0 *= vinput_scale; |
| 119 |
vout0x1 *= vinput_scale; |
| 120 |
vout0x2 *= vinput_scale; |
| 121 |
vout0x3 *= vinput_scale; |
| 122 |
vout1x0 *= vinput_scale; |
| 123 |
vout1x1 *= vinput_scale; |
| 124 |
vout1x2 *= vinput_scale; |
| 125 |
vout1x3 *= vinput_scale; |
| 126 |
|
| 127 |
const float vfilter_output_scale0 = ((const float*) w)[0]; |
| 128 |
vout0x0 *= vfilter_output_scale0; |
| 129 |
vout1x0 *= vfilter_output_scale0; |
| 130 |
const float vfilter_output_scale1 = ((const float*) w)[1]; |
| 131 |
vout0x1 *= vfilter_output_scale1; |
| 132 |
vout1x1 *= vfilter_output_scale1; |
| 133 |
const float vfilter_output_scale2 = ((const float*) w)[2]; |
| 134 |
vout0x2 *= vfilter_output_scale2; |
| 135 |
vout1x2 *= vfilter_output_scale2; |
| 136 |
const float vfilter_output_scale3 = ((const float*) w)[3]; |
| 137 |
vout0x3 *= vfilter_output_scale3; |
| 138 |
vout1x3 *= vfilter_output_scale3; |
| 139 |
|
| 140 |
const float vbias0 = ((const float*) w)[4]; |
| 141 |
vout0x0 += vbias0; |
| 142 |
vout1x0 += vbias0; |
| 143 |
const float vbias1 = ((const float*) w)[5]; |
| 144 |
vout0x1 += vbias1; |
| 145 |
vout1x1 += vbias1; |
| 146 |
const float vbias2 = ((const float*) w)[6]; |
| 147 |
vout0x2 += vbias2; |
| 148 |
vout1x2 += vbias2; |
| 149 |
const float vbias3 = ((const float*) w)[7]; |
| 150 |
vout0x3 += vbias3; |
| 151 |
vout1x3 += vbias3; |
| 152 |
|
| 153 |
w = (const float*) w + 8; |
| 154 |
|
| 155 |
const float voutput_min = params->scalar.min; |
| 156 |
vout0x0 = math_max_f32(vout0x0, voutput_min); |
| 157 |
vout1x0 = math_max_f32(vout1x0, voutput_min); |
| 158 |
vout0x1 = math_max_f32(vout0x1, voutput_min); |
| 159 |
vout1x1 = math_max_f32(vout1x1, voutput_min); |
| 160 |
vout0x2 = math_max_f32(vout0x2, voutput_min); |
| 161 |
vout1x2 = math_max_f32(vout1x2, voutput_min); |
| 162 |
vout0x3 = math_max_f32(vout0x3, voutput_min); |
| 163 |
vout1x3 = math_max_f32(vout1x3, voutput_min); |
| 164 |
|
| 165 |
const float voutput_max = params->scalar.max; |
| 166 |
vout0x0 = math_min_f32(vout0x0, voutput_max); |
| 167 |
vout1x0 = math_min_f32(vout1x0, voutput_max); |
| 168 |
vout0x1 = math_min_f32(vout0x1, voutput_max); |
| 169 |
vout1x1 = math_min_f32(vout1x1, voutput_max); |
| 170 |
vout0x2 = math_min_f32(vout0x2, voutput_max); |
| 171 |
vout1x2 = math_min_f32(vout1x2, voutput_max); |
| 172 |
vout0x3 = math_min_f32(vout0x3, voutput_max); |
| 173 |
vout1x3 = math_min_f32(vout1x3, voutput_max); |
| 174 |
|
| 175 |
if XNN_LIKELY(nc >= 4) { |
| 176 |
c1[0] = vout1x0; |
| 177 |
c1[1] = vout1x1; |
| 178 |
c1[2] = vout1x2; |
| 179 |
c1[3] = vout1x3; |
| 180 |
c0[0] = vout0x0; |
| 181 |
c0[1] = vout0x1; |
| 182 |
c0[2] = vout0x2; |
| 183 |
c0[3] = vout0x3; |
| 184 |
|
| 185 |
c0 = (float*) ((uintptr_t) c0 + cn_stride); |
| 186 |
c1 = (float*) ((uintptr_t) c1 + cn_stride); |
| 187 |
|
| 188 |
a = (const int8_t**restrict) ((uintptr_t) a - ks); |
| 189 |
nc -= 4; |
| 190 |
} else { |
| 191 |
if (nc & 2) { |
| 192 |
c1[0] = vout1x0; |
| 193 |
c1[1] = vout1x1; |
| 194 |
vout1x0 = vout1x2; |
| 195 |
c1 += 2; |
| 196 |
c0[0] = vout0x0; |
| 197 |
c0[1] = vout0x1; |
| 198 |
vout0x0 = vout0x2; |
| 199 |
c0 += 2; |
| 200 |
} |
| 201 |
if (nc & 1) { |
| 202 |
c1[0] = vout1x0; |
| 203 |
c0[0] = vout0x0; |
| 204 |
} |
| 205 |
|
| 206 |
nc = 0; |
| 207 |
} |
| 208 |
} while (nc != 0); |
| 209 |
} |