• 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$assert OP in ["ABS", "NEG", "SQR"]
10#include <assert.h>
11
12#include <arm_neon.h>
13
14#include <xnnpack/common.h>
15#include <xnnpack/vunary.h>
16
17
18$VOPQ_F32 = {
19$  "ABS": lambda x: "vabsq_f32(%s)" % x,
20$  "NEG": lambda x: "vnegq_f32(%s)" % x,
21$  "SQR": lambda x: "vmulq_f32(%s, %s)" % (x, x),
22$}[OP]
23$PARAMS = {
24$  "ABS": "xnn_f32_abs_params",
25$  "NEG": "xnn_f32_neg_params",
26$  "SQR": "xnn_f32_default_params",
27$}[OP]
28void xnn_f32_v${OP.lower()}_ukernel__neon_x${BATCH_TILE}(
29    size_t n,
30    const float* x,
31    float* y,
32    const union ${PARAMS} params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
33{
34  assert(n != 0);
35  assert(n % sizeof(float) == 0);
36  assert(x != NULL);
37  assert(y != NULL);
38
39  for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
40    $for N in range(0, BATCH_TILE, 4):
41      const float32x4_t vx${ABC[N:N+4]} = vld1q_f32(x); x += 4;
42
43    $for N in range(0, BATCH_TILE, 4):
44      const float32x4_t vy${ABC[N:N+4]} = ${VOPQ_F32("vx" + ABC[N:N+4])};
45
46    $for N in range(0, BATCH_TILE, 4):
47      vst1q_f32(y, vy${ABC[N:N+4]}); y += 4;
48  }
49  $if BATCH_TILE > 4:
50    for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
51      const float32x4_t vx = vld1q_f32(x); x += 4;
52      const float32x4_t vy = ${VOPQ_F32("vx")};
53      vst1q_f32(y, vy); y += 4;
54    }
55  if XNN_UNLIKELY(n != 0) {
56    const float32x4_t vx = vld1q_f32(x);
57    const float32x4_t vy = ${VOPQ_F32("vx")};
58    float32x2_t vy_lo = vget_low_f32(vy);
59    if (n & (2 * sizeof(float))) {
60      vst1_f32(y, vy_lo); y += 2;
61      vy_lo = vget_high_f32(vy);
62    }
63    if (n & (1 * sizeof(float))) {
64      vst1_lane_f32(y, vy_lo, 0);
65    }
66  }
67}
68