Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/cospi.c
48375 views
/*1* Double-precision SVE cospi(x) function.2*3* Copyright (c) 2023-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "sv_math.h"8#include "mathlib.h"9#include "test_sig.h"10#include "test_defs.h"11#include "sv_poly_f64.h"1213static const struct data14{15double poly[10];16double range_val;17} data = {18/* Polynomial coefficients generated using Remez algorithm,19see sinpi.sollya for details. */20.poly = { 0x1.921fb54442d184p1, -0x1.4abbce625be53p2, 0x1.466bc6775ab16p1,21-0x1.32d2cce62dc33p-1, 0x1.507834891188ep-4, -0x1.e30750a28c88ep-8,220x1.e8f48308acda4p-12, -0x1.6fc0032b3c29fp-16,230x1.af86ae521260bp-21, -0x1.012a9870eeb7dp-25 },24.range_val = 0x1p53,25};2627/* A fast SVE implementation of cospi.28Maximum error 3.20 ULP:29_ZGVsMxv_cospi(0x1.f18ba32c63159p-6) got 0x1.fdabf595f9763p-130want 0x1.fdabf595f9766p-1. */31svfloat64_t SV_NAME_D1 (cospi) (svfloat64_t x, const svbool_t pg)32{33const struct data *d = ptr_barrier (&data);3435/* Using cospi(x) = sinpi(0.5 - x)36range reduction and offset into sinpi range -1/2 .. 1/237r = 0.5 - |x - rint(x)|. */38svfloat64_t n = svrinta_x (pg, x);39svfloat64_t r = svsub_x (pg, x, n);40r = svsub_x (pg, sv_f64 (0.5), svabs_x (pg, r));4142/* Result should be negated based on if n is odd or not.43If ax >= 2^53, the result will always be positive. */44svbool_t cmp = svaclt (pg, x, d->range_val);45svuint64_t intn = svreinterpret_u64 (svcvt_s64_z (pg, n));46svuint64_t sign = svlsl_z (cmp, intn, 63);4748/* y = sin(r). */49svfloat64_t r2 = svmul_x (pg, r, r);50svfloat64_t r4 = svmul_x (pg, r2, r2);51svfloat64_t y = sv_pw_horner_9_f64_x (pg, r2, r4, d->poly);52y = svmul_x (pg, y, r);5354return svreinterpret_f64 (sveor_x (pg, svreinterpret_u64 (y), sign));55}5657#if WANT_TRIGPI_TESTS58TEST_ULP (SV_NAME_D1 (cospi), 2.71)59TEST_DISABLE_FENV (SV_NAME_D1 (cospi))60TEST_SYM_INTERVAL (SV_NAME_D1 (cospi), 0, 0x1p-63, 5000)61TEST_SYM_INTERVAL (SV_NAME_D1 (cospi), 0x1p-63, 0.5, 10000)62TEST_SYM_INTERVAL (SV_NAME_D1 (cospi), 0.5, 0x1p51, 10000)63TEST_SYM_INTERVAL (SV_NAME_D1 (cospi), 0x1p51, inf, 100000)64#endif65CLOSE_SVE_ATTR666768