Sun Dec 8 13:37:46 2019 UTC ()
Pull up following revision(s) (requested by riastradh in ticket #507):

	lib/libm/arch/aarch64/fenv.c: revision 1.5
	lib/libm/arch/aarch64/fenv.c: revision 1.6

Fix fesetenv and feupdateenv.
- fesetenv is supposed to set the stored rounding mode (and stored trap
  settings, but they have no effect on any ARMv8 I know).
- feupdateenv is supposed to re-raise the exceptions that were raised
  in the environment when it was called.
XXX atf test
XXX pullup-9

Fix feraiseexcept.
- Don't touch the trap flags (though on all ARMv8 I know they have no
  effect anyway).
- Don't clear any existing raised exception flags; just add to them.
XXX atf test
XXX pullup-9


(martin)
diff -r1.4 -r1.4.2.1 src/lib/libm/arch/aarch64/fenv.c

cvs diff -r1.4 -r1.4.2.1 src/lib/libm/arch/aarch64/fenv.c (expand / switch to unified diff)

--- src/lib/libm/arch/aarch64/fenv.c 2018/11/07 06:47:38 1.4
+++ src/lib/libm/arch/aarch64/fenv.c 2019/12/08 13:37:46 1.4.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fenv.c,v 1.4 2018/11/07 06:47:38 riastradh Exp $ */ 1/* $NetBSD: fenv.c,v 1.4.2.1 2019/12/08 13:37:46 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__RCSID("$NetBSD: fenv.c,v 1.4 2018/11/07 06:47:38 riastradh Exp $"); 33__RCSID("$NetBSD: fenv.c,v 1.4.2.1 2019/12/08 13:37:46 martin Exp $");
34 34
35#include "namespace.h" 35#include "namespace.h"
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/types.h> 38#include <sys/types.h>
39#include <assert.h> 39#include <assert.h>
40#include <fenv.h> 40#include <fenv.h>
41#include <string.h> 41#include <string.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <inttypes.h> 43#include <inttypes.h>
44 44
45#include <aarch64/armreg.h> 45#include <aarch64/armreg.h>
46 46
@@ -97,31 +97,29 @@ fegetexceptflag(fexcept_t *flagp, int ex @@ -97,31 +97,29 @@ fegetexceptflag(fexcept_t *flagp, int ex
97 97
98/* 98/*
99 * The feraiseexcept() function shall attempt to raise the supported 99 * The feraiseexcept() function shall attempt to raise the supported
100 * floating-point exceptions represented by the argument excepts. The order 100 * floating-point exceptions represented by the argument excepts. The order
101 * in which these floating-point exceptions are raised is unspecified.  101 * in which these floating-point exceptions are raised is unspecified.
102 */ 102 */
103int 103int
104feraiseexcept(int excepts) 104feraiseexcept(int excepts)
105{ 105{
106#ifndef lint 106#ifndef lint
107 _DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0); 107 _DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
108#endif 108#endif
109 unsigned int fpsr = reg_fpsr_read(); 109 unsigned int fpsr = reg_fpsr_read();
110 fpsr = (fpsr & ~FPSR_CSUM) | __SHIFTIN(excepts, FPSR_CSUM); 110 excepts &= FE_ALL_EXCEPT; /* paranoia */
 111 fpsr |= __SHIFTIN(excepts, FPSR_CSUM);
111 reg_fpsr_write(fpsr); 112 reg_fpsr_write(fpsr);
112 unsigned int fpcr = reg_fpcr_read(); 
113 fpcr = (fpcr & ~FPCR_ESUM) | __SHIFTIN(excepts, FPCR_ESUM); 
114 reg_fpcr_write(fpcr); 
115 return 0; 113 return 0;
116} 114}
117 115
118/* 116/*
119 * The fesetexceptflag() function shall attempt to set the floating-point 117 * The fesetexceptflag() function shall attempt to set the floating-point
120 * status flags indicated by the argument excepts to the states stored in the 118 * status flags indicated by the argument excepts to the states stored in the
121 * object pointed to by flagp. The value pointed to by flagp shall have been 119 * object pointed to by flagp. The value pointed to by flagp shall have been
122 * set by a previous call to fegetexceptflag() whose second argument 120 * set by a previous call to fegetexceptflag() whose second argument
123 * represented at least those floating-point exceptions represented by the 121 * represented at least those floating-point exceptions represented by the
124 * argument excepts. This function does not raise floating-point exceptions, 122 * argument excepts. This function does not raise floating-point exceptions,
125 * but only sets the state of the flags. 123 * but only sets the state of the flags.
126 */ 124 */
127int 125int
@@ -203,43 +201,43 @@ feholdexcept(fenv_t *envp) @@ -203,43 +201,43 @@ feholdexcept(fenv_t *envp)
203 return 0; 201 return 0;
204} 202}
205 203
206/* 204/*
207 * The fesetenv() function shall attempt to establish the floating-point 205 * The fesetenv() function shall attempt to establish the floating-point
208 * environment represented by the object pointed to by envp. The fesetenv() 206 * environment represented by the object pointed to by envp. The fesetenv()
209 * function does not raise floating-point exceptions, but only installs the 207 * function does not raise floating-point exceptions, but only installs the
210 * state of the floating-point status flags represented through its argument. 208 * state of the floating-point status flags represented through its argument.
211 */ 209 */
212int 210int
213fesetenv(const fenv_t *envp) 211fesetenv(const fenv_t *envp)
214{ 212{
215 reg_fpsr_write(envp->__fpsr); 213 reg_fpsr_write(envp->__fpsr);
 214 reg_fpcr_write(envp->__fpcr);
216 return 0; 215 return 0;
217} 216}
218 217
219/* 218/*
220 * The feupdateenv() function shall attempt to save the currently raised 219 * The feupdateenv() function shall attempt to save the currently raised
221 * floating-point exceptions in its automatic storage, attempt to install the 220 * floating-point exceptions in its automatic storage, attempt to install the
222 * floating-point environment represented by the object pointed to by envp, 221 * floating-point environment represented by the object pointed to by envp,
223 * and then attempt to raise the saved floating-point exceptions.  222 * and then attempt to raise the saved floating-point exceptions.
224 */ 223 */
225int 224int
226feupdateenv(const fenv_t *envp) 225feupdateenv(const fenv_t *envp)
227{ 226{
228#ifndef lint 227 int except = fetestexcept(FE_ALL_EXCEPT);
229 _DIAGASSERT(envp != NULL); 228
230#endif 229 fesetenv(envp);
231 reg_fpsr_write(envp->__fpsr); 230 feraiseexcept(except);
232 reg_fpcr_write(envp->__fpcr); 
233 231
234 /* Success */ 232 /* Success */
235 return 0; 233 return 0;
236} 234}
237 235
238int 236int
239feenableexcept(int excepts) 237feenableexcept(int excepts)
240{ 238{
241 const uint32_t __fpcr = reg_fpcr_read(); 239 const uint32_t __fpcr = reg_fpcr_read();
242 reg_fpcr_write((__fpcr & ~FPCR_ESUM) | __SHIFTIN(excepts, FPCR_ESUM)); 240 reg_fpcr_write((__fpcr & ~FPCR_ESUM) | __SHIFTIN(excepts, FPCR_ESUM));
243 return __SHIFTOUT(__fpcr, FPCR_ESUM); 241 return __SHIFTOUT(__fpcr, FPCR_ESUM);
244} 242}
245 243