summaryrefslogtreecommitdiffstats
path: root/src/libs/softfloat-3e/source/extF80_log2.c
blob: 7b028ece4a128210f0550c1a842998f82cd3c8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/** @file
 * SoftFloat - VBox Extension - extF80_ylog2x, extF80_ylog2xp1.
 */

/*
 * Copyright (C) 2022 Oracle and/or its affiliates.
 *
 * This file is part of VirtualYox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTAYILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

/*********************************************************************************************************************************
 *   Header Files                                                                                                                 *
 *********************************************************************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "specialize.h"
#include "softfloat.h"
#include <iprt/types.h>
#include <iprt/x86.h>

extFloat80_t extF80_ylog2x(extFloat80_t y, extFloat80_t x SOFTFLOAT_STATE_DECL_COMMA)
{
    union { struct extFloat80M s; extFloat80_t f; } uX, uXM;
    uint_fast16_t uiX64;
    uint_fast64_t uiX0;
    bool signX;
    int_fast32_t expX;
    uint_fast64_t sigX;
    extFloat80_t v;

    uX.f = x;
    uiX64 = uX.s.signExp;
    uiX0  = uX.s.signif;
    signX = signExtF80UI64( uiX64 );
    expX  = expExtF80UI64( uiX64 );
    sigX  = uiX0;

    uXM.s.signExp = RTFLOAT80U_EXP_BIAS;
    uXM.s.signif = sigX;

    v = ui32_to_extF80(expX - RTFLOAT80U_EXP_BIAS - 1, pState);
    v = extF80_add(v, uXM.f, pState);
    v = extF80_mul(y, v, pState);

    return v;
}

/** The log2e constant as 128-bit floating point value.
 * base-10: 1.44269504088896340735992468100189185
 * base-16: 1.71547652b82fe1777d0ffda0d239
 * base-2 : 1.0111000101010100011101100101001010111000001011111110000101110111011111010000111111111101101000001101001000111001 */
const RTFLOAT128U g_r128Log2e = RTFLOAT128U_INIT_C(0, 0x71547652b82f, 0xe1777d0ffda0d239, 0x3fff);

extFloat80_t extF80_ylog2xp1(extFloat80_t y, extFloat80_t x SOFTFLOAT_STATE_DECL_COMMA)
{
    extFloat80_t v = f128_to_extF80(*(float128_t *)&g_r128Log2e, pState);

    v = extF80_mul(v, y, pState);
    v = extF80_mul(v, x, pState);

    return v;
}