xref: /aosp_15_r20/external/XNNPACK/src/s16-rmaxabs/gen/neon-x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/s16-rmaxabs/neon.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 <arm_neon.h>
15 
16 #include <xnnpack/math.h>
17 #include <xnnpack/rmaxabs.h>
18 
19 
xnn_s16_rmaxabs_ukernel__neon_x16(size_t batch,const int16_t * input,uint16_t * output)20 void xnn_s16_rmaxabs_ukernel__neon_x16(
21     size_t batch,
22     const int16_t* input,
23     uint16_t* output) {
24 
25   assert(batch > 0);
26   assert(input != NULL);
27   assert(output != NULL);
28 
29   const uint16x8_t vzero = vdupq_n_u16(0);
30   uint16x8_t vmax0 = vzero;
31   uint16x8_t vmax1 = vzero;
32 
33   for (; batch >= 16; batch -= 16) {
34     const int16x8_t vi0 = vld1q_s16(input); input += 8;
35     const int16x8_t vi1 = vld1q_s16(input); input += 8;
36 
37     const uint16x8_t vabs0 = vreinterpretq_u16_s16(vabsq_s16(vi0));
38     const uint16x8_t vabs1 = vreinterpretq_u16_s16(vabsq_s16(vi1));
39 
40     vmax0 = vmaxq_u16(vmax0, vabs0);
41     vmax1 = vmaxq_u16(vmax1, vabs1);
42   }
43 
44   vmax0 = vmaxq_u16(vmax0, vmax1);
45 
46   // Remainder of full vectors
47   for (; batch >= 8; batch -= 8) {
48     const int16x8_t vi = vld1q_s16(input); input += 8;
49     const uint16x8_t vabs = vreinterpretq_u16_s16(vabsq_s16(vi));
50     vmax0 = vmaxq_u16(vmax0, vabs);
51   }
52 
53   // Remainder
54   if (batch != 0) {
55     do {
56       const int16x8_t vi = vld1q_dup_s16(input); input += 1;
57       const uint16x8_t vabs = vreinterpretq_u16_s16(vabsq_s16(vi));
58       vmax0 = vmaxq_u16(vmax0, vabs);
59     } while (--batch != 0);
60   }
61 
62   #if XNN_ARCH_ARM64
63     *output = vmaxvq_u16(vmax0);
64   #else
65     uint16x4_t vmax_lo = vmax_u16(vget_low_u16(vmax0), vget_high_u16(vmax0));
66     vmax_lo = vpmax_u16(vmax_lo, vmax_lo);
67     vmax_lo = vpmax_u16(vmax_lo, vmax_lo);
68     vst1_lane_u16(output, vmax_lo, 0);
69   #endif
70 }
71