VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 3 months 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.4 KB
Line 
1; $Id: feclearexcept.asm 106061 2024-09-16 14:03:52Z vboxsync $
2;; @file
3; IPRT - No-CRT feclearexcept - 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
42
43BEGINCODE
44
45;;
46; Sets the hardware rounding mode.
47;
48; @returns eax = 0 on success, non-zero on failure.
49; @param fXcpts 32-bit: [xBP+8]; msc64: ecx; gcc64: edi; -- Zero or more bits from X86_FSW_XCPT_MASK
50;
51RT_NOCRT_BEGINPROC feclearexcept
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 parameter into ecx, validate and adjust it.
62 ;
63%ifdef ASM_CALL64_GCC
64 mov ecx, edi
65%elifdef RT_ARCH_X86
66 mov ecx, [xBP + xCB*2]
67%endif
68%if 0
69 and ecx, X86_FSW_XCPT_MASK
70%else
71 or eax, -1
72 test ecx, ~X86_FSW_XCPT_MASK
73 jnz .return
74%endif
75
76 ; #IE implies #SF
77 mov al, cl
78 and al, X86_FSW_IE
79 shl al, X86_FSW_SF_BIT - X86_FSW_IE_BIT
80 or cl, al
81
82 ; Make it into and AND mask suitable for clearing the specified exceptions.
83 not ecx
84
85 ;
86 ; Make the changes.
87 ;
88
89 ; Modify the x87 flags first (ecx preserved).
90 cmp ecx, ~X86_FSW_XCPT_MASK ; This includes all the x87 exceptions, including stack error.
91 jne .partial_mask
92 fnclex
93 jmp .do_sse
94
95.partial_mask:
96 fnstenv [xBP - 20h]
97 and word [xBP - 20h + 4], cx ; The FCW is at offset 4 in the 32-bit prot mode layout
98 fldenv [xBP - 20h] ; Recalculates the FSW.ES flag.
99.do_sse:
100
101%ifdef RT_ARCH_X86
102 ; SSE supported (ecx preserved)?
103 extern NAME(rtNoCrtHasSse)
104 call NAME(rtNoCrtHasSse)
105 test al, al
106 jz .return_ok
107%endif
108
109 ; Modify the SSE flags (modifies ecx).
110 stmxcsr [xBP - 10h]
111 or ecx, X86_FSW_XCPT_MASK & ~X86_MXCSR_XCPT_FLAGS ; Don't mix X86_FSW_SF with X86_MXCSR_DAZ.
112 and [xBP - 10h], ecx
113 ldmxcsr [xBP - 10h]
114
115.return_ok:
116 xor eax, eax
117.return:
118 leave
119 ret
120ENDPROC RT_NOCRT(feclearexcept)
121
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