VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/extF80_tan.c@ 105770

Last change on this file since 105770 was 97234, checked in by vboxsync, 2 years ago

VMM/IEM: Rough implementation for fptan instruction in SoftFloat library, bugref:9898

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1/** @file
2 * SoftFloat - VBox Extension - extF80_tan.
3 */
4
5/*
6 * Copyright (C) 2022 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox 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 * MERCHANTABILITY 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/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <stdbool.h>
32#include <stdint.h>
33#include "platform.h"
34#include "internals.h"
35#include "specialize.h"
36#include "softfloat.h"
37#include <iprt/types.h>
38#include <iprt/x86.h>
39
40extern const RTFLOAT128U g_r128pi2;
41
42extFloat80_t extF80_tan( extFloat80_t x SOFTFLOAT_STATE_DECL_COMMA )
43{
44 int32_t fSign = 0;
45 extFloat80_t v, f80Zero, f80One, f80Pi2;
46
47 f80Zero = ui32_to_extF80(0, pState);
48 f80One = ui32_to_extF80(1, pState);
49 f80Pi2 = f128_to_extF80(*(float128_t *)&g_r128pi2, pState);
50
51 if (extF80_le(x, f80Zero, pState))
52 {
53 x = extF80_sub(f80Zero, x, pState);
54 fSign = 1;
55 }
56
57 uint16_t fCxFlags = 0;
58 extFloat80_t rem = extF80_partialRem(x, f80Pi2, pState->roundingMode, &fCxFlags, pState);
59 int32_t const quo = X86_FSW_CX_TO_QUOTIENT(fCxFlags);
60
61 v = extF80_div(rem, f80Pi2, pState);
62 v = extF80_mul(v, v, pState);
63 v = extF80_sub(f80One, v, pState);
64 v = extF80_div(rem, v, pState);
65
66 if (quo % 2)
67 {
68 v = extF80_div(f80One, v, pState);
69 v = extF80_sub(f80Zero, v, pState);
70 }
71
72 if (fSign)
73 v = extF80_sub(f80Zero, v, pState);
74
75 return v;
76}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette