• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 
8 #include <xnnpack/math.h>
9 #include <xnnpack/vunary.h>
10 
11 
xnn_s8_vclamp_ukernel__scalar_x4(size_t n,const int8_t * x,int8_t * y,const union xnn_s8_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])12 void xnn_s8_vclamp_ukernel__scalar_x4(
13     size_t n,
14     const int8_t* x,
15     int8_t* y,
16     const union xnn_s8_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
17 {
18   assert(n != 0);
19 
20   const int32_t voutput_max = params->scalar.max;
21   const int32_t voutput_min = params->scalar.min;
22 
23   for (; n >= 4 * sizeof(int8_t); n -= 4 * sizeof(int8_t)) {
24     int32_t vt0 = (int32_t) x[0];
25     int32_t vt1 = (int32_t) x[1];
26     int32_t vt2 = (int32_t) x[2];
27     int32_t vt3 = (int32_t) x[3];
28     x += 4;
29 
30     vt0 = math_max_s32(vt0, voutput_min);
31     vt1 = math_max_s32(vt1, voutput_min);
32     vt2 = math_max_s32(vt2, voutput_min);
33     vt3 = math_max_s32(vt3, voutput_min);
34 
35     vt0 = math_min_s32(vt0, voutput_max);
36     vt1 = math_min_s32(vt1, voutput_max);
37     vt2 = math_min_s32(vt2, voutput_max);
38     vt3 = math_min_s32(vt3, voutput_max);
39 
40     y[0] = (int8_t) vt0;
41     y[1] = (int8_t) vt1;
42     y[2] = (int8_t) vt2;
43     y[3] = (int8_t) vt3;
44     y += 4;
45   }
46 
47   if XNN_UNLIKELY(n != 0) {
48     do {
49       int32_t vt = (int32_t) *x++;
50       vt = math_max_s32(vt, voutput_min);
51       vt = math_min_s32(vt, voutput_max);
52       *y++ = (int8_t) vt;
53 
54       n -= sizeof(int8_t);
55     } while (n != 0);
56   }
57 }
58