blob: 2c3eb1dcbc323ec108882d66d284e801c5153eca [file] [log] [blame]
Marat Dukhan80fc9322019-09-29 21:06:36 -07001// Copyright (c) Facebook, Inc. and its affiliates.
2// All rights reserved.
3//
4// Copyright 2019 Google LLC
5//
6// This source code is licensed under the BSD-style license found in the
7// LICENSE file in the root directory of this source tree.
XNNPACK Teamb455b122019-09-27 18:10:33 -07008
9#include <assert.h>
10
11#include <arm_neon.h>
12
13#include <xnnpack/rmax.h>
14
15
16void xnn_u8_rmax_ukernel__neon(
17 size_t n,
18 const uint8_t* x,
19 uint8_t* y)
20{
21 assert(n != 0);
22
23 if XNN_LIKELY(n >= 16) {
24 uint8x16_t vmax = vmovq_n_u8(0);
25 do {
26 const uint8x16_t vx = vld1q_u8(x); x += 16;
27 vmax = vmaxq_u8(vmax, vx);
28 n -= 16;
29 } while (n >= 16);
30 if (n != 0) {
31 const size_t x_increment = n - 16;
32 x = (const uint8_t*) ((uintptr_t) x + x_increment);
33 const uint8x16_t vx = vld1q_u8(x);
34 vmax = vmaxq_u8(vmax, vx);
35 }
36 uint8x8_t vmax8 = vmax_u8(vget_low_u8(vmax), vget_high_u8(vmax));
37 const uint8x8_t vmax4 = vpmax_u8(vmax8, vmax8);
38 const uint8x8_t vmax2 = vpmax_u8(vmax4, vmax4);
39 const uint8x8_t vmax1 = vpmax_u8(vmax2, vmax2);
40 vst1_lane_u8(y, vmax1, 0);
41 } else {
42 uint8x8_t vmax = vmov_n_u8(0);
43 do {
44 const uint8x8_t vx = vld1_dup_u8(x); x += 1;
45 vmax = vmax_u8(vmax, vx);
46 } while (--n != 0);
47 vst1_lane_u8(y, vmax, 0);
48 }
49}