1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner * Double-precision SVE hypot(x) function.
3*f3087befSAndrew Turner *
4*f3087befSAndrew Turner * Copyright (c) 2023-2024, Arm Limited.
5*f3087befSAndrew Turner * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6*f3087befSAndrew Turner */
7*f3087befSAndrew Turner
8*f3087befSAndrew Turner #include "sv_math.h"
9*f3087befSAndrew Turner #include "test_sig.h"
10*f3087befSAndrew Turner #include "test_defs.h"
11*f3087befSAndrew Turner
12*f3087befSAndrew Turner static const struct data
13*f3087befSAndrew Turner {
14*f3087befSAndrew Turner uint64_t tiny_bound, thres;
15*f3087befSAndrew Turner } data = {
16*f3087befSAndrew Turner .tiny_bound = 0x0c80000000000000, /* asuint (0x1p-102). */
17*f3087befSAndrew Turner .thres = 0x7300000000000000, /* asuint (inf) - tiny_bound. */
18*f3087befSAndrew Turner };
19*f3087befSAndrew Turner
20*f3087befSAndrew Turner static svfloat64_t NOINLINE
special_case(svfloat64_t sqsum,svfloat64_t x,svfloat64_t y,svbool_t pg,svbool_t special)21*f3087befSAndrew Turner special_case (svfloat64_t sqsum, svfloat64_t x, svfloat64_t y, svbool_t pg,
22*f3087befSAndrew Turner svbool_t special)
23*f3087befSAndrew Turner {
24*f3087befSAndrew Turner return sv_call2_f64 (hypot, x, y, svsqrt_x (pg, sqsum), special);
25*f3087befSAndrew Turner }
26*f3087befSAndrew Turner
27*f3087befSAndrew Turner /* SVE implementation of double-precision hypot.
28*f3087befSAndrew Turner Maximum error observed is 1.21 ULP:
29*f3087befSAndrew Turner _ZGVsMxvv_hypot (-0x1.6a22d0412cdd3p+352, 0x1.d3d89bd66fb1ap+330)
30*f3087befSAndrew Turner got 0x1.6a22d0412cfp+352
31*f3087befSAndrew Turner want 0x1.6a22d0412cf01p+352. */
SV_NAME_D2(hypot)32*f3087befSAndrew Turner svfloat64_t SV_NAME_D2 (hypot) (svfloat64_t x, svfloat64_t y, svbool_t pg)
33*f3087befSAndrew Turner {
34*f3087befSAndrew Turner const struct data *d = ptr_barrier (&data);
35*f3087befSAndrew Turner
36*f3087befSAndrew Turner svfloat64_t sqsum = svmla_x (pg, svmul_x (pg, x, x), y, y);
37*f3087befSAndrew Turner
38*f3087befSAndrew Turner svbool_t special = svcmpge (
39*f3087befSAndrew Turner pg, svsub_x (pg, svreinterpret_u64 (sqsum), d->tiny_bound), d->thres);
40*f3087befSAndrew Turner
41*f3087befSAndrew Turner if (unlikely (svptest_any (pg, special)))
42*f3087befSAndrew Turner return special_case (sqsum, x, y, pg, special);
43*f3087befSAndrew Turner return svsqrt_x (pg, sqsum);
44*f3087befSAndrew Turner }
45*f3087befSAndrew Turner
46*f3087befSAndrew Turner TEST_SIG (SV, D, 2, hypot, -10.0, 10.0)
47*f3087befSAndrew Turner TEST_ULP (SV_NAME_D2 (hypot), 0.71)
48*f3087befSAndrew Turner TEST_DISABLE_FENV (SV_NAME_D2 (hypot))
49*f3087befSAndrew Turner TEST_INTERVAL2 (SV_NAME_D2 (hypot), 0, inf, 0, inf, 10000)
50*f3087befSAndrew Turner TEST_INTERVAL2 (SV_NAME_D2 (hypot), 0, inf, -0, -inf, 10000)
51*f3087befSAndrew Turner TEST_INTERVAL2 (SV_NAME_D2 (hypot), -0, -inf, 0, inf, 10000)
52*f3087befSAndrew Turner TEST_INTERVAL2 (SV_NAME_D2 (hypot), -0, -inf, -0, -inf, 10000)
53*f3087befSAndrew Turner CLOSE_SVE_ATTR
54