Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
glibc
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security
Insights
Files
bd37f2e
abilist
argp
assert
bits
catgets
conf
conform
crypt
csu
ctype
debug
dirent
dlfcn
elf
gmon
gnulib
grp
gshadow
hesiod
hurd
iconv
iconvdata
include
inet
intl
io
libidn
libio
locale
localedata
login
mach
malloc
manual
math
misc
nis
nptl
nptl_db
nscd
nss
po
posix
pwd
resolv
resource
rt
scripts
setjmp
shadow
signal
socket
soft-fp
stdio-common
stdlib
streams
string
sunrpc
sysdeps
generic
gnu
i386
bits
elf
fpu
bits
Makefile
Versions
doasin.c
e_acos.S
e_acosf.S
e_acosh.S
e_acoshf.S
e_acoshl.S
e_acosl.c
e_asin.S
e_asinf.S
e_atan2.S
e_atan2f.S
e_atan2l.c
e_atanh.S
e_atanhf.S
e_atanhl.S
e_exp.S
e_exp10.S
e_exp10f.S
e_exp10l.S
e_exp2.S
e_exp2f.S
e_exp2l.S
e_expf.S
e_expl.c
e_fmod.S
e_fmodf.S
e_fmodl.c
e_hypot.S
e_hypotf.S
e_log.S
e_log10.S
e_log10f.S
e_log10l.S
e_log2.S
e_log2f.S
e_log2l.S
e_logf.S
e_logl.S
e_pow.S
e_powf.S
e_powl.S
e_rem_pio2.c
e_remainder.S
e_remainderf.S
e_remainderl.S
e_scalb.S
e_scalbf.S
e_scalbl.S
e_sqrt.S
e_sqrtf.S
e_sqrtl.c
fclrexcpt.c
fedisblxcpt.c
feenablxcpt.c
fegetenv.c
fegetexcept.c
fegetround.c
feholdexcpt.c
fenv_private.h
fesetenv.c
fesetround.c
feupdateenv.c
fgetexcptflg.c
fraiseexcpt.c
fsetexcptflg.c
ftestexcept.c
halfulp.c
k_rem_pio2l.c
libm-test-ulps
math_private.h
mpatan.c
mpatan2.c
mpexp.c
mplog.c
mpsqrt.c
s_asinh.S
s_asinhf.S
s_asinhl.S
s_atan.S
s_atanf.S
s_atanl.c
s_cbrt.S
s_cbrtf.S
s_cbrtl.S
s_ceil.S
s_ceilf.S
s_ceill.S
s_cexp.S
s_cexpf.S
s_cexpl.S
s_copysign.S
s_copysignf.S
s_copysignl.S
s_expm1.S
s_expm1f.S
s_expm1l.S
s_fabs.S
s_fabsf.S
s_fabsl.S
s_fdim.S
s_fdimf.S
s_fdiml.S
s_finite.S
s_finitef.S
s_finitel.S
s_floor.S
s_floorf.S
s_floorl.S
s_fmax.S
s_fmaxf.S
s_fmaxl.S
s_fmin.S
s_fminf.S
s_fminl.S
s_fpclassifyl.c
s_frexp.S
s_frexpf.S
s_frexpl.S
s_ilogb.S
s_ilogbf.S
s_ilogbl.S
s_isinfl.c
s_isnanl.c
s_llrint.S
s_llrintf.S
s_llrintl.S
s_log1p.S
s_log1pf.S
s_log1pl.S
s_logb.S
s_logbf.S
s_logbl.c
s_lrint.S
s_lrintf.S
s_lrintl.S
s_nearbyint.S
s_nearbyintf.S
s_nearbyintl.S
s_nextafterl.c
s_nexttoward.c
s_nexttowardf.c
s_remquo.S
s_remquof.S
s_remquol.S
s_rint.S
s_rintf.S
s_rintl.c
s_scalbln.c
s_scalblnf.c
s_scalblnl.c
s_scalbn.S
s_scalbnf.S
s_scalbnl.S
s_significand.S
s_significandf.S
s_significandl.c
s_trunc.S
s_truncf.S
s_truncl.S
slowexp.c
slowpow.c
t_exp.c
i486
i586
i686
i786
sys
Implies
Makefile
Versions
____longjmp_chk.S
__longjmp.S
abort-instr.h
add_n.S
addmul_1.S
asm-syntax.h
backtrace.c
bp-asm.h
bsd-_setjmp.S
bsd-setjmp.S
bzero.c
configure
configure.in
crti.S
crtn.S
dl-irel.h
dl-lookupcfg.h
dl-machine.h
dl-procinfo.c
dl-procinfo.h
dl-tls.h
dl-tlsdesc.S
dl-tlsdesc.h
dl-trampoline.S
ffs.c
fpu_control.h
gccframe.h
gmp-mparam.h
htonl.S
htons.S
i386-mcount.S
init-first.c
jmpbuf-offsets.h
jmpbuf-unwind.h
ldbl2mpn.c
lshift.S
machine-gmon.h
memchr.S
memcmp.S
memcopy.h
memset.c
memusage.h
mp_clz_tab.c
mul_1.S
rawmemchr.S
rshift.S
setfpucw.c
setjmp.S
stackinfo.h
stpcpy.S
stpncpy.S
strchr.S
strchrnul.S
strcspn.S
string-inlines.c
strlen.c
strpbrk.S
strrchr.S
strspn.S
strtok.S
strtok_r.S
sub_n.S
submul_1.S
sysdep.h
tlsdesc.c
tlsdesc.sym
tst-stack-align.h
ieee754
mach
posix
powerpc
pthread
s390
sh
sparc
unix
wordsize-32
wordsize-64
x86_64
sysvipc
termios
time
timezone
wcsmbs
wctype
.gitattributes
.gitignore
BUGS
CANCEL-FCT-WAIVE
CANCEL-FILE-WAIVE
CONFORMANCE
COPYING
COPYING.LIB
ChangeLog
ChangeLog.1
ChangeLog.10
ChangeLog.11
ChangeLog.12
ChangeLog.13
ChangeLog.14
ChangeLog.15
ChangeLog.16
ChangeLog.17
ChangeLog.2
ChangeLog.3
ChangeLog.4
ChangeLog.5
ChangeLog.6
ChangeLog.7
ChangeLog.8
ChangeLog.9
FAQ
FAQ.in
INSTALL
LICENSES
Makeconfig
Makefile
Makefile.in
Makerules
NAMESPACE
NEWS
NOTES
PROJECTS
README
README.libm
Rules
Versions.def
WUR-REPORT
abi-tags
aclocal.m4
config.h.in
config.make.in
configure
configure.in
cppflags-iterator.mk
extra-lib.mk
extra-modules.mk
libc-abis
o-iterator.mk
shlib-versions
test-skeleton.c
version.h
Breadcrumbs
glibc
/
sysdeps
/
i386
/
fpu
/
fenv_private.h
Blame
Blame
Latest commit
History
History
304 lines (263 loc) · 8.44 KB
Breadcrumbs
glibc
/
sysdeps
/
i386
/
fpu
/
fenv_private.h
Top
File metadata and controls
Code
Blame
304 lines (263 loc) · 8.44 KB
Raw
#ifndef FENV_PRIVATE_H #define FENV_PRIVATE_H 1 #include <fenv.h> #include <fpu_control.h> #ifdef __SSE2_MATH__ # define math_opt_barrier(x) \ ({ __typeof(x) __x; \ if (sizeof (x) <= sizeof (double)) \ __asm ("" : "=x" (__x) : "0" (x)); \ else \ __asm ("" : "=t" (__x) : "0" (x)); \ __x; }) # define math_force_eval(x) \ do { \ if (sizeof (x) <= sizeof (double)) \ __asm __volatile ("" : : "x" (x)); \ else \ __asm __volatile ("" : : "f" (x)); \ } while (0) #else # define math_opt_barrier(x) \ ({ __typeof (x) __x; \ __asm ("" : "=t" (__x) : "0" (x)); \ __x; }) # define math_force_eval(x) \ do { \ __typeof (x) __x = (x); \ if (sizeof (x) <= sizeof (double)) \ __asm __volatile ("" : : "m" (__x)); \ else \ __asm __volatile ("" : : "f" (__x)); \ } while (0) #endif /* This file is used by both the 32- and 64-bit ports. The 64-bit port has a field in the fenv_t for the mxcsr; the 32-bit port does not. Instead, we (ab)use the only 32-bit field extant in the struct. */ #ifndef __x86_64__ # define __mxcsr __eip #endif /* All of these functions are private to libm, and are all used in pairs to save+change the fp state and restore the original state. Thus we need not care for both the 387 and the sse unit, only the one we're actually using. */ #if defined __AVX__ || defined SSE2AVX # define STMXCSR "vstmxcsr" # define LDMXCSR "vldmxcsr" #else # define STMXCSR "stmxcsr" # define LDMXCSR "ldmxcsr" #endif static __always_inline void libc_feholdexcept_sse (fenv_t *e) { unsigned int mxcsr; asm (STMXCSR " %0" : "=m" (*&mxcsr)); e->__mxcsr = mxcsr; mxcsr = (mxcsr | 0x1f80) & ~0x3f; asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr)); } static __always_inline void libc_feholdexcept_387 (fenv_t *e) { /* Recall that fnstenv has a side-effect of masking exceptions. Clobber all of the fp registers so that the TOS field is 0. */ asm volatile ("fnstenv %0; fnclex" : "=m"(*e) : : "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"); } static __always_inline void libc_feholdexcept_setround_sse (fenv_t *e, int r) { unsigned int mxcsr; asm (STMXCSR " %0" : "=m" (*&mxcsr)); e->__mxcsr = mxcsr; mxcsr = ((mxcsr | 0x1f80) & ~0x603f) | (r << 3); asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr)); } /* Set both rounding mode and precision. A convenience function for use by libc_feholdexcept_setround and libc_feholdexcept_setround_53bit. */ static __always_inline void libc_feholdexcept_setround_387_prec (fenv_t *e, int r) { libc_feholdexcept_387 (e); fpu_control_t cw = e->__control_word; cw &= ~(_FPU_RC_ZERO | _FPU_EXTENDED); cw |= r | 0x3f; _FPU_SETCW (cw); } static __always_inline void libc_feholdexcept_setround_387 (fenv_t *e, int r) { libc_feholdexcept_setround_387_prec (e, r | _FPU_EXTENDED); } static __always_inline void libc_feholdexcept_setround_387_53bit (fenv_t *e, int r) { libc_feholdexcept_setround_387_prec (e, r | _FPU_DOUBLE); } static __always_inline int libc_fetestexcept_sse (int e) { unsigned int mxcsr; asm volatile (STMXCSR " %0" : "=m" (*&mxcsr)); return mxcsr & e & FE_ALL_EXCEPT; } static __always_inline int libc_fetestexcept_387 (int ex) { fexcept_t temp; asm volatile ("fnstsw %0" : "=a" (temp)); return temp & ex & FE_ALL_EXCEPT; } static __always_inline void libc_fesetenv_sse (fenv_t *e) { asm volatile (LDMXCSR " %0" : : "m" (e->__mxcsr)); } static __always_inline void libc_fesetenv_387 (fenv_t *e) { /* Clobber all fp registers so that the TOS value we saved earlier is compatible with the current state of the compiler. */ asm volatile ("fldenv %0" : : "m" (*e) : "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"); } static __always_inline int libc_feupdateenv_test_sse (fenv_t *e, int ex) { unsigned int mxcsr, old_mxcsr, cur_ex; asm volatile (STMXCSR " %0" : "=m" (*&mxcsr)); cur_ex = mxcsr & FE_ALL_EXCEPT; /* Merge current exceptions with the old environment. */ old_mxcsr = e->__mxcsr; mxcsr = old_mxcsr | cur_ex; asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr)); /* Raise SIGFPE for any new exceptions since the hold. Expect that the normal environment has all exceptions masked. */ if (__builtin_expect ((old_mxcsr >> 7) & cur_ex, 0)) __feraiseexcept (cur_ex); /* Test for exceptions raised since the hold. */ return cur_ex & ex; } static __always_inline int libc_feupdateenv_test_387 (fenv_t *e, int ex) { fexcept_t cur_ex; /* Save current exceptions. */ asm volatile ("fnstsw %0" : "=a" (cur_ex)); cur_ex &= FE_ALL_EXCEPT; /* Reload original environment. */ libc_fesetenv_387 (e); /* Merge current exceptions. */ __feraiseexcept (cur_ex); /* Test for exceptions raised since the hold. */ return cur_ex & ex; } static __always_inline void libc_feupdateenv_sse (fenv_t *e) { libc_feupdateenv_test_sse (e, 0); } static __always_inline void libc_feupdateenv_387 (fenv_t *e) { libc_feupdateenv_test_387 (e, 0); } static __always_inline void libc_feholdsetround_sse (fenv_t *e, int r) { unsigned int mxcsr; asm (STMXCSR " %0" : "=m" (*&mxcsr)); e->__mxcsr = mxcsr; mxcsr = (mxcsr & ~0x6000) | (r << 3); asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr)); } static __always_inline void libc_feholdsetround_387_prec (fenv_t *e, int r) { fpu_control_t cw; _FPU_GETCW (cw); e->__control_word = cw; cw &= ~(_FPU_RC_ZERO | _FPU_EXTENDED); cw |= r; _FPU_SETCW (cw); } static __always_inline void libc_feholdsetround_387 (fenv_t *e, int r) { libc_feholdsetround_387_prec (e, r | _FPU_EXTENDED); } static __always_inline void libc_feholdsetround_387_53bit (fenv_t *e, int r) { libc_feholdsetround_387_prec (e, r | _FPU_DOUBLE); } static __always_inline void libc_feresetround_sse (fenv_t *e) { unsigned int mxcsr; asm (STMXCSR " %0" : "=m" (*&mxcsr)); mxcsr = (mxcsr & ~0x6000) | (e->__mxcsr & 0x6000); asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr)); } static __always_inline void libc_feresetround_387 (fenv_t *e) { _FPU_SETCW (e->__control_word); } #ifdef __SSE_MATH__ # define libc_feholdexceptf libc_feholdexcept_sse # define libc_feholdexcept_setroundf libc_feholdexcept_setround_sse # define libc_fetestexceptf libc_fetestexcept_sse # define libc_fesetenvf libc_fesetenv_sse # define libc_feupdateenv_testf libc_feupdateenv_test_sse # define libc_feupdateenvf libc_feupdateenv_sse # define libc_feholdsetroundf libc_feholdsetround_sse # define libc_feresetroundf libc_feresetround_sse #else # define libc_feholdexceptf libc_feholdexcept_387 # define libc_feholdexcept_setroundf libc_feholdexcept_setround_387 # define libc_fetestexceptf libc_fetestexcept_387 # define libc_fesetenvf libc_fesetenv_387 # define libc_feupdateenv_testf libc_feupdateenv_test_387 # define libc_feupdateenvf libc_feupdateenv_387 # define libc_feholdsetroundf libc_feholdsetround_387 # define libc_feresetroundf libc_feresetround_387 #endif /* __SSE_MATH__ */ #ifdef __SSE2_MATH__ # define libc_feholdexcept libc_feholdexcept_sse # define libc_feholdexcept_setround libc_feholdexcept_setround_sse # define libc_fetestexcept libc_fetestexcept_sse # define libc_fesetenv libc_fesetenv_sse # define libc_feupdateenv_test libc_feupdateenv_test_sse # define libc_feupdateenv libc_feupdateenv_sse # define libc_feholdsetround libc_feholdsetround_sse # define libc_feresetround libc_feresetround_sse #else # define libc_feholdexcept libc_feholdexcept_387 # define libc_feholdexcept_setround libc_feholdexcept_setround_387 # define libc_fetestexcept libc_fetestexcept_387 # define libc_fesetenv libc_fesetenv_387 # define libc_feupdateenv_test libc_feupdateenv_test_387 # define libc_feupdateenv libc_feupdateenv_387 # define libc_feholdsetround libc_feholdsetround_387 # define libc_feresetround libc_feresetround_387 #endif /* __SSE2_MATH__ */ #define libc_feholdexceptl libc_feholdexcept_387 #define libc_feholdexcept_setroundl libc_feholdexcept_setround_387 #define libc_fetestexceptl libc_fetestexcept_387 #define libc_fesetenvl libc_fesetenv_387 #define libc_feupdateenv_testl libc_feupdateenv_test_387 #define libc_feupdateenvl libc_feupdateenv_387 #define libc_feholdsetroundl libc_feholdsetround_387 #define libc_feresetroundl libc_feresetround_387 #ifndef __SSE2_MATH__ # define libc_feholdexcept_setround_53bit libc_feholdexcept_setround_387_53bit # define libc_feholdsetround_53bit libc_feholdsetround_387_53bit #endif #undef __mxcsr #endif /* FENV_PRIVATE_H */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
You can’t perform that action at this time.