VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/math/exp2f.asm

Last change on this file was 106061, checked in by vboxsync, 8 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1; $Id: exp2f.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; IPRT - No-CRT exp2f - AMD64 & X86.
4;
5
6;
7; Copyright (C) 2022-2024 Oracle and/or its affiliates.
8;
9; This file is part of VirtualBox base platform packages, as
10; available from https://www.virtualbox.org.
11;
12; This program is free software; you can redistribute it and/or
13; modify it under the terms of the GNU General Public License
14; as published by the Free Software Foundation, in version 3 of the
15; License.
16;
17; This program is distributed in the hope that it will be useful, but
18; WITHOUT ANY WARRANTY; without even the implied warranty of
19; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20; General Public License for more details.
21;
22; You should have received a copy of the GNU General Public License
23; along with this program; if not, see <https://www.gnu.org/licenses>.
24;
25; The contents of this file may alternatively be used under the terms
26; of the Common Development and Distribution License Version 1.0
27; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28; in the VirtualBox distribution, in which case the provisions of the
29; CDDL are applicable instead of those of the GPL.
30;
31; You may elect to license modified versions of this file under the
32; terms and conditions of either the GPL or the CDDL or both.
33;
34; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35;
36
37
38%define RT_ASM_WITH_SEH64
39%include "iprt/asmdefs.mac"
40%include "iprt/x86.mac"
41
42BEGINCODE
43
44;;
45; Calculate two to the power of @a r32.
46;
47; @returns st(0) / xmm0
48; @param r32 [rbp + 8] / xmm0
49RT_NOCRT_BEGINPROC exp2f
50 push xBP
51 SEH64_PUSH_xBP
52 mov xBP, xSP
53 SEH64_SET_FRAME_xBP 0
54%ifdef RT_ARCH_AMD64
55 sub xSP, 10h
56 SEH64_ALLOCATE_STACK 10h
57%endif
58 SEH64_END_PROLOGUE
59
60 ;
61 ; Load the value into st(0).
62 ;
63%ifdef RT_ARCH_AMD64
64 movss [xSP], xmm0
65 fld dword [xSP]
66%else
67 fld dword [xBP + xCB*2]
68%endif
69
70 ;
71 ; Return immediately if NaN or infinity.
72 ;
73 fxam
74 fstsw ax
75 test ax, X86_FSW_C0 ; C0 is set for NaN, Infinity and Empty register. The latter is not the case.
76 jz .input_ok
77%ifdef RT_ARCH_AMD64
78 ffreep st0 ; return the xmm0 register value unchanged, as FLD changes SNaN to QNaN.
79%endif
80 test ax, X86_FSW_C2 ; C2 is clear for NaN (and Empty) but set for Infinity.
81 jz .return_val2
82 test ax, X86_FSW_C1 ; C1 = sign bit
83 jz .return_val2 ; Not sign, return +Inf.
84%ifndef RT_ARCH_AMD64
85 ffreep st0
86%endif
87 fldz ; Signed, so return zero as that's a good approximation for 2**-Inf.
88 jmp .return_val
89.input_ok:
90
91 ;
92 ; Split the job in two on the fraction and integer input parts.
93 ;
94 fld st0 ; Push a copy of the input on the stack.
95 frndint ; st0 = (int)input
96 fsub st1, st0 ; st1 = input - (int)input; i.e. st1 = fraction, st0 = integer.
97 fxch ; st0 = fraction, st1 = integer.
98
99 ; 1. Calculate on the fraction.
100 f2xm1 ; st0 = 2**fraction - 1.0
101 fld1
102 faddp ; st0 = 2**fraction
103
104 ; 2. Apply the integer power of two.
105 fscale ; st0 = result; st1 = integer part of input.
106 fstp st1 ; st0 = result; no st1.
107
108.return_val:
109%ifdef RT_ARCH_AMD64
110 fstp dword [xSP]
111 movss xmm0, [xSP]
112%endif
113.return_val2:
114 leave
115 ret
116ENDPROC RT_NOCRT(exp2f)
117
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