Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/log10.c
48375 views
/*1* Double-precision SVE log10(x) function.2*3* Copyright (c) 2022-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "sv_math.h"8#include "test_sig.h"9#include "test_defs.h"1011#define Min 0x001000000000000012#define Max 0x7ff000000000000013#define Thres 0x7fe0000000000000 /* Max - Min. */14#define N (1 << V_LOG10_TABLE_BITS)1516static const struct data17{18double c0, c2;19double c1, c3;20double invln10, log10_2;21double c4;22uint64_t off;23} data = {24.c0 = -0x1.bcb7b1526e506p-3,25.c1 = 0x1.287a7636be1d1p-3,26.c2 = -0x1.bcb7b158af938p-4,27.c3 = 0x1.63c78734e6d07p-4,28.c4 = -0x1.287461742fee4p-4,29.invln10 = 0x1.bcb7b1526e50ep-2,30.log10_2 = 0x1.34413509f79ffp-2,31.off = 0x3fe6900900000000,32};3334static svfloat64_t NOINLINE35special_case (svfloat64_t hi, svuint64_t tmp, svfloat64_t y, svfloat64_t r2,36svbool_t special, const struct data *d)37{38svfloat64_t x = svreinterpret_f64 (svadd_x (svptrue_b64 (), tmp, d->off));39return sv_call_f64 (log10, x, svmla_x (svptrue_b64 (), hi, r2, y), special);40}4142/* Double-precision SVE log10 routine.43Maximum measured error is 2.46 ulps.44SV_NAME_D1 (log10)(0x1.131956cd4b627p+0) got 0x1.fffbdf6eaa669p-645want 0x1.fffbdf6eaa667p-6. */46svfloat64_t SV_NAME_D1 (log10) (svfloat64_t x, const svbool_t pg)47{48const struct data *d = ptr_barrier (&data);4950svuint64_t ix = svreinterpret_u64 (x);51svbool_t special = svcmpge (pg, svsub_x (pg, ix, Min), Thres);5253/* x = 2^k z; where z is in range [Off,2*Off) and exact.54The range is split into N subintervals.55The ith subinterval contains z and c is near its center. */56svuint64_t tmp = svsub_x (pg, ix, d->off);57svuint64_t i = svlsr_x (pg, tmp, 51 - V_LOG10_TABLE_BITS);58i = svand_x (pg, i, (N - 1) << 1);59svfloat64_t k = svcvt_f64_x (pg, svasr_x (pg, svreinterpret_s64 (tmp), 52));60svfloat64_t z = svreinterpret_f64 (61svsub_x (pg, ix, svand_x (pg, tmp, 0xfffULL << 52)));6263/* log(x) = k*log(2) + log(c) + log(z/c). */64svfloat64_t invc = svld1_gather_index (pg, &__v_log10_data.table[0].invc, i);65svfloat64_t logc66= svld1_gather_index (pg, &__v_log10_data.table[0].log10c, i);6768/* We approximate log(z/c) with a polynomial P(x) ~= log(x + 1):69r = z/c - 1 (we look up precomputed 1/c)70log(z/c) ~= P(r). */71svfloat64_t r = svmad_x (pg, invc, z, -1.0);7273/* hi = log(c) + k*log(2). */74svfloat64_t invln10_log10_2 = svld1rq_f64 (svptrue_b64 (), &d->invln10);75svfloat64_t w = svmla_lane_f64 (logc, r, invln10_log10_2, 0);76svfloat64_t hi = svmla_lane_f64 (w, k, invln10_log10_2, 1);7778/* y = r2*(A0 + r*A1 + r2*(A2 + r*A3 + r2*A4)) + hi. */79svfloat64_t odd_coeffs = svld1rq_f64 (svptrue_b64 (), &d->c1);80svfloat64_t r2 = svmul_x (svptrue_b64 (), r, r);81svfloat64_t y = svmla_lane_f64 (sv_f64 (d->c2), r, odd_coeffs, 1);82svfloat64_t p = svmla_lane_f64 (sv_f64 (d->c0), r, odd_coeffs, 0);83y = svmla_x (pg, y, r2, d->c4);84y = svmla_x (pg, p, r2, y);8586if (unlikely (svptest_any (pg, special)))87return special_case (hi, tmp, y, r2, special, d);88return svmla_x (pg, hi, r2, y);89}9091TEST_SIG (SV, D, 1, log10, 0.01, 11.1)92TEST_ULP (SV_NAME_D1 (log10), 1.97)93TEST_DISABLE_FENV (SV_NAME_D1 (log10))94TEST_INTERVAL (SV_NAME_D1 (log10), -0.0, -0x1p126, 100)95TEST_INTERVAL (SV_NAME_D1 (log10), 0x1p-149, 0x1p-126, 4000)96TEST_INTERVAL (SV_NAME_D1 (log10), 0x1p-126, 0x1p-23, 50000)97TEST_INTERVAL (SV_NAME_D1 (log10), 0x1p-23, 1.0, 50000)98TEST_INTERVAL (SV_NAME_D1 (log10), 1.0, 100, 50000)99TEST_INTERVAL (SV_NAME_D1 (log10), 100, inf, 50000)100CLOSE_SVE_ATTR101102103