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