1 /* 2 * Single-precision vector tanpif(x) function. 3 * 4 * Copyright (c) 2024, Arm Limited. 5 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 6 */ 7 8 #include "sv_math.h" 9 #include "test_defs.h" 10 #include "test_sig.h" 11 12 const static struct v_tanpif_data 13 { 14 float c0, c2, c4, c6; 15 float c1, c3, c5, c7; 16 } tanpif_data = { 17 /* Coefficients for tan(pi * x). */ 18 .c0 = 0x1.921fb4p1f, .c1 = 0x1.4abbcep3f, .c2 = 0x1.466b8p5f, 19 .c3 = 0x1.461c72p7f, .c4 = 0x1.42e9d4p9f, .c5 = 0x1.69e2c4p11f, 20 .c6 = 0x1.e85558p11f, .c7 = 0x1.a52e08p16f, 21 }; 22 23 /* Approximation for single-precision vector tanpif(x) 24 The maximum error is 3.34 ULP: 25 _ZGVsMxv_tanpif(0x1.d6c09ap-2) got 0x1.f70aacp+2 26 want 0x1.f70aa6p+2. */ 27 svfloat32_t SV_NAME_F1 (tanpi) (svfloat32_t x, const svbool_t pg) 28 { 29 const struct v_tanpif_data *d = ptr_barrier (&tanpif_data); 30 svfloat32_t odd_coeffs = svld1rq (pg, &d->c1); 31 svfloat32_t n = svrintn_x (pg, x); 32 33 /* inf produces nan that propagates. */ 34 svfloat32_t xr = svsub_x (pg, x, n); 35 svfloat32_t ar = svabd_x (pg, x, n); 36 svbool_t flip = svcmpgt (pg, ar, 0.25f); 37 svfloat32_t r = svsel (flip, svsub_x (pg, sv_f32 (0.5f), ar), ar); 38 39 svfloat32_t r2 = svmul_x (pg, r, r); 40 svfloat32_t r4 = svmul_x (pg, r2, r2); 41 42 /* Order-7 Pairwise Horner. */ 43 svfloat32_t p01 = svmla_lane (sv_f32 (d->c0), r2, odd_coeffs, 0); 44 svfloat32_t p23 = svmla_lane (sv_f32 (d->c2), r2, odd_coeffs, 1); 45 svfloat32_t p45 = svmla_lane (sv_f32 (d->c4), r2, odd_coeffs, 2); 46 svfloat32_t p67 = svmla_lane (sv_f32 (d->c6), r2, odd_coeffs, 3); 47 svfloat32_t p = svmad_x (pg, p67, r4, p45); 48 p = svmad_x (pg, p, r4, p23); 49 p = svmad_x (pg, p, r4, p01); 50 svfloat32_t poly = svmul_x (pg, r, p); 51 52 svfloat32_t poly_recip = svdiv_x (pg, sv_f32 (1.0), poly); 53 svfloat32_t y = svsel (flip, poly_recip, poly); 54 55 svuint32_t sign 56 = sveor_x (pg, svreinterpret_u32 (xr), svreinterpret_u32 (ar)); 57 return svreinterpret_f32 (svorr_x (pg, svreinterpret_u32 (y), sign)); 58 } 59 60 #if WANT_TRIGPI_TESTS 61 TEST_DISABLE_FENV (SV_NAME_F1 (tanpi)) 62 TEST_ULP (SV_NAME_F1 (tanpi), 2.84) 63 TEST_SYM_INTERVAL (SV_NAME_F1 (tanpi), 0, 0x1p-31, 50000) 64 TEST_SYM_INTERVAL (SV_NAME_F1 (tanpi), 0x1p-31, 0.5, 100000) 65 TEST_SYM_INTERVAL (SV_NAME_F1 (tanpi), 0.5, 0x1p23f, 100000) 66 TEST_SYM_INTERVAL (SV_NAME_F1 (tanpi), 0x1p23f, inf, 100000) 67 #endif 68 CLOSE_SVE_ATTR 69