• 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 % 4 == 0
7$assert BATCH_TILE >= 4
8$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
9#include <assert.h>
10
11#include <arm_neon.h>
12
13#include <xnnpack/common.h>
14#include <xnnpack/vunary.h>
15
16
17void xnn_f32_vlrelu_ukernel__neon_x${BATCH_TILE}(
18    size_t n,
19    const float* x,
20    float* y,
21    const union xnn_f32_lrelu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
22{
23  assert(n != 0);
24  assert(n % sizeof(float) == 0);
25
26  const float32x4_t vslope = vld1q_dup_f32(&params->scalar.slope);
27
28  for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
29    $for N in range(0, BATCH_TILE, 4):
30      const float32x4_t vx${ABC[N:N+4]} = vld1q_f32(x); x += 4;
31
32    $for N in range(0, BATCH_TILE, 4):
33      float32x4_t vacc${ABC[N:N+4]} = vmulq_f32(vx${ABC[N:N+4]}, vslope);
34      const uint32x4_t vmask${ABC[N:N+4]} = vcltq_s32(vreinterpretq_s32_f32(vx${ABC[N:N+4]}), vmovq_n_s32(0));
35
36    $for N in range(0, BATCH_TILE, 4):
37      vacc${ABC[N:N+4]} = vbslq_f32(vmask${ABC[N:N+4]}, vacc${ABC[N:N+4]}, vx${ABC[N:N+4]});
38
39    $for N in range(0, BATCH_TILE, 4):
40      vst1q_f32(y, vacc${ABC[N:N+4]}); y += 4;
41  }
42  $if BATCH_TILE > 4:
43    for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
44      const float32x4_t vx = vld1q_f32(x); x += 4;
45      float32x4_t vacc = vmulq_f32(vx, vslope);
46      const uint32x4_t vmask = vcltq_s32(vreinterpretq_s32_f32(vx), vmovq_n_s32(0));
47      vacc = vbslq_f32(vmask, vacc, vx);
48      vst1q_f32(y, vacc); y += 4;
49    }
50  if XNN_UNLIKELY(n != 0) {
51    const float32x4_t vx = vld1q_f32(x);
52    float32x4_t vacc = vmulq_f32(vx, vslope);
53    const uint32x4_t vmask = vcltq_s32(vreinterpretq_s32_f32(vx), vmovq_n_s32(0));
54    vacc = vbslq_f32(vmask, vacc, vx);
55
56    float32x2_t vacc_lo = vget_low_f32(vacc);
57    if (n & (2 * sizeof(float))) {
58      vst1_f32(y, vacc_lo); y += 2;
59      vacc_lo = vget_high_f32(vacc);
60    }
61    if (n & (1 * sizeof(float))) {
62      vst1_lane_f32(y, vacc_lo, 0);
63    }
64  }
65}
66