VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/math/exp.asm@ 100249

Last change on this file since 100249 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1; $Id: exp.asm 98103 2023-01-17 14:15:46Z vboxsync $
2;; @file
3; IPRT - No-CRT exp - AMD64 & X86.
4;
5
6;
7; Copyright (C) 2006-2023 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
42
43BEGINCODE
44
45extern NAME(RT_NOCRT(feraiseexcept))
46
47;;
48; Compute the e (2.7182818...) to the power of rd.
49; @returns st(0) / xmm0
50; @param rd [xSP + xCB*2] / xmm0
51RT_NOCRT_BEGINPROC exp
52 push xBP
53 SEH64_PUSH_xBP
54 mov xBP, xSP
55 SEH64_SET_FRAME_xBP 0
56 sub xSP, 20h
57 SEH64_ALLOCATE_STACK 20h
58 SEH64_END_PROLOGUE
59
60 ;
61 ; Load the input into st0.
62 ;
63%ifdef RT_ARCH_AMD64
64 movsd [xBP - 10h], xmm0
65 fld qword [xBP - 10h]
66%else
67 fld qword [xBP + xCB*2]
68%endif
69
70 ;
71 ; Weed out non-normal values.
72 ;
73 fxam
74 fnstsw ax
75 mov cx, ax
76 and ax, X86_FSW_C3 | X86_FSW_C2 | X86_FSW_C0
77 cmp ax, X86_FSW_C2 ; Normal finite number (excluding zero)
78 je .finite
79 cmp ax, X86_FSW_C3 ; Zero
80 je .zero
81 cmp ax, X86_FSW_C3 | X86_FSW_C2 ; Denormals
82 je .finite
83 cmp ax, X86_FSW_C0 | X86_FSW_C2 ; Infinity.
84 je .inf
85 jmp .nan
86
87.finite:
88 ;
89 ; Convert to power of 2 and it'll be the same as exp2.
90 ;
91 fldl2e ; -> st0=log2(e); st1=input
92 fmulp ; -> st0=input*log2(e)
93
94 ;
95 ; Split the job in two on the fraction and integer input parts.
96 ;
97 fld st0 ; Push a copy of the input on the stack.
98 frndint ; st0 = (int)(input*log2(e))
99 fsub st1, st0 ; st1 = input*log2(e) - (int)input*log2(e); i.e. st1 = fraction, st0 = integer.
100 fxch ; st0 = fraction, st1 = integer.
101
102 ; 1. Calculate on the fraction.
103 f2xm1 ; st0 = 2**fraction - 1.0
104 fld1
105 faddp ; st0 = 2**fraction
106
107 ; 2. Apply the integer power of two.
108 fscale ; st0 = result; st1 = integer part of input.
109 fstp st1 ; st0 = result; no st1.
110
111 ;
112 ; Return st0.
113 ;
114.return_val:
115%ifdef RT_ARCH_AMD64
116 fstp qword [xBP - 10h]
117 movsd xmm0, [xBP - 10h]
118%endif
119.return:
120 leave
121 ret
122
123 ;
124 ; +/-0.0: Return +1.0
125 ;
126.zero:
127 ffreep st0
128 fld1
129 jmp .return_val
130
131 ;
132 ; -Inf: Return +0.0.
133 ; +Inf: Return +Inf. Join path with NaN.
134 ;
135.inf:
136 test cx, X86_FSW_C1 ; sign bit
137 jz .nan
138 ffreep st0
139 fldz
140 jmp .return_val
141
142 ;
143 ; NaN: Return the input NaN value as is, if we can.
144 ;
145.nan:
146%ifdef RT_ARCH_AMD64
147 ffreep st0
148%endif
149 jmp .return
150ENDPROC RT_NOCRT(exp)
151
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