• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 
8 #include <arm_neon.h>
9 
10 #include <xnnpack/common.h>
11 #include <xnnpack/rmax.h>
12 
13 
xnn_f32_rmax_ukernel__neon(size_t n,const float * x,float * y)14 void xnn_f32_rmax_ukernel__neon(
15     size_t n,
16     const float* x,
17     float* y)
18 {
19   assert(n != 0);
20   assert(n % sizeof(float) == 0);
21 
22   float32x4_t vmax0 = vld1q_dup_f32(x);
23   float32x4_t vmax1 = vmax0;
24   float32x4_t vmax2 = vmax0;
25   float32x4_t vmax3 = vmax0;
26   for (; n >= 64; n -= 64) {
27     const float32x4_t vx0 = vld1q_f32(x); x += 4;
28     const float32x4_t vx1 = vld1q_f32(x); x += 4;
29     const float32x4_t vx2 = vld1q_f32(x); x += 4;
30     const float32x4_t vx3 = vld1q_f32(x); x += 4;
31 
32     vmax0 = vmaxq_f32(vmax0, vx0);
33     vmax1 = vmaxq_f32(vmax1, vx1);
34     vmax2 = vmaxq_f32(vmax2, vx2);
35     vmax3 = vmaxq_f32(vmax3, vx3);
36   }
37   float32x4_t vmax = vmaxq_f32(vmaxq_f32(vmax0, vmax1), vmaxq_f32(vmax2, vmax3));
38   for (; n >= 16; n -= 16) {
39     const float32x4_t vx = vld1q_f32(x); x += 4;
40     vmax = vmaxq_f32(vmax, vx);
41   }
42 #if XNN_ARCH_ARM64
43   float32x2_t vmax_lo = vget_low_f32(vpmaxq_f32(vmax, vmax));
44 #else
45   float32x2_t vmax_lo = vmax_f32(vget_low_f32(vmax), vget_high_f32(vmax));
46 #endif
47   if XNN_UNLIKELY(n != 0) {
48     do {
49       const float32x2_t vx = vld1_dup_f32(x); x += 1;
50       vmax_lo = vmax_f32(vmax_lo, vx);
51       n -= 4;
52     } while (n != 0);
53   }
54 #if XNN_ARCH_ARM64
55   *y = vmaxv_f32(vmax_lo);
56 #else
57   vst1_lane_f32(y, vpmax_f32(vmax_lo, vmax_lo), 0);
58 #endif
59 }
60