xref: /aosp_15_r20/external/XNNPACK/src/f32-vsqrt/scalar-sqrt.c.in (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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#include <math.h>
10
11#include <xnnpack/common.h>
12#include <xnnpack/vunary.h>
13
14
15void xnn_f32_vsqrt_ukernel__scalar_sqrt_x${BATCH_TILE}(
16    size_t n,
17    const float* x,
18    float* y,
19    const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS(1)])
20{
21  assert(n != 0);
22  assert(n % sizeof(float) == 0);
23
24  $if BATCH_TILE > 1:
25    for (; n >= ${BATCH_TILE} * sizeof(float); n -= ${BATCH_TILE} * sizeof(float)) {
26      $for N in range(BATCH_TILE):
27        const float vx${ABC[N]} = x[${N}];
28      x += ${BATCH_TILE};
29
30      $for N in range(BATCH_TILE):
31        const float vy${ABC[N]} = sqrtf(vx${ABC[N]});
32
33      $for N in range(BATCH_TILE):
34        y[${N}] = vy${ABC[N]};
35      y += ${BATCH_TILE};
36    }
37    if XNN_UNLIKELY(n != 0) {
38      $if BATCH_TILE > 2:
39        do {
40          const float vx = *x++;
41          const float vy = sqrtf(vx);
42          *y++ = vy;
43          n -= sizeof(float);
44        } while (n != 0);
45      $else:
46        const float vx = *x;
47        const float vy = sqrtf(vx);
48        *y = vy;
49    }
50  $else:
51    for (; n >= sizeof(float); n -= sizeof(float)) {
52      const float vx = *x++;
53      const float vy = sqrtf(vx);
54      *y++ = vy;
55    }
56}
57