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$assert OP in ["RNDNE", "RNDZ", "RNDU", "RNDD"] 9#include <assert.h> 10#include <math.h> 11 12#include <xnnpack/common.h> 13#include <xnnpack/math.h> 14#include <xnnpack/vunary.h> 15 16 17$OP_FUNC = { 18$ "RNDNE": "nearbyintf", 19$ "RNDZ": "truncf", 20$ "RNDU": "ceilf", 21$ "RNDD": "floorf", 22$}[OP] 23void xnn_f32_v${OP.lower()}_ukernel__scalar_libm_x${BATCH_TILE}( 24 size_t n, 25 const float* x, 26 float* y, 27 const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS(1)]) 28{ 29 assert(n != 0); 30 assert(n % sizeof(float) == 0); 31 32 $if BATCH_TILE > 1: 33 for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) { 34 $for N in range(BATCH_TILE): 35 const float vx${ABC[N]} = x[${N}]; 36 x += ${BATCH_TILE}; 37 38 $for N in range(BATCH_TILE): 39 const float vy${ABC[N]} = ${OP_FUNC}(vx${ABC[N]}); 40 41 $for N in range(BATCH_TILE): 42 y[${N}] = vy${ABC[N]}; 43 y += ${BATCH_TILE}; 44 } 45 if XNN_UNLIKELY(n != 0) { 46 $if BATCH_TILE > 2: 47 do { 48 const float vx = *x++; 49 const float vy = ${OP_FUNC}(vx); 50 *y++ = vy; 51 n -= sizeof(float); 52 } while (n != 0); 53 $else: 54 const float vx = *x; 55 const float vy = ${OP_FUNC}(vx); 56 *y = vy; 57 } 58 $else: 59 do { 60 const float vx = *x++; 61 const float vy = ${OP_FUNC}(vx); 62 *y++ = vy; 63 n -= sizeof(float); 64 } while (n != 0); 65} 66