1*f3087befSAndrew Turner /*
2*f3087befSAndrew Turner * Single-precision vector log function - inline version
3*f3087befSAndrew Turner *
4*f3087befSAndrew Turner * Copyright (c) 2024, Arm Limited.
5*f3087befSAndrew Turner * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6*f3087befSAndrew Turner */
7*f3087befSAndrew Turner
8*f3087befSAndrew Turner #include "sv_math.h"
9*f3087befSAndrew Turner
10*f3087befSAndrew Turner struct sv_logf_data
11*f3087befSAndrew Turner {
12*f3087befSAndrew Turner float p1, p3, p5, p6, p0, p2, p4;
13*f3087befSAndrew Turner float ln2;
14*f3087befSAndrew Turner uint32_t off, mantissa_mask;
15*f3087befSAndrew Turner };
16*f3087befSAndrew Turner
17*f3087befSAndrew Turner #define SV_LOGF_CONSTANTS \
18*f3087befSAndrew Turner { \
19*f3087befSAndrew Turner .p0 = -0x1.ffffc8p-2f, .p1 = 0x1.555d7cp-2f, .p2 = -0x1.00187cp-2f, \
20*f3087befSAndrew Turner .p3 = 0x1.961348p-3f, .p4 = -0x1.4f9934p-3f, .p5 = 0x1.5a9aa2p-3f, \
21*f3087befSAndrew Turner .p6 = -0x1.3e737cp-3f, .ln2 = 0x1.62e43p-1f, .off = 0x3f2aaaab, \
22*f3087befSAndrew Turner .mantissa_mask = 0x007fffff \
23*f3087befSAndrew Turner }
24*f3087befSAndrew Turner
25*f3087befSAndrew Turner static inline svfloat32_t
sv_logf_inline(svbool_t pg,svfloat32_t x,const struct sv_logf_data * d)26*f3087befSAndrew Turner sv_logf_inline (svbool_t pg, svfloat32_t x, const struct sv_logf_data *d)
27*f3087befSAndrew Turner {
28*f3087befSAndrew Turner svuint32_t u = svreinterpret_u32 (x);
29*f3087befSAndrew Turner
30*f3087befSAndrew Turner /* x = 2^n * (1+r), where 2/3 < 1+r < 4/3. */
31*f3087befSAndrew Turner u = svsub_x (pg, u, d->off);
32*f3087befSAndrew Turner svfloat32_t n = svcvt_f32_s32_x (
33*f3087befSAndrew Turner pg, svasr_x (pg, svreinterpret_s32_u32 (u), 23)); /* signextend. */
34*f3087befSAndrew Turner u = svand_x (pg, u, d->mantissa_mask);
35*f3087befSAndrew Turner u = svadd_x (pg, u, d->off);
36*f3087befSAndrew Turner svfloat32_t r = svsub_x (pg, svreinterpret_f32 (u), 1.0f);
37*f3087befSAndrew Turner
38*f3087befSAndrew Turner /* y = log(1+r) + n*ln2. */
39*f3087befSAndrew Turner svfloat32_t r2 = svmul_x (pg, r, r);
40*f3087befSAndrew Turner /* n*ln2 + r + r2*(P1 + r*P2 + r2*(P3 + r*P4 + r2*(P5 + r*P6 + r2*P7))). */
41*f3087befSAndrew Turner svfloat32_t p1356 = svld1rq_f32 (svptrue_b32 (), &d->p1);
42*f3087befSAndrew Turner svfloat32_t p = svmla_lane (sv_f32 (d->p4), r, p1356, 2);
43*f3087befSAndrew Turner svfloat32_t q = svmla_lane (sv_f32 (d->p2), r, p1356, 1);
44*f3087befSAndrew Turner svfloat32_t y = svmla_lane (sv_f32 (d->p0), r, p1356, 0);
45*f3087befSAndrew Turner p = svmla_lane (p, r2, p1356, 3);
46*f3087befSAndrew Turner q = svmla_x (pg, q, p, r2);
47*f3087befSAndrew Turner y = svmla_x (pg, y, q, r2);
48*f3087befSAndrew Turner p = svmla_x (pg, r, n, d->ln2);
49*f3087befSAndrew Turner
50*f3087befSAndrew Turner return svmla_x (pg, p, y, r2);
51*f3087befSAndrew Turner }
52