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/vunary.h> 11#include <xnnpack/common.h> 12#include <xnnpack/math.h> 13 14void xnn_f32_vrelu_ukernel__scalar_x${BATCH_TILE}( 15 size_t n, 16 const float* x_ptr, 17 float* y_ptr, 18 const union xnn_f32_relu_params params[restrict XNN_MIN_ELEMENTS(1)]) 19{ 20 assert(n != 0); 21 assert(n % sizeof(float) == 0); 22 assert(x_ptr != NULL); 23 assert(y_ptr != NULL); 24 25 const uint32_t* x = (const uint32_t*)x_ptr; 26 uint32_t* y = (uint32_t*)y_ptr; 27 28 $if BATCH_TILE > 1: 29 for (; n >= ${BATCH_TILE} * sizeof(uint32_t); n -= ${BATCH_TILE} * sizeof(uint32_t)) { 30 $for N in range(BATCH_TILE): 31 uint32_t vacc${ABC[N]} = x[${N}]; 32 x += ${BATCH_TILE}; 33 34 $for N in range(BATCH_TILE): 35 vacc${ABC[N]} = ((vacc${ABC[N]} >> 31) - 1) & vacc${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 uint32_t vacc = *x++; 45 vacc = ((vacc >> 31) - 1) & vacc; 46 *y++ = vacc; 47 n -= sizeof(uint32_t); 48 } while (n != 0); 49 $else: 50 uint32_t vacc = *x; 51 vacc = ((vacc >> 31) - 1) & vacc; 52 *y = vacc; 53 } 54 $else: 55 for (; n >= sizeof(uint32_t); n -= sizeof(uint32_t)) { 56 uint32_t vacc = *x++; 57 vacc = ((vacc >> 31) - 1) & vacc; 58 *y++ = vacc; 59 } 60} 61