Fri Jun 14 02:37:53 2013 UTC ()
Pull up following revision(s) (requested by riastradh in ticket #899):
	lib/libm/arch/i387/fenv.c: revision 1.5
	lib/libm/arch/x86_64/fenv.c: revision 1.3-1.4
Fix amd64 feraiseexcept so that it actually traps.
The call to fwait got lost somewhere along the line; the i387 code has it.
Fix sense of fegetexcept on x86.
Somehow I overlooked this when I fixed feenableexcept and fedisableexcept
last summer.


(msaitoh)
diff -r1.3.8.1 -r1.3.8.1.4.1 src/lib/libm/arch/i387/fenv.c
diff -r1.1.8.1 -r1.1.8.1.4.1 src/lib/libm/arch/x86_64/fenv.c

cvs diff -r1.3.8.1 -r1.3.8.1.4.1 src/lib/libm/arch/i387/fenv.c (expand / switch to unified diff)

--- src/lib/libm/arch/i387/fenv.c 2012/08/12 18:53:11 1.3.8.1
+++ src/lib/libm/arch/i387/fenv.c 2013/06/14 02:37:53 1.3.8.1.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fenv.c,v 1.3.8.1 2012/08/12 18:53:11 martin Exp $ */ 1/* $NetBSD: fenv.c,v 1.3.8.1.4.1 2013/06/14 02:37:53 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> 4 * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__RCSID("$NetBSD: fenv.c,v 1.3.8.1 2012/08/12 18:53:11 martin Exp $"); 30__RCSID("$NetBSD: fenv.c,v 1.3.8.1.4.1 2013/06/14 02:37:53 msaitoh Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/sysctl.h> 33#include <sys/sysctl.h>
34#include <assert.h> 34#include <assert.h>
35#include <fenv.h> 35#include <fenv.h>
36#include <stddef.h> 36#include <stddef.h>
37#include <string.h> 37#include <string.h>
38 38
39/* Load x87 Control Word */ 39/* Load x87 Control Word */
40#define __fldcw(__cw) __asm__ __volatile__ \ 40#define __fldcw(__cw) __asm__ __volatile__ \
41 ("fldcw %0" : : "m" (__cw)) 41 ("fldcw %0" : : "m" (__cw))
42 42
43/* No-Wait Store Control Word */ 43/* No-Wait Store Control Word */
@@ -500,15 +500,15 @@ fedisableexcept(int mask) @@ -500,15 +500,15 @@ fedisableexcept(int mask)
500} 500}
501 501
502int 502int
503fegetexcept(void) 503fegetexcept(void)
504{ 504{
505 uint16_t control; 505 uint16_t control;
506 506
507 /* 507 /*
508 * We assume that the masks for the x87 and the SSE unit are 508 * We assume that the masks for the x87 and the SSE unit are
509 * the same. 509 * the same.
510 */ 510 */
511 __fnstcw(&control); 511 __fnstcw(&control);
512 512
513 return (control & FE_ALL_EXCEPT); 513 return (~control & FE_ALL_EXCEPT);
514} 514}

cvs diff -r1.1.8.1 -r1.1.8.1.4.1 src/lib/libm/arch/x86_64/fenv.c (expand / switch to unified diff)

--- src/lib/libm/arch/x86_64/fenv.c 2012/08/12 18:53:11 1.1.8.1
+++ src/lib/libm/arch/x86_64/fenv.c 2013/06/14 02:37:53 1.1.8.1.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fenv.c,v 1.1.8.1 2012/08/12 18:53:11 martin Exp $ */ 1/* $NetBSD: fenv.c,v 1.1.8.1.4.1 2013/06/14 02:37:53 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> 4 * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__RCSID("$NetBSD: fenv.c,v 1.1.8.1 2012/08/12 18:53:11 martin Exp $"); 30__RCSID("$NetBSD: fenv.c,v 1.1.8.1.4.1 2013/06/14 02:37:53 msaitoh Exp $");
31 31
32#include <assert.h> 32#include <assert.h>
33#include <fenv.h> 33#include <fenv.h>
34#include <stddef.h> 34#include <stddef.h>
35#include <string.h> 35#include <string.h>
36 36
37/* Load x87 Control Word */ 37/* Load x87 Control Word */
38#define __fldcw(__cw) __asm__ __volatile__ \ 38#define __fldcw(__cw) __asm__ __volatile__ \
39 ("fldcw %0" : : "m" (__cw)) 39 ("fldcw %0" : : "m" (__cw))
40 40
41/* No-Wait Store Control Word */ 41/* No-Wait Store Control Word */
42#define __fnstcw(__cw) __asm__ __volatile__ \ 42#define __fnstcw(__cw) __asm__ __volatile__ \
43 ("fnstcw %0" : "=m" (*(__cw))) 43 ("fnstcw %0" : "=m" (*(__cw)))
@@ -48,26 +48,30 @@ __RCSID("$NetBSD: fenv.c,v 1.1.8.1 2012/ @@ -48,26 +48,30 @@ __RCSID("$NetBSD: fenv.c,v 1.1.8.1 2012/
48 48
49/* No-Wait Clear Exception Flags */ 49/* No-Wait Clear Exception Flags */
50#define __fnclex() __asm__ __volatile__ \ 50#define __fnclex() __asm__ __volatile__ \
51 ("fnclex") 51 ("fnclex")
52 52
53/* Load x87 Environment */ 53/* Load x87 Environment */
54#define __fldenv(__env) __asm__ __volatile__ \ 54#define __fldenv(__env) __asm__ __volatile__ \
55 ("fldenv %0" : : "m" (__env)) 55 ("fldenv %0" : : "m" (__env))
56 56
57/* No-Wait Store x87 environment */ 57/* No-Wait Store x87 environment */
58#define __fnstenv(__env) __asm__ __volatile__ \ 58#define __fnstenv(__env) __asm__ __volatile__ \
59 ("fnstenv %0" : "=m" (*(__env))) 59 ("fnstenv %0" : "=m" (*(__env)))
60 60
 61/* Check for and handle pending unmasked x87 pending FPU exceptions */
 62#define __fwait(__env) __asm__ __volatile__ \
 63 ("fwait")
 64
61/* Load the MXCSR register */ 65/* Load the MXCSR register */
62#define __ldmxcsr(__mxcsr) __asm__ __volatile__ \ 66#define __ldmxcsr(__mxcsr) __asm__ __volatile__ \
63 ("ldmxcsr %0" : : "m" (__mxcsr)) 67 ("ldmxcsr %0" : : "m" (__mxcsr))
64 68
65/* Store the MXCSR register state */ 69/* Store the MXCSR register state */
66#define __stmxcsr(__mxcsr) __asm__ __volatile__ \ 70#define __stmxcsr(__mxcsr) __asm__ __volatile__ \
67 ("stmxcsr %0" : "=m" (*(__mxcsr))) 71 ("stmxcsr %0" : "=m" (*(__mxcsr)))
68 72
69/* 73/*
70 * The following constant represents the default floating-point environment 74 * The following constant represents the default floating-point environment
71 * (that is, the one installed at program startup) and has type pointer to 75 * (that is, the one installed at program startup) and has type pointer to
72 * const-qualified fenv_t. 76 * const-qualified fenv_t.
73 * 77 *
@@ -168,26 +172,27 @@ fegetexceptflag(fexcept_t *flagp, int ex @@ -168,26 +172,27 @@ fegetexceptflag(fexcept_t *flagp, int ex
168 * directly. 172 * directly.
169 * 173 *
170 * The validation of input is being deferred to fesetexceptflag(). 174 * The validation of input is being deferred to fesetexceptflag().
171 */ 175 */
172int 176int
173feraiseexcept(int excepts) 177feraiseexcept(int excepts)
174{ 178{
175 int ex; 179 int ex;
176 180
177 _DIAGASSERT((excepts & ~FE_ALL_EXCEPT) == 0); 181 _DIAGASSERT((excepts & ~FE_ALL_EXCEPT) == 0);
178 182
179 ex = excepts & FE_ALL_EXCEPT; 183 ex = excepts & FE_ALL_EXCEPT;
180 fesetexceptflag((unsigned int *)&excepts, excepts); 184 fesetexceptflag((unsigned int *)&excepts, excepts);
 185 __fwait();
181 186
182 /* Success */ 187 /* Success */
183 return (0); 188 return (0);
184} 189}
185 190
186/* 191/*
187 * This function sets the floating-point status flags indicated by the argument 192 * This function sets the floating-point status flags indicated by the argument
188 * `excepts' to the states stored in the object pointed to by `flagp'. It does 193 * `excepts' to the states stored in the object pointed to by `flagp'. It does
189 * NOT raise any floating-point exceptions, but only sets the state of the flags. 194 * NOT raise any floating-point exceptions, but only sets the state of the flags.
190 */ 195 */
191int 196int
192fesetexceptflag(const fexcept_t *flagp, int excepts) 197fesetexceptflag(const fexcept_t *flagp, int excepts)
193{ 198{
@@ -509,16 +514,16 @@ fedisableexcept(int mask) @@ -509,16 +514,16 @@ fedisableexcept(int mask)
509} 514}
510 515
511int 516int
512fegetexcept(void) 517fegetexcept(void)
513{ 518{
514 uint16_t control; 519 uint16_t control;
515 520
516 /* 521 /*
517 * We assume that the masks for the x87 and the SSE unit are 522 * We assume that the masks for the x87 and the SSE unit are
518 * the same. 523 * the same.
519 */ 524 */
520 __fnstcw(&control); 525 __fnstcw(&control);
521 526
522 return (control & FE_ALL_EXCEPT); 527 return (~control & FE_ALL_EXCEPT);
523} 528}
524 529