xref: /freebsd/contrib/arm-optimized-routines/pl/math/sv_hypotf_1u5.c (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1 /*
2  * Single-precision SVE hypot(x) function.
3  *
4  * Copyright (c) 2023, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 #include "sv_math.h"
9 #include "pl_sig.h"
10 #include "pl_test.h"
11 
12 #define TinyBound 0x0c800000 /* asuint (0x1p-102).  */
13 #define Thres 0x73000000     /* 0x70000000 - TinyBound.  */
14 
15 static svfloat32_t NOINLINE
16 special_case (svfloat32_t sqsum, svfloat32_t x, svfloat32_t y, svbool_t pg,
17 	      svbool_t special)
18 {
19   return sv_call2_f32 (hypotf, x, y, svsqrt_x (pg, sqsum), special);
20 }
21 
22 /* SVE implementation of single-precision hypot.
23    Maximum error observed is 1.21 ULP:
24    _ZGVsMxvv_hypotf (0x1.6a213cp-19, -0x1.32b982p-26) got 0x1.6a2346p-19
25 						     want 0x1.6a2344p-19.  */
26 svfloat32_t SV_NAME_F2 (hypot) (svfloat32_t x, svfloat32_t y,
27 				const svbool_t pg)
28 {
29   svfloat32_t sqsum = svmla_x (pg, svmul_x (pg, x, x), y, y);
30 
31   svbool_t special = svcmpge (
32       pg, svsub_x (pg, svreinterpret_u32 (sqsum), TinyBound), Thres);
33 
34   if (unlikely (svptest_any (pg, special)))
35     return special_case (sqsum, x, y, pg, special);
36 
37   return svsqrt_x (pg, sqsum);
38 }
39 
40 PL_SIG (SV, F, 2, hypot, -10.0, 10.0)
41 PL_TEST_ULP (SV_NAME_F2 (hypot), 0.71)
42 PL_TEST_INTERVAL2 (SV_NAME_F2 (hypot), 0, inf, 0, inf, 10000)
43 PL_TEST_INTERVAL2 (SV_NAME_F2 (hypot), 0, inf, -0, -inf, 10000)
44 PL_TEST_INTERVAL2 (SV_NAME_F2 (hypot), -0, -inf, 0, inf, 10000)
45 PL_TEST_INTERVAL2 (SV_NAME_F2 (hypot), -0, -inf, -0, -inf, 10000)
46