xref: /aosp_15_r20/external/XNNPACK/src/s16-rmaxabs/gen/neon-x8.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_x8(size_t batch,const int16_t * input,uint16_t * output)20 void xnn_s16_rmaxabs_ukernel__neon_x8(
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 
32 
33   // Remainder of full vectors
34   for (; batch >= 8; batch -= 8) {
35     const int16x8_t vi = vld1q_s16(input); input += 8;
36     const uint16x8_t vabs = vreinterpretq_u16_s16(vabsq_s16(vi));
37     vmax0 = vmaxq_u16(vmax0, vabs);
38   }
39 
40   // Remainder
41   if (batch != 0) {
42     do {
43       const int16x8_t vi = vld1q_dup_s16(input); input += 1;
44       const uint16x8_t vabs = vreinterpretq_u16_s16(vabsq_s16(vi));
45       vmax0 = vmaxq_u16(vmax0, vabs);
46     } while (--batch != 0);
47   }
48 
49   #if XNN_ARCH_ARM64
50     *output = vmaxvq_u16(vmax0);
51   #else
52     uint16x4_t vmax_lo = vmax_u16(vget_low_u16(vmax0), vget_high_u16(vmax0));
53     vmax_lo = vpmax_u16(vmax_lo, vmax_lo);
54     vmax_lo = vpmax_u16(vmax_lo, vmax_lo);
55     vst1_lane_u16(output, vmax_lo, 0);
56   #endif
57 }
58