Debian Codegraph @

src/qs8-vmulc/gen/qs8-vmulc-minmax-fp32-scalar-u1.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vmulc/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/vbinary.h"
14
15
16 void xnn_qs8_vmulc_minmax_fp32_ukernel__scalar_u1(
17 size_t batch,
18 const int8_t* input_a,
19 const int8_t* input_b,
20 int8_t* output,
21 const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
22 {
23 assert(batch != 0);
24 assert(batch % sizeof(int8_t) == 0);
25 assert(input_a != NULL);
26 assert(input_b != NULL);
27 assert(output != NULL);
28
29 const int32_t va_zero_point = params->scalar.a_zero_point;
30 const float vscale = params->scalar.scale;
31 const float voutput_min_less_zero_point = (int32_t) params->scalar.output_min - (int32_t) params->scalar.output_zero_point;
32 const float voutput_max_less_zero_point = (int32_t) params->scalar.output_max - (int32_t) params->scalar.output_zero_point;
33 const float vmagic_bias = 12582912.0f;
34 const int32_t vmagic_bias_less_output_zero_point = INT32_C(0x4B400000) - (int32_t) params->scalar.output_zero_point;
35
36 const int32_t vb = (int32_t) *input_b - params->scalar.b_zero_point;
37 do {
38 const int32_t va = (int32_t) *input_a++ - va_zero_point;
39 const int32_t vacc = va * vb;
40
41 float vfpacc = (float) vacc * vscale;
42 vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
43 vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
44 vfpacc += vmagic_bias;
45 const int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
46 *output++ = (int8_t) vout;
47
48 batch -= sizeof(int8_t);
49 } while (batch != 0);
50 }