Sun Aug 25 18:31:30 2019 UTC ()
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


(riastradh)
diff -r1.4 -r1.5 src/lib/libm/arch/aarch64/fenv.c

cvs diff -r1.4 -r1.5 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/08/25 18:31:30 1.5
@@ -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.5 2019/08/25 18:31:30 riastradh 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.5 2019/08/25 18:31:30 riastradh 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
@@ -203,43 +203,43 @@ feholdexcept(fenv_t *envp) @@ -203,43 +203,43 @@ feholdexcept(fenv_t *envp)
203 return 0; 203 return 0;
204} 204}
205 205
206/* 206/*
207 * The fesetenv() function shall attempt to establish the floating-point 207 * The fesetenv() function shall attempt to establish the floating-point
208 * environment represented by the object pointed to by envp. The fesetenv() 208 * environment represented by the object pointed to by envp. The fesetenv()
209 * function does not raise floating-point exceptions, but only installs the 209 * function does not raise floating-point exceptions, but only installs the
210 * state of the floating-point status flags represented through its argument. 210 * state of the floating-point status flags represented through its argument.
211 */ 211 */
212int 212int
213fesetenv(const fenv_t *envp) 213fesetenv(const fenv_t *envp)
214{ 214{
215 reg_fpsr_write(envp->__fpsr); 215 reg_fpsr_write(envp->__fpsr);
 216 reg_fpcr_write(envp->__fpcr);
216 return 0; 217 return 0;
217} 218}
218 219
219/* 220/*
220 * The feupdateenv() function shall attempt to save the currently raised 221 * The feupdateenv() function shall attempt to save the currently raised
221 * floating-point exceptions in its automatic storage, attempt to install the 222 * floating-point exceptions in its automatic storage, attempt to install the
222 * floating-point environment represented by the object pointed to by envp, 223 * floating-point environment represented by the object pointed to by envp,
223 * and then attempt to raise the saved floating-point exceptions.  224 * and then attempt to raise the saved floating-point exceptions.
224 */ 225 */
225int 226int
226feupdateenv(const fenv_t *envp) 227feupdateenv(const fenv_t *envp)
227{ 228{
228#ifndef lint 229 int except = fetestexcept(FE_ALL_EXCEPT);
229 _DIAGASSERT(envp != NULL); 230
230#endif 231 fesetenv(envp);
231 reg_fpsr_write(envp->__fpsr); 232 feraiseexcept(except);
232 reg_fpcr_write(envp->__fpcr); 
233 233
234 /* Success */ 234 /* Success */
235 return 0; 235 return 0;
236} 236}
237 237
238int 238int
239feenableexcept(int excepts) 239feenableexcept(int excepts)
240{ 240{
241 const uint32_t __fpcr = reg_fpcr_read(); 241 const uint32_t __fpcr = reg_fpcr_read();
242 reg_fpcr_write((__fpcr & ~FPCR_ESUM) | __SHIFTIN(excepts, FPCR_ESUM)); 242 reg_fpcr_write((__fpcr & ~FPCR_ESUM) | __SHIFTIN(excepts, FPCR_ESUM));
243 return __SHIFTOUT(__fpcr, FPCR_ESUM); 243 return __SHIFTOUT(__fpcr, FPCR_ESUM);
244} 244}
245 245