• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vmul/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_qs8_vmul_minmax_fp32_ukernel__scalar_x1(size_t n,const int8_t * input_a,const int8_t * input_b,int8_t * output,const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qs8_vmul_minmax_fp32_ukernel__scalar_x1(
17     size_t n,
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   const int32_t va_zero_point = params->fp32_scalar.a_zero_point;
24   const int32_t vb_zero_point = params->fp32_scalar.b_zero_point;
25   const float vscale = params->fp32_scalar.scale;
26   const float voutput_min_less_zero_point = params->fp32_scalar.output_min_less_zero_point;
27   const float voutput_max_less_zero_point = params->fp32_scalar.output_max_less_zero_point;
28   const float vmagic_bias = params->fp32_scalar.magic_bias;
29   const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar.magic_bias_less_output_zero_point;
30 
31   do {
32     const int32_t va = (int32_t) *input_a++ - va_zero_point;
33     const int32_t vb = (int32_t) *input_b++ - vb_zero_point;
34     const int32_t vacc = va * vb;
35 
36     float vfpacc = (float) vacc * vscale;
37     vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
38     vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
39     vfpacc += vmagic_bias;
40     const int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
41     *output++ = (int8_t) vout;
42 
43     n -= sizeof(int8_t);
44   } while (n != 0);
45 }
46