1 /* Test x86-specific floating-point environment (bug 16068): x87 part.
2 Copyright (C) 2015-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <fpu_control.h>
34 set_x87_cw (uint16_t val
)
36 fpu_control_t cw
= val
;
41 set_x87_cw_bits (uint16_t mask
, uint16_t bits
)
43 uint16_t cw
= get_x87_cw ();
44 cw
= (cw
& ~mask
) | bits
;
49 test_x87_cw_bits (const char *test
, uint16_t mask
, uint16_t bits
)
51 uint16_t cw
= get_x87_cw ();
52 printf ("Testing %s: cw = %x\n", test
, cw
);
53 if ((cw
& mask
) == bits
)
55 printf ("PASS: %s\n", test
);
60 printf ("FAIL: %s\n", test
);
69 __asm__
__volatile__ ("fnstsw %0" : "=a" (temp
));
74 set_x87_sw_bits (uint16_t mask
, uint16_t bits
)
77 __asm__
__volatile__ ("fnstenv %0" : "=m" (temp
));
78 temp
.__status_word
= (temp
.__status_word
& ~mask
) | bits
;
79 __asm__
__volatile__ ("fldenv %0" : : "m" (temp
));
83 test_x87_sw_bits (const char *test
, uint16_t mask
, uint16_t bits
)
85 uint16_t sw
= get_x87_sw ();
86 printf ("Testing %s: sw = %x\n", test
, sw
);
87 if ((sw
& mask
) == bits
)
89 printf ("PASS: %s\n", test
);
94 printf ("FAIL: %s\n", test
);
99 #define X87_CW_PREC_MASK _FPU_EXTENDED
106 /* Test precision mask. */
108 set_x87_cw_bits (X87_CW_PREC_MASK
, _FPU_SINGLE
);
111 result
|= test_x87_cw_bits ("fesetenv precision restoration",
112 X87_CW_PREC_MASK
, _FPU_EXTENDED
);
113 set_x87_cw_bits (X87_CW_PREC_MASK
, _FPU_EXTENDED
);
115 result
|= test_x87_cw_bits ("fesetenv precision restoration 2",
116 X87_CW_PREC_MASK
, _FPU_SINGLE
);
117 set_x87_cw_bits (X87_CW_PREC_MASK
, _FPU_DOUBLE
);
118 fesetenv (FE_NOMASK_ENV
);
119 result
|= test_x87_cw_bits ("fesetenv (FE_NOMASK_ENV) precision restoration",
120 X87_CW_PREC_MASK
, _FPU_EXTENDED
);
121 set_x87_cw_bits (X87_CW_PREC_MASK
, _FPU_SINGLE
);
122 fesetenv (FE_DFL_ENV
);
123 result
|= test_x87_cw_bits ("fesetenv (FE_DFL_ENV) precision restoration",
124 X87_CW_PREC_MASK
, _FPU_EXTENDED
);
125 /* Test x87 denormal operand masking. */
126 set_x87_cw_bits (_FPU_MASK_DM
, 0);
129 result
|= test_x87_cw_bits ("fesetenv denormal mask restoration",
130 _FPU_MASK_DM
, _FPU_MASK_DM
);
131 set_x87_cw_bits (_FPU_MASK_DM
, _FPU_MASK_DM
);
133 result
|= test_x87_cw_bits ("fesetenv denormal mask restoration 2",
135 set_x87_cw_bits (_FPU_MASK_DM
, 0);
136 /* Presume FE_NOMASK_ENV should leave the "denormal operand"
137 exception masked, as not a standard exception. */
138 fesetenv (FE_NOMASK_ENV
);
139 result
|= test_x87_cw_bits ("fesetenv (FE_NOMASK_ENV) denormal mask "
141 _FPU_MASK_DM
, _FPU_MASK_DM
);
142 set_x87_cw_bits (_FPU_MASK_DM
, 0);
143 fesetenv (FE_DFL_ENV
);
144 result
|= test_x87_cw_bits ("fesetenv (FE_DFL_ENV) denormal mask "
146 _FPU_MASK_DM
, _FPU_MASK_DM
);
147 /* Test x87 denormal operand exception. */
148 set_x87_sw_bits (__FE_DENORM
, __FE_DENORM
);
151 result
|= test_x87_sw_bits ("fesetenv denormal exception restoration",
153 set_x87_sw_bits (__FE_DENORM
, 0);
155 result
|= test_x87_sw_bits ("fesetenv denormal exception restoration 2",
156 __FE_DENORM
, __FE_DENORM
);
157 set_x87_sw_bits (__FE_DENORM
, __FE_DENORM
);
158 fesetenv (FE_NOMASK_ENV
);
159 result
|= test_x87_sw_bits ("fesetenv (FE_NOMASK_ENV) exception restoration",
161 set_x87_sw_bits (__FE_DENORM
, __FE_DENORM
);
162 fesetenv (FE_DFL_ENV
);
163 result
|= test_x87_sw_bits ("fesetenv (FE_DFL_ENV) exception restoration",
168 #define TEST_FUNCTION do_test ()
169 #include <test-skeleton.c>