Path: blob/main/contrib/arm-optimized-routines/math/aarch64/sve/exp2f.c
48378 views
/*1* Single-precision SVE 2^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 "test_sig.h"9#include "test_defs.h"1011#define Thres 0x1.5d5e2ap+6f1213static const struct data14{15float c0, c2, c4, c1, c3;16float shift, thres;17} data = {18/* Coefficients copied from the polynomial in AdvSIMD variant. */19.c0 = 0x1.62e422p-1f,20.c1 = 0x1.ebf9bcp-3f,21.c2 = 0x1.c6bd32p-5f,22.c3 = 0x1.3ce9e4p-7f,23.c4 = 0x1.59977ap-10f,24/* 1.5*2^17 + 127. */25.shift = 0x1.803f8p17f,26/* Roughly 87.3. For x < -Thres, the result is subnormal and not handled27correctly by FEXPA. */28.thres = Thres,29};3031static inline svfloat32_t32sv_exp2f_inline (svfloat32_t x, const svbool_t pg, const struct data *d)33{34/* exp2(x) = 2^n (1 + poly(r)), with 1 + poly(r) in [1/sqrt(2),sqrt(2)]35x = n + r, with r in [-1/2, 1/2]. */36svfloat32_t z = svadd_x (svptrue_b32 (), x, d->shift);37svfloat32_t n = svsub_x (svptrue_b32 (), z, d->shift);38svfloat32_t r = svsub_x (svptrue_b32 (), x, n);3940svfloat32_t scale = svexpa (svreinterpret_u32 (z));4142/* Polynomial evaluation: poly(r) ~ exp2(r)-1.43Evaluate polynomial use hybrid scheme - offset ESTRIN by 1 for44coefficients 1 to 4, and apply most significant coefficient directly. */45svfloat32_t even_coeffs = svld1rq (svptrue_b32 (), &d->c0);46svfloat32_t r2 = svmul_x (svptrue_b32 (), r, r);47svfloat32_t p12 = svmla_lane (sv_f32 (d->c1), r, even_coeffs, 1);48svfloat32_t p34 = svmla_lane (sv_f32 (d->c3), r, even_coeffs, 2);49svfloat32_t p14 = svmla_x (pg, p12, r2, p34);50svfloat32_t p0 = svmul_lane (r, even_coeffs, 0);51svfloat32_t poly = svmla_x (pg, p0, r2, p14);5253return svmla_x (pg, scale, scale, poly);54}5556static svfloat32_t NOINLINE57special_case (svfloat32_t x, svbool_t special, const struct data *d)58{59return sv_call_f32 (exp2f, x, sv_exp2f_inline (x, svptrue_b32 (), d),60special);61}6263/* Single-precision SVE exp2f routine. Implements the same algorithm64as AdvSIMD exp2f.65Worst case error is 1.04 ULPs.66_ZGVsMxv_exp2f(-0x1.af994ap-3) got 0x1.ba6a66p-167want 0x1.ba6a64p-1. */68svfloat32_t SV_NAME_F1 (exp2) (svfloat32_t x, const svbool_t pg)69{70const struct data *d = ptr_barrier (&data);71svbool_t special = svacgt (pg, x, d->thres);72if (unlikely (svptest_any (special, special)))73return special_case (x, special, d);74return sv_exp2f_inline (x, pg, d);75}7677TEST_SIG (SV, F, 1, exp2, -9.9, 9.9)78TEST_ULP (SV_NAME_F1 (exp2), 0.54)79TEST_DISABLE_FENV (SV_NAME_F1 (exp2))80TEST_SYM_INTERVAL (SV_NAME_F1 (exp2), 0, Thres, 50000)81TEST_SYM_INTERVAL (SV_NAME_F1 (exp2), Thres, inf, 50000)82CLOSE_SVE_ATTR838485