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__scalar_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 25 $if BATCH_TILE > 1: 26 for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) { 27 $for N in range(BATCH_TILE): 28 const float vx${ABC[N]} = x[${N}]; 29 x += ${BATCH_TILE}; 30 31 $for N in range(BATCH_TILE): 32 float vacc${ABC[N]} = vx${ABC[N]} * vslope; 33 34 $for N in range(BATCH_TILE): 35 vacc${ABC[N]} = XNN_UNPREDICTABLE(vx${ABC[N]} < 0.0f) ? vacc${ABC[N]} : vx${ABC[N]}; 36 37 $for N in range(BATCH_TILE): 38 y[${N}] = vacc${ABC[N]}; 39 y += ${BATCH_TILE}; 40 } 41 if XNN_UNLIKELY(n != 0) { 42 $if BATCH_TILE > 2: 43 do { 44 const float vx = *x++; 45 float vacc = vx * vslope; 46 vacc = XNN_UNPREDICTABLE(vx < 0.0f) ? vacc : vx; 47 *y++ = vacc; 48 n -= sizeof(float); 49 } while (n != 0); 50 $else: 51 const float vx = *x; 52 float vacc = vx * vslope; 53 vacc = XNN_UNPREDICTABLE(vx < 0.0f) ? vacc : vx; 54 *y = vacc; 55 } 56 $else: 57 do { 58 const float vx = *x++; 59 float vacc = vx * vslope; 60 vacc = XNN_UNPREDICTABLE(vx < 0.0f) ? vacc : vx; 61 *y++ = vacc; 62 n -= sizeof(float); 63 } while (n != 0); 64} 65