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