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 % 4 == 0 7$assert BATCH_TILE >= 4 8$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" 9#include <assert.h> 10#include <math.h> 11 12#include <arm_neon.h> 13 14#include <xnnpack/common.h> 15#include <xnnpack/vunary.h> 16 17 18void xnn_f32_vsqrt_ukernel__neonfma_nr2fma1adj_x${BATCH_TILE}( 19 size_t n, 20 const float* x, 21 float* y, 22 const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN 23{ 24 assert(n != 0); 25 assert(n % sizeof(float) == 0); 26 27 $if BATCH_TILE > 4: 28 const float32x4_t vhalf = vmovq_n_f32(0.5f); 29 for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) { 30 $for N in range(0, BATCH_TILE, 4): 31 const float32x4_t vx${ABC[N:N+4]} = vld1q_f32(x); x += 4; 32 33 $for N in range(0, BATCH_TILE, 4): 34 const float32x4_t vrsqrtx${ABC[N:N+4]} = vrsqrteq_f32(vx${ABC[N:N+4]}); 35 36 $for N in range(0, BATCH_TILE, 4): 37 float32x4_t vsqrtx${ABC[N:N+4]} = vmulq_f32(vrsqrtx${ABC[N:N+4]}, vx${ABC[N:N+4]}); 38 float32x4_t vhalfrsqrtx${ABC[N:N+4]} = vmulq_f32(vrsqrtx${ABC[N:N+4]}, vhalf); 39 40 $for N in range(0, BATCH_TILE, 4): 41 float32x4_t vresidual${ABC[N:N+4]} = vfmsq_f32(vhalf, vsqrtx${ABC[N:N+4]}, vhalfrsqrtx${ABC[N:N+4]}); 42 43 $for N in range(0, BATCH_TILE, 4): 44 vhalfrsqrtx${ABC[N:N+4]} = vfmaq_f32(vhalfrsqrtx${ABC[N:N+4]}, vresidual${ABC[N:N+4]}, vhalfrsqrtx${ABC[N:N+4]}); 45 vsqrtx${ABC[N:N+4]} = vfmaq_f32(vsqrtx${ABC[N:N+4]}, vresidual${ABC[N:N+4]}, vsqrtx${ABC[N:N+4]}); 46 47 $for N in range(0, BATCH_TILE, 4): 48 vresidual${ABC[N:N+4]} = vfmsq_f32(vhalf, vsqrtx${ABC[N:N+4]}, vhalfrsqrtx${ABC[N:N+4]}); 49 50 $for N in range(0, BATCH_TILE, 4): 51 vhalfrsqrtx${ABC[N:N+4]} = vfmaq_f32(vhalfrsqrtx${ABC[N:N+4]}, vresidual${ABC[N:N+4]}, vhalfrsqrtx${ABC[N:N+4]}); 52 vsqrtx${ABC[N:N+4]} = vfmaq_f32(vsqrtx${ABC[N:N+4]}, vresidual${ABC[N:N+4]}, vsqrtx${ABC[N:N+4]}); 53 54 $for N in range(0, BATCH_TILE, 4): 55 const float32x4_t vadjustment${ABC[N:N+4]} = vfmsq_f32(vx${ABC[N:N+4]}, vsqrtx${ABC[N:N+4]}, vsqrtx${ABC[N:N+4]}); 56 57 $for N in range(0, BATCH_TILE, 4): 58 const float32x4_t vy${ABC[N:N+4]} = vfmaq_f32(vsqrtx${ABC[N:N+4]}, vhalfrsqrtx${ABC[N:N+4]}, vadjustment${ABC[N:N+4]}); 59 60 $for N in range(0, BATCH_TILE, 4): 61 vst1q_f32(y, vy${ABC[N:N+4]}); y += 4; 62 } 63 if XNN_UNLIKELY(n != 0) { 64 do { 65 const float vx = *x++; 66 const float vy = sqrtf(vx); 67 *y++ = vy; 68 n -= sizeof(float); 69 } while (n != 0); 70 } 71} 72