• 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 ["RNDNE", "RNDZ", "RNDU", "RNDD"]
10#include <assert.h>
11
12#include <arm_neon.h>
13
14#include <xnnpack/common.h>
15#include <xnnpack/math.h>
16#include <xnnpack/vunary.h>
17
18
19$VRNDQ_F32 = {
20$  "RNDNE": "vrndnq_f32",
21$  "RNDZ": "vrndq_f32",
22$  "RNDU": "vrndpq_f32",
23$  "RNDD": "vrndmq_f32",
24$}[OP]
25void xnn_f32_v${OP.lower()}_ukernel__neonv8_x${BATCH_TILE}(
26    size_t n,
27    const float* x,
28    float* y,
29    const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
30{
31  assert(n != 0);
32  assert(n % sizeof(float) == 0);
33
34  for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
35    $for N in range(0, BATCH_TILE, 4):
36      const float32x4_t vx${ABC[N:N+4]} = vld1q_f32(x); x += 4;
37
38    $for N in range(0, BATCH_TILE, 4):
39      const float32x4_t vy${ABC[N:N+4]} = ${VRNDQ_F32}(vx${ABC[N:N+4]});
40
41    $for N in range(0, BATCH_TILE, 4):
42      vst1q_f32(y, vy${ABC[N:N+4]}); y += 4;
43  }
44  $if BATCH_TILE > 4:
45    for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
46      const float32x4_t vx = vld1q_f32(x); x += 4;
47      const float32x4_t vy = ${VRNDQ_F32}(vx);
48      vst1q_f32(y, vy); y += 4;
49    }
50  if XNN_UNLIKELY(n != 0) {
51    const float32x4_t vx = vld1q_f32(x);
52    const float32x4_t vy = ${VRNDQ_F32}(vx);
53    float32x2_t vy_lo = vget_low_f32(vy);
54    if (n & (2 * sizeof(float))) {
55      vst1_f32(y, vy_lo); y += 2;
56      vy_lo = vget_high_f32(vy);
57    }
58    if (n & (1 * sizeof(float))) {
59      vst1_lane_f32(y, vy_lo, 0);
60    }
61  }
62}
63