xref: /aosp_15_r20/external/XNNPACK/src/s16-rmaxabs/gen/scalar-x4.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/s16-rmaxabs/scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2022 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 <stddef.h>
12 #include <stdint.h>
13 
14 #include <xnnpack/math.h>
15 #include <xnnpack/rmaxabs.h>
16 
17 
xnn_s16_rmaxabs_ukernel__scalar_x4(size_t batch,const int16_t * input,uint16_t * output)18 void xnn_s16_rmaxabs_ukernel__scalar_x4(
19     size_t batch,
20     const int16_t* input,
21     uint16_t* output) {
22 
23   assert(batch > 0);
24   assert(input != NULL);
25   assert(output != NULL);
26 
27   uint32_t vmax0 = 0;
28   uint32_t vmax1 = 0;
29   uint32_t vmax2 = 0;
30   uint32_t vmax3 = 0;
31 
32   for (; batch >= 4; batch -= 4) {
33     const int32_t vi0 = (int32_t) input[0];
34     const int32_t vi1 = (int32_t) input[1];
35     const int32_t vi2 = (int32_t) input[2];
36     const int32_t vi3 = (int32_t) input[3];
37     input += 4;
38 
39     const uint32_t vabs0 = math_abs_s32(vi0);
40     const uint32_t vabs1 = math_abs_s32(vi1);
41     const uint32_t vabs2 = math_abs_s32(vi2);
42     const uint32_t vabs3 = math_abs_s32(vi3);
43 
44     vmax0 = math_max_u32(vmax0, vabs0);
45     vmax1 = math_max_u32(vmax1, vabs1);
46     vmax2 = math_max_u32(vmax2, vabs2);
47     vmax3 = math_max_u32(vmax3, vabs3);
48   }
49 
50   vmax0 = math_max_u32(vmax0, vmax1);
51   vmax2 = math_max_u32(vmax2, vmax3);
52   vmax0 = math_max_u32(vmax0, vmax2);
53 
54   if (batch != 0) {
55     do {
56       const int32_t vi = (int32_t) *input++;
57       const uint32_t vabs = math_abs_s32(vi);
58       vmax0 = math_max_u32(vmax0, vabs);
59     } while (--batch != 0);
60   }
61   *output = (uint16_t) vmax0;
62 }
63