• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 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$assert BATCH_TILE % 8 == 0
7$assert BATCH_TILE >= 8
8$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
9#include <assert.h>
10
11#include <arm_neon.h>
12
13#include <xnnpack/vunary.h>
14#include <xnnpack/common.h>
15
16
17void xnn_f16_relu_ukernel__neonfp16arith_x${BATCH_TILE}(
18    size_t n,
19    const void* restrict x_ptr,
20    void* restrict y_ptr,
21    const struct xnn_f16_relu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
22{
23  assert(n != 0);
24  assert(n % sizeof(__fp16) == 0);
25  assert(x_ptr != NULL);
26  assert(y_ptr != NULL);
27
28  const __fp16* x = (const __fp16*) x_ptr;
29  __fp16* y = (__fp16*) y_ptr;
30
31  const float16x8_t vzero = vmovq_n_f16(0);
32
33  for (; n >= ${BATCH_TILE} * sizeof(__fp16); n -= ${BATCH_TILE} * sizeof(__fp16)) {
34    $for N in range(0, BATCH_TILE, 8):
35      float16x8_t vacc${ABC[N:N+8]} = vld1q_f16(x); x += 8;
36
37    $for N in range(0, BATCH_TILE, 8):
38      vacc${ABC[N:N+8]} = vmaxq_f16(vacc${ABC[N:N+8]}, vzero);
39
40    $for N in range(0, BATCH_TILE, 8):
41      vst1q_f16(y, vacc${ABC[N:N+8]}); y += 8;
42  }
43  $if BATCH_TILE > 8:
44    for (; n >= 8 * sizeof(__fp16); n -= 8 * sizeof(__fp16)) {
45      float16x8_t vacc = vld1q_f16(x); x += 8;
46      vacc = vmaxq_f16(vacc, vzero);
47      vst1q_f16(y, vacc); y += 8;
48    }
49  if XNN_UNLIKELY(n != 0) {
50    float16x8_t vacc = vld1q_f16(x);
51    vacc = vmaxq_f16(vacc, vzero);
52
53    float16x4_t vacc_lo = vget_low_f16(vacc);
54    if (n & (4 * sizeof(__fp16))) {
55      vst1_f16(y, vacc_lo); y += 4;
56      vacc_lo = vget_high_f16(vacc);
57    }
58    if (n & (2 * sizeof(__fp16))) {
59      vst1_lane_u32(__builtin_assume_aligned(y, 1), vreinterpret_u32_f16(vacc_lo), 0); y += 2;
60      vacc_lo = vext_f16(vacc_lo, vacc_lo, 2);
61    }
62    if (n & (1 * sizeof(__fp16))) {
63      vst1_lane_f16(y, vacc_lo, 0);
64    }
65  }
66}
67