VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/math/fesetenv.asm@ 96205

最後變更 在這個檔案從96205是 96205,由 vboxsync 提交於 3 年 前

IPRT/nocrt: Implemented x86 and amd64 fenv.h to assist with the testing. More tests. bugref:10261

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.0 KB
 
1; $Id: fesetenv.asm 96205 2022-08-14 23:40:55Z vboxsync $
2;; @file
3; IPRT - No-CRT fesetenv - AMD64 & X86.
4;
5
6;
7; Copyright (C) 2022 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.alldomusa.eu.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; The contents of this file may alternatively be used under the terms
18; of the Common Development and Distribution License Version 1.0
19; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20; VirtualBox OSE distribution, in which case the provisions of the
21; CDDL are applicable instead of those of the GPL.
22;
23; You may elect to license modified versions of this file under the
24; terms and conditions of either the GPL or the CDDL or both.
25;
26
27
28%define RT_ASM_WITH_SEH64
29%include "iprt/asmdefs.mac"
30%include "iprt/x86.mac"
31
32%define RT_NOCRT_FE_DFL_ENV 1
33%define RT_NOCRT_FE_NOMASK_ENV 2
34
35
36BEGINCODE
37
38;;
39; Sets the FPU+SSE environment.
40;
41; @returns eax = 0 on success, -1 on failure.
42; @param pEnv 32-bit: [xBP+8] msc64: rcx gcc64: rdi - Saved environment to restore.
43;
44RT_NOCRT_BEGINPROC fesetenv
45 push xBP
46 SEH64_PUSH_xBP
47 mov xBP, xSP
48 SEH64_SET_FRAME_xBP 0
49 sub xBP, 20h
50 SEH64_ALLOCATE_STACK 20h
51 SEH64_END_PROLOGUE
52
53 ;
54 ; Load the parameter into rcx.
55 ;
56%ifdef ASM_CALL64_GCC
57 mov rcx, rdi
58%elifdef RT_ARCH_X86
59 mov ecx, [xBP + xCB*2]
60%endif
61
62 ;
63 ; For the x87 state we only set FSW.XCPT, FCW.XCPT, FCW.RC and FCW.PC.
64 ; So we save the current environment, merge those fields and load it.
65 ;
66 fnstenv [xBP - 20h]
67
68 cmp xCX, RT_NOCRT_FE_DFL_ENV
69 je .x87_default_env
70 cmp xCX, RT_NOCRT_FE_NOMASK_ENV
71 je .x87_default_nomask_env
72 jmp .x87_regular
73
74.x87_default_env:
75 and word [xCX + X86FSTENV32P.FCW], ~(X86_FCW_MASK_ALL | X86_FCW_PC_MASK | X86_FCW_RC_MASK | X86_FCW_IC_MASK)
76 or word [xCX + X86FSTENV32P.FCW], X86_FCW_MASK_ALL | X86_FCW_PC_64 | X86_FCW_RC_NEAREST | X86_FCW_IC_PROJECTIVE
77 and word [xCX + X86FSTENV32P.FSW], ~X86_FSW_XCPT_ES_MASK
78 jmp .x87_common
79
80.x87_default_nomask_env:
81 and word [xCX + X86FSTENV32P.FCW], ~(X86_FCW_MASK_ALL | X86_FCW_PC_MASK | X86_FCW_RC_MASK | X86_FCW_IC_MASK)
82 or word [xCX + X86FSTENV32P.FCW], X86_FCW_DM | X86_FCW_PC_64 | X86_FCW_RC_NEAREST | X86_FCW_IC_PROJECTIVE
83 and word [xCX + X86FSTENV32P.FSW], ~X86_FSW_XCPT_ES_MASK
84 jmp .x87_common
85
86.x87_regular:
87 ; FCW:
88 mov ax, [xCX + X86FSTENV32P.FCW]
89 mov dx, [xBP - 20h + X86FSTENV32P.FCW]
90 and ax, X86_FCW_MASK_ALL | X86_FCW_RC_MASK | X86_FCW_PC_MASK
91 and dx, ~(X86_FCW_MASK_ALL | X86_FCW_RC_MASK | X86_FCW_PC_MASK)
92 or dx, ax
93 mov [xBP - 20h + X86FSTENV32P.FCW], dx
94 ; FSW
95 mov ax, [xCX + X86FSTENV32P.FSW]
96 mov dx, [xBP - 20h + X86FSTENV32P.FSW]
97 and ax, X86_FSW_XCPT_MASK
98 and dx, ~(X86_FSW_XCPT_MASK)
99 or dx, ax
100 mov [xBP - 20h + X86FSTENV32P.FSW], dx
101
102.x87_common:
103 ; Clear the exception info.
104 xor eax, eax
105 mov [xBP - 20h + X86FSTENV32P.FPUIP], eax
106 mov [xBP - 20h + X86FSTENV32P.FPUCS], eax ; covers FOP too.
107 mov [xBP - 20h + X86FSTENV32P.FPUDP], eax
108 mov [xBP - 20h + X86FSTENV32P.FPUDS], eax
109
110 ; Load the merged and cleaned up environment.
111 fldenv [xBP - 20h]
112
113 ;
114 ; Now for SSE, if supported, where we'll restore everything as is.
115 ;
116%ifdef RT_ARCH_X86
117 ; SSE supported (ecx preserved)?
118 extern NAME(rtNoCrtHasSse)
119 call NAME(rtNoCrtHasSse)
120 test al, al
121 jz .return_okay
122%endif
123
124 cmp xCX, RT_NOCRT_FE_DFL_ENV
125 je .sse_special_env
126 cmp xCX, RT_NOCRT_FE_NOMASK_ENV
127 je .sse_special_env
128 ldmxcsr [xCX + 28]
129 jmp .return_okay
130
131.sse_special_env:
132 stmxcsr [xBP - 10h]
133 mov eax, [xBP - 10h]
134 and eax, ~(X86_MXCSR_XCPT_FLAGS | X86_MXCSR_XCPT_MASK | X86_MXCSR_RC_MASK | X86_MXCSR_DAZ | X86_MXCSR_FZ)
135 or eax, X86_MXCSR_RC_NEAREST | X86_MXCSR_DM
136 cmp xCX, RT_NOCRT_FE_NOMASK_ENV
137 je .sse_special_load_eax
138 or eax, X86_MXCSR_RC_NEAREST | X86_MXCSR_XCPT_MASK ; default enviornment masks all exceptions
139.sse_special_load_eax:
140 mov [xBP - 10h], eax
141 ldmxcsr [xBP - 10h]
142
143 ;
144 ; Return success.
145 ;
146.return_okay:
147 xor eax, eax
148 leave
149 ret
150ENDPROC RT_NOCRT(fesetenv)
151
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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