blob: 12e5bbf28909b7120587cf029b16b57b3e38c345 [file] [log] [blame]
XNNPACK Teamb455b122019-09-27 18:10:33 -07001/*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 * All rights reserved.
4 *
5 * Copyright 2019 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
11#include <assert.h>
12
13#include <arm_neon.h>
14
15#include <xnnpack/rmax.h>
16
17
18void xnn_u8_rmax_ukernel__neon(
19 size_t n,
20 const uint8_t* x,
21 uint8_t* y)
22{
23 assert(n != 0);
24
25 if XNN_LIKELY(n >= 16) {
26 uint8x16_t vmax = vmovq_n_u8(0);
27 do {
28 const uint8x16_t vx = vld1q_u8(x); x += 16;
29 vmax = vmaxq_u8(vmax, vx);
30 n -= 16;
31 } while (n >= 16);
32 if (n != 0) {
33 const size_t x_increment = n - 16;
34 x = (const uint8_t*) ((uintptr_t) x + x_increment);
35 const uint8x16_t vx = vld1q_u8(x);
36 vmax = vmaxq_u8(vmax, vx);
37 }
38 uint8x8_t vmax8 = vmax_u8(vget_low_u8(vmax), vget_high_u8(vmax));
39 const uint8x8_t vmax4 = vpmax_u8(vmax8, vmax8);
40 const uint8x8_t vmax2 = vpmax_u8(vmax4, vmax4);
41 const uint8x8_t vmax1 = vpmax_u8(vmax2, vmax2);
42 vst1_lane_u8(y, vmax1, 0);
43 } else {
44 uint8x8_t vmax = vmov_n_u8(0);
45 do {
46 const uint8x8_t vx = vld1_dup_u8(x); x += 1;
47 vmax = vmax_u8(vmax, vx);
48 } while (--n != 0);
49 vst1_lane_u8(y, vmax, 0);
50 }
51}