1 // Auto-generated file. Do not edit!
2 // Template: src/f32-qs8-vcvt/scalar-lrintf.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/common.h>
14 #include <xnnpack/math.h>
15 #include <xnnpack/vcvt.h>
16
17
xnn_f32_qu8_vcvt_ukernel__scalar_lrintf_x4(size_t n,const float * x,uint8_t * y,const union xnn_f32_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_qu8_vcvt_ukernel__scalar_lrintf_x4(
19 size_t n,
20 const float* x,
21 uint8_t* y,
22 const union xnn_f32_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)])
23 {
24 assert(n != 0);
25 assert(n % sizeof(float) == 0);
26 assert(x != NULL);
27 assert(y != NULL);
28
29 const float vscale = params->scalar_lrintf.scale;
30 const float voutput_min_less_zero_point = params->scalar_lrintf.output_min_less_zero_point;
31 const float voutput_max_less_zero_point = params->scalar_lrintf.output_max_less_zero_point;
32 const int32_t voutput_zero_point = params->scalar_lrintf.output_zero_point;
33
34 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
35 float vx0 = x[0];
36 float vx1 = x[1];
37 float vx2 = x[2];
38 float vx3 = x[3];
39 x += 4;
40
41 vx0 *= vscale;
42 vx1 *= vscale;
43 vx2 *= vscale;
44 vx3 *= vscale;
45
46 vx0 = math_max_f32(vx0, voutput_min_less_zero_point);
47 vx1 = math_max_f32(vx1, voutput_min_less_zero_point);
48 vx2 = math_max_f32(vx2, voutput_min_less_zero_point);
49 vx3 = math_max_f32(vx3, voutput_min_less_zero_point);
50
51 vx0 = math_min_f32(vx0, voutput_max_less_zero_point);
52 vx1 = math_min_f32(vx1, voutput_max_less_zero_point);
53 vx2 = math_min_f32(vx2, voutput_max_less_zero_point);
54 vx3 = math_min_f32(vx3, voutput_max_less_zero_point);
55
56 int32_t vy0 = (int32_t) lrintf(vx0);
57 int32_t vy1 = (int32_t) lrintf(vx1);
58 int32_t vy2 = (int32_t) lrintf(vx2);
59 int32_t vy3 = (int32_t) lrintf(vx3);
60
61 vy0 += voutput_zero_point;
62 vy1 += voutput_zero_point;
63 vy2 += voutput_zero_point;
64 vy3 += voutput_zero_point;
65
66 y[0] = (uint8_t) vy0;
67 y[1] = (uint8_t) vy1;
68 y[2] = (uint8_t) vy2;
69 y[3] = (uint8_t) vy3;
70 y += 4;
71 }
72 if XNN_UNLIKELY(n != 0) {
73 do {
74 float vx = *x++;
75 vx *= vscale;
76 vx = math_max_f32(vx, voutput_min_less_zero_point);
77 vx = math_min_f32(vx, voutput_max_less_zero_point);
78
79 int32_t vy = (int32_t) lrintf(vx);
80 vy += voutput_zero_point;
81
82 *y++ = (uint8_t) vy;
83
84 n -= sizeof(float);
85 } while (n != 0);
86 }
87 }
88