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