xref: /aosp_15_r20/external/XNNPACK/src/s16-rmaxabs/gen/neon-x24.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_x24(size_t batch,const int16_t * input,uint16_t * output)20 void xnn_s16_rmaxabs_ukernel__neon_x24(
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   uint16x8_t vmax2 = vzero;
33 
34   for (; batch >= 24; batch -= 24) {
35     const int16x8_t vi0 = vld1q_s16(input); input += 8;
36     const int16x8_t vi1 = vld1q_s16(input); input += 8;
37     const int16x8_t vi2 = vld1q_s16(input); input += 8;
38 
39     const uint16x8_t vabs0 = vreinterpretq_u16_s16(vabsq_s16(vi0));
40     const uint16x8_t vabs1 = vreinterpretq_u16_s16(vabsq_s16(vi1));
41     const uint16x8_t vabs2 = vreinterpretq_u16_s16(vabsq_s16(vi2));
42 
43     vmax0 = vmaxq_u16(vmax0, vabs0);
44     vmax1 = vmaxq_u16(vmax1, vabs1);
45     vmax2 = vmaxq_u16(vmax2, vabs2);
46   }
47 
48   vmax0 = vmaxq_u16(vmax0, vmax1);
49   vmax0 = vmaxq_u16(vmax0, vmax2);
50 
51   // Remainder of full vectors
52   for (; batch >= 8; batch -= 8) {
53     const int16x8_t vi = vld1q_s16(input); input += 8;
54     const uint16x8_t vabs = vreinterpretq_u16_s16(vabsq_s16(vi));
55     vmax0 = vmaxq_u16(vmax0, vabs);
56   }
57 
58   // Remainder
59   if (batch != 0) {
60     do {
61       const int16x8_t vi = vld1q_dup_s16(input); input += 1;
62       const uint16x8_t vabs = vreinterpretq_u16_s16(vabsq_s16(vi));
63       vmax0 = vmaxq_u16(vmax0, vabs);
64     } while (--batch != 0);
65   }
66 
67   #if XNN_ARCH_ARM64
68     *output = vmaxvq_u16(vmax0);
69   #else
70     uint16x4_t vmax_lo = vmax_u16(vget_low_u16(vmax0), vget_high_u16(vmax0));
71     vmax_lo = vpmax_u16(vmax_lo, vmax_lo);
72     vmax_lo = vpmax_u16(vmax_lo, vmax_lo);
73     vst1_lane_u16(output, vmax_lo, 0);
74   #endif
75 }
76