Path: blob/main/contrib/arm-optimized-routines/math/aarch64/advsimd/exp2f_1u.c
48378 views
/*1* Single-precision vector 2^x function.2*3* Copyright (c) 2019-2024, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include "v_math.h"8#include "test_defs.h"910static const struct data11{12float32x4_t c0, c1, c2, c3, c4, c5, shift;13uint32x4_t exponent_bias;14float32x4_t special_bound, scale_thresh;15uint32x4_t special_offset, special_bias;16} data = {17.shift = V4 (0x1.8p23f),18.exponent_bias = V4 (0x3f800000),19.special_bound = V4 (126.0f),20.scale_thresh = V4 (192.0f),21.special_offset = V4 (0x82000000),22.special_bias = V4 (0x7f000000),23/* maxerr: 0.878 ulp. */24.c0 = V4 (0x1.416b5ep-13f),25.c1 = V4 (0x1.5f082ep-10f),26.c2 = V4 (0x1.3b2dep-7f),27.c3 = V4 (0x1.c6af7cp-5f),28.c4 = V4 (0x1.ebfbdcp-3f),29.c5 = V4 (0x1.62e43p-1f),30};3132static float32x4_t VPCS_ATTR NOINLINE33specialcase (float32x4_t p, float32x4_t n, uint32x4_t e, const struct data *d)34{35/* 2^n may overflow, break it up into s1*s2. */36uint32x4_t b = vandq_u32 (vclezq_f32 (n), d->special_offset);37float32x4_t s1 = vreinterpretq_f32_u32 (vaddq_u32 (b, d->special_bias));38float32x4_t s2 = vreinterpretq_f32_u32 (vsubq_u32 (e, b));39uint32x4_t cmp = vcagtq_f32 (n, d->scale_thresh);40float32x4_t r1 = vmulq_f32 (s1, s1);41float32x4_t r0 = vmulq_f32 (vmulq_f32 (p, s1), s2);42return vreinterpretq_f32_u32 ((cmp & vreinterpretq_u32_f32 (r1))43| (~cmp & vreinterpretq_u32_f32 (r0)));44}4546float32x4_t VPCS_ATTR47_ZGVnN4v_exp2f_1u (float32x4_t x)48{49/* exp2(x) = 2^n * poly(r), with poly(r) in [1/sqrt(2),sqrt(2)]50x = n + r, with r in [-1/2, 1/2]. */51const struct data *d = ptr_barrier (&data);52float32x4_t n = vrndaq_f32 (x);53float32x4_t r = x - n;54uint32x4_t e = vreinterpretq_u32_s32 (vcvtaq_s32_f32 (x)) << 23;55float32x4_t scale = vreinterpretq_f32_u32 (e + d->exponent_bias);56uint32x4_t cmp = vcagtq_f32 (n, d->special_bound);5758float32x4_t p = vfmaq_f32 (d->c1, d->c0, r);59p = vfmaq_f32 (d->c2, p, r);60p = vfmaq_f32 (d->c3, p, r);61p = vfmaq_f32 (d->c4, p, r);62p = vfmaq_f32 (d->c5, p, r);63p = vfmaq_f32 (v_f32 (1.0f), p, r);64if (unlikely (v_any_u32 (cmp)))65return specialcase (p, n, e, d);66return scale * p;67}6869TEST_ULP (_ZGVnN4v_exp2f_1u, 0.4)70TEST_DISABLE_FENV (_ZGVnN4v_exp2f_1u)71TEST_INTERVAL (_ZGVnN4v_exp2f_1u, 0, 0xffff0000, 10000)72TEST_SYM_INTERVAL (_ZGVnN4v_exp2f_1u, 0x1p-14, 0x1p8, 500000)737475