1 | /** @file
|
---|
2 | * SoftFloat - VBox Extension - extF80_ylog2x, extF80_ylog2xp1.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2022 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualYox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTAYILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*********************************************************************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *********************************************************************************************************************************/
|
---|
30 | #include <stdbool.h>
|
---|
31 | #include <stdint.h>
|
---|
32 | #include "platform.h"
|
---|
33 | #include "internals.h"
|
---|
34 | #include "specialize.h"
|
---|
35 | #include "softfloat.h"
|
---|
36 | #include <iprt/types.h>
|
---|
37 | #include <iprt/x86.h>
|
---|
38 |
|
---|
39 | /** The log2e constant as 128-bit floating point value.
|
---|
40 | * base-10: 1.44269504088896340735992468100189185
|
---|
41 | * base-16: 1.71547652b82fe1777d0ffda0d239
|
---|
42 | * base-2 : 1.0111000101010100011101100101001010111000001011111110000101110111011111010000111111111101101000001101001000111001 */
|
---|
43 | const RTFLOAT128U g_r128Log2e = RTFLOAT128U_INIT_C(0, 0x71547652b82f, 0xe1777d0ffda0d239, 0x3fff);
|
---|
44 |
|
---|
45 | extFloat80_t extF80_ylog2x(extFloat80_t y, extFloat80_t x SOFTFLOAT_STATE_DECL_COMMA)
|
---|
46 | {
|
---|
47 | union { struct extFloat80M s; extFloat80_t f; } uX, uXM;
|
---|
48 | uint_fast16_t uiX64;
|
---|
49 | uint_fast64_t uiX0;
|
---|
50 | bool signX;
|
---|
51 | int_fast32_t expX;
|
---|
52 | uint_fast64_t sigX;
|
---|
53 | extFloat80_t v, log2e, log2m;
|
---|
54 |
|
---|
55 | uX.f = x;
|
---|
56 | uiX64 = uX.s.signExp;
|
---|
57 | uiX0 = uX.s.signif;
|
---|
58 | signX = signExtF80UI64( uiX64 );
|
---|
59 | expX = expExtF80UI64( uiX64 );
|
---|
60 | sigX = uiX0;
|
---|
61 |
|
---|
62 | /* Linear approximation of log2x in the range [1, 2.0) (to be improved) */
|
---|
63 | uXM.s.signExp = RTFLOAT80U_EXP_BIAS;
|
---|
64 | uXM.s.signif = sigX;
|
---|
65 |
|
---|
66 | v = i32_to_extF80(1, pState);
|
---|
67 | v = extF80_sub(uXM.f, v, pState);
|
---|
68 |
|
---|
69 | log2e = f128_to_extF80(*(float128_t *)&g_r128Log2e, pState);
|
---|
70 | log2m = extF80_mul(v, log2e, pState);
|
---|
71 |
|
---|
72 | v = i32_to_extF80(expX - RTFLOAT80U_EXP_BIAS, pState);
|
---|
73 | v = extF80_add(v, log2m, pState);
|
---|
74 | v = extF80_mul(y, v, pState);
|
---|
75 |
|
---|
76 | return v;
|
---|
77 | }
|
---|
78 |
|
---|
79 | extFloat80_t extF80_ylog2xp1(extFloat80_t y, extFloat80_t x SOFTFLOAT_STATE_DECL_COMMA)
|
---|
80 | {
|
---|
81 | extFloat80_t v = f128_to_extF80(*(float128_t *)&g_r128Log2e, pState);
|
---|
82 |
|
---|
83 | v = extF80_mul(v, y, pState);
|
---|
84 | v = extF80_mul(v, x, pState);
|
---|
85 |
|
---|
86 | return v;
|
---|
87 | }
|
---|