xref: /aosp_15_r20/external/XNNPACK/src/qu8-vmulc/gen/minmax-fp32-scalar-x1.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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/vmul.h>
14 
15 
xnn_qu8_vmulc_minmax_fp32_ukernel__scalar_x1(size_t n,const uint8_t * input_a,const uint8_t * input_b,uint8_t * output,const union xnn_qu8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qu8_vmulc_minmax_fp32_ukernel__scalar_x1(
17     size_t n,
18     const uint8_t* input_a,
19     const uint8_t* input_b,
20     uint8_t* output,
21     const union xnn_qu8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
22 {
23   const int32_t va_zero_point = params->fp32_scalar.a_zero_point;
24   const float vscale = params->fp32_scalar.scale;
25   const float voutput_min_less_zero_point = params->fp32_scalar.output_min_less_zero_point;
26   const float voutput_max_less_zero_point = params->fp32_scalar.output_max_less_zero_point;
27   const float vmagic_bias = params->fp32_scalar.magic_bias;
28   const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar.magic_bias_less_output_zero_point;
29 
30   const int32_t vb = (int32_t) *input_b - params->fp32_scalar.b_zero_point;
31   do {
32     const int32_t va = (int32_t) *input_a++ - va_zero_point;
33     const int32_t vacc = va * vb;
34 
35     float vfpacc = (float) vacc * vscale;
36     vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
37     vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
38     vfpacc += vmagic_bias;
39     const int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
40     *output++ = (uint8_t) vout;
41 
42     n -= sizeof(uint8_t);
43   } while (n != 0);
44 }
45