• 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 >= 1
7$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
8#include <assert.h>
9
10#include <xnnpack/common.h>
11#include <xnnpack/vunary.h>
12
13
14void xnn_f32_vlrelu_ukernel__wasm_x${BATCH_TILE}(
15    size_t n,
16    const float* x,
17    float* y,
18    const union xnn_f32_lrelu_params params[restrict XNN_MIN_ELEMENTS(1)])
19{
20  assert(n != 0);
21  assert(n % sizeof(float) == 0);
22
23  const float vslope = params->scalar.slope;
24  const float vzero = 0.0f;
25
26  $if BATCH_TILE > 1:
27    for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
28      $for N in range(BATCH_TILE):
29        const float vx${ABC[N]} = x[${N}];
30      x += ${BATCH_TILE};
31
32      $for N in range(BATCH_TILE):
33        const float vnegx${ABC[N]} = __builtin_wasm_min_f32(vx${ABC[N]}, vzero);
34
35      $for N in range(BATCH_TILE):
36        float vacc${ABC[N]} = vnegx${ABC[N]} * vslope;
37        const float vposx${ABC[N]} = __builtin_wasm_max_f32(vx${ABC[N]}, vzero);
38
39      $for N in range(BATCH_TILE):
40        vacc${ABC[N]} += vposx${ABC[N]};
41
42      $for N in range(BATCH_TILE):
43        y[${N}] = vacc${ABC[N]};
44      y += ${BATCH_TILE};
45    }
46    if XNN_UNLIKELY(n != 0) {
47      $if BATCH_TILE > 2:
48        do {
49          const float vx = *x++;
50          const float vnegx = __builtin_wasm_min_f32(vx, vzero);
51          float vacc = vnegx * vslope;
52          const float vposx = __builtin_wasm_max_f32(vx, vzero);
53          vacc += vposx;
54          *y++ = vacc;
55          n -= sizeof(float);
56        } while (n != 0);
57      $else:
58        const float vx = *x;
59        const float vnegx = __builtin_wasm_min_f32(vx, vzero);
60        float vacc = vnegx * vslope;
61        const float vposx = __builtin_wasm_max_f32(vx, vzero);
62        vacc += vposx;
63        *y = vacc;
64    }
65  $else:
66    do {
67      const float vx = *x++;
68      const float vnegx = __builtin_wasm_min_f32(vx, vzero);
69      float vacc = vnegx * vslope;
70      const float vposx = __builtin_wasm_max_f32(vx, vzero);
71      vacc += vposx;
72      *y++ = vacc;
73      n -= sizeof(float);
74    } while (n != 0);
75}
76