xref: /aosp_15_r20/external/XNNPACK/src/math/sqrt-u32-scalar-cvti64-sqrt-lrint.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Copyright 2022 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 #include <assert.h>
7 #include <stddef.h>
8 #include <math.h>
9 
10 #include <xnnpack/math-stubs.h>
11 
12 
xnn_math_u32_sqrt__scalar_cvti64_sqrt_lrint(size_t n,const uint32_t * input,uint32_t * output)13 void xnn_math_u32_sqrt__scalar_cvti64_sqrt_lrint(
14     size_t n,
15     const uint32_t* input,
16     uint32_t* output)
17 {
18   assert(n % sizeof(uint32_t) == 0);
19 
20   for (; n != 0; n -= sizeof(uint32_t)) {
21     const uint32_t vx = *input++;
22 
23     double vf = (double) (int64_t) (uint64_t) vx;
24     vf = sqrt(vf);
25     const uint32_t vy = (uint32_t) (int32_t) lrint(vf);
26 
27     *output++ = vy;
28   }
29 }
30