VirtualBox

source: vbox/trunk/include/iprt/nocrt/amd64/fenv.h@ 76375

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

include/iprt/nocrt//fenv.h: Make recent gcc happy.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 7.4 KB
 
1/** @file
2 * IPRT / No-CRT - fenv.h, AMD64.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 * --------------------------------------------------------------------
25 *
26 * This code is based on:
27 *
28 * Copyright (c) 2004-2005 David Schultz <[email protected]>
29 * All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 */
52
53#ifndef ___iprt_nocrt_amd64_fenv_h
54#define ___iprt_nocrt_amd64_fenv_h
55
56#include <iprt/types.h>
57
58typedef struct {
59 struct {
60 uint32_t __control;
61 uint32_t __status;
62 uint32_t __tag;
63 char __other[16];
64 } __x87;
65 uint32_t __mxcsr;
66} fenv_t;
67
68typedef uint16_t fexcept_t;
69
70/* Exception flags */
71#define FE_INVALID 0x01
72#define FE_DENORMAL 0x02
73#define FE_DIVBYZERO 0x04
74#define FE_OVERFLOW 0x08
75#define FE_UNDERFLOW 0x10
76#define FE_INEXACT 0x20
77#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \
78 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
79
80/* Rounding modes */
81#define FE_TONEAREST 0x0000
82#define FE_DOWNWARD 0x0400
83#define FE_UPWARD 0x0800
84#define FE_TOWARDZERO 0x0c00
85#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
86 FE_UPWARD | FE_TOWARDZERO)
87
88/*
89 * As compared to the x87 control word, the SSE unit's control word
90 * has the rounding control bits offset by 3 and the exception mask
91 * bits offset by 7.
92 */
93#define _SSE_ROUND_SHIFT 3
94#define _SSE_EMASK_SHIFT 7
95
96RT_C_DECLS_BEGIN
97
98/* Default floating-point environment */
99extern const fenv_t RT_NOCRT(__fe_dfl_env);
100#define FE_DFL_ENV (&__fe_dfl_env)
101
102#define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw))
103#define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env))
104#define __fnclex() __asm __volatile("fnclex")
105#define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env)))
106#define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw)))
107#define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw)))
108#define __fwait() __asm __volatile("fwait")
109#define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr))
110#define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr)))
111
112#if RT_GNUC_PREREQ(4, 6)
113# pragma GCC diagnostic push
114# pragma GCC diagnostic ignored "-Wshadow"
115#endif
116
117DECLINLINE(int)
118feclearexcept(int __excepts)
119{
120 fenv_t __env;
121
122 if (__excepts == FE_ALL_EXCEPT) {
123 __fnclex();
124 } else {
125 __fnstenv(&__env.__x87);
126 __env.__x87.__status &= ~__excepts;
127 __fldenv(__env.__x87);
128 }
129 __stmxcsr(&__env.__mxcsr);
130 __env.__mxcsr &= ~__excepts;
131 __ldmxcsr(__env.__mxcsr);
132 return (0);
133}
134
135DECLINLINE(int)
136fegetexceptflag(fexcept_t *__flagp, int __excepts)
137{
138 int __mxcsr, __status;
139
140 __stmxcsr(&__mxcsr);
141 __fnstsw(&__status);
142 *__flagp = (__mxcsr | __status) & __excepts;
143 return (0);
144}
145
146int RT_NOCRT(fesetexceptflag)(const fexcept_t *__flagp, int __excepts);
147int RT_NOCRT(feraiseexcept)(int __excepts);
148
149DECLINLINE(int)
150fetestexcept(int __excepts)
151{
152 int __mxcsr, __status;
153
154 __stmxcsr(&__mxcsr);
155 __fnstsw(&__status);
156 return ((__status | __mxcsr) & __excepts);
157}
158
159DECLINLINE(int)
160fegetround(void)
161{
162 int __control;
163
164 /*
165 * We assume that the x87 and the SSE unit agree on the
166 * rounding mode. Reading the control word on the x87 turns
167 * out to be about 5 times faster than reading it on the SSE
168 * unit on an Opteron 244.
169 */
170 __fnstcw(&__control);
171 return (__control & _ROUND_MASK);
172}
173
174DECLINLINE(int)
175fesetround(int __round)
176{
177 int __mxcsr, __control;
178
179 if (__round & ~_ROUND_MASK)
180 return (-1);
181
182 __fnstcw(&__control);
183 __control &= ~_ROUND_MASK;
184 __control |= __round;
185 __fldcw(__control);
186
187 __stmxcsr(&__mxcsr);
188 __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT);
189 __mxcsr |= __round << _SSE_ROUND_SHIFT;
190 __ldmxcsr(__mxcsr);
191
192 return (0);
193}
194
195int RT_NOCRT(fegetenv)(fenv_t *__envp);
196int RT_NOCRT(feholdexcept)(fenv_t *__envp);
197
198DECLINLINE(int)
199fesetenv(const fenv_t *__envp)
200{
201
202 __fldenv(__envp->__x87);
203 __ldmxcsr(__envp->__mxcsr);
204 return (0);
205}
206
207int RT_NOCRT(feupdateenv)(const fenv_t *__envp);
208int RT_NOCRT(feenableexcept)(int __mask);
209int RT_NOCRT(fedisableexcept)(int __mask);
210
211DECLINLINE(int)
212fegetexcept(void)
213{
214 int __control;
215
216 /*
217 * We assume that the masks for the x87 and the SSE unit are
218 * the same.
219 */
220 __fnstcw(&__control);
221 return (~__control & FE_ALL_EXCEPT);
222}
223
224#if RT_GNUC_PREREQ(4, 6)
225# pragma GCC diagnostic pop
226#endif
227
228RT_C_DECLS_END
229
230#ifndef RT_WITHOUT_NOCRT_WRAPPERS
231# define fesetexceptflag RT_NOCRT(fesetexceptflag)
232# define feraiseexcept RT_NOCRT(feraiseexcept)
233# define fegetenv RT_NOCRT(fegetenv)
234# define feholdexcept RT_NOCRT(feholdexcept)
235# define feupdateenv RT_NOCRT(feupdateenv)
236# define feenableexcept RT_NOCRT(feenableexcept)
237# define fedisableexcept RT_NOCRT(fedisableexcept)
238# define __fe_dfl_env RT_NOCRT(__fe_dfl_env)
239#endif
240
241#endif /* !__iprt_nocrt_amd64_fenv_h__ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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