Mercurial > jwe > octave
changeset 22073:d18c63a45070
wrappers for setting long double rounding mode (bug #48319)
* fpucw-wrappers.c: Rename from fpucw-wrapper.c.
* fpucw-wrappers.h: Rename from fpucw-wrapper.h. Change all uses.
* liboctave/wrappers/module.mk: Update.
* fpucw-wrappers.h, fpucw-wrappers.c
(octave_begin_long_double_rounding, octave_end_long_double_rounding):
New functions.
* oct-inttypes.cc: Use wrapper functions from fpucw-wrappers.h instead
of instead of macros from fpucw.h.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 07 Jul 2016 18:24:50 -0400 |
parents | 7680225527ef |
children | 5a0eea960bdb |
files | libinterp/octave-value/ov-java.cc liboctave/util/oct-inttypes.cc liboctave/util/oct-inttypes.h liboctave/wrappers/fpucw-wrapper.c liboctave/wrappers/fpucw-wrapper.h liboctave/wrappers/fpucw-wrappers.c liboctave/wrappers/fpucw-wrappers.h liboctave/wrappers/module.mk |
diffstat | 8 files changed, 136 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-java.cc Thu Jul 07 16:27:21 2016 -0400 +++ b/libinterp/octave-value/ov-java.cc Thu Jul 07 18:24:50 2016 -0400 @@ -27,7 +27,7 @@ #include "defun.h" #include "error.h" #include "errwarn.h" -#include "fpucw-wrapper.h" +#include "fpucw-wrappers.h" #if defined (HAVE_WINDOWS_H) # include <windows.h>
--- a/liboctave/util/oct-inttypes.cc Thu Jul 07 16:27:21 2016 -0400 +++ b/liboctave/util/oct-inttypes.cc Thu Jul 07 18:24:50 2016 -0400 @@ -25,8 +25,8 @@ # include "config.h" #endif +#include "fpucw-wrappers.h" #include "lo-error.h" - #include "oct-inttypes.h" template <typename T> @@ -110,14 +110,12 @@ bool \ octave_int_cmp_op::external_mop (double x, T y) \ { \ - DECL_LONG_DOUBLE_ROUNDING \ - \ - BEGIN_LONG_DOUBLE_ROUNDING (); \ + unsigned int oldcw = octave_begin_long_double_rounding (); \ \ bool retval = xop::op (static_cast<long double> (x), \ static_cast<long double> (y)); \ \ - END_LONG_DOUBLE_ROUNDING (); \ + octave_end_long_double_rounding (oldcw); \ \ return retval; \ } \ @@ -126,16 +124,14 @@ bool \ octave_int_cmp_op::external_mop (T x, double y) \ { \ - DECL_LONG_DOUBLE_ROUNDING \ - \ - BEGIN_LONG_DOUBLE_ROUNDING (); \ + unsigned int oldcw = octave_begin_long_double_rounding (); \ \ - bool retval = xop::op (static_cast<long double> (x), \ - static_cast<long double> (y)); \ + bool retval = xop::op (static_cast<long double> (x), \ + static_cast<long double> (y)); \ \ - END_LONG_DOUBLE_ROUNDING (); \ + octave_end_long_double_rounding (oldcw); \ \ - return retval; \ + return retval; \ } DEFINE_OCTAVE_LONG_DOUBLE_CMP_OP_TEMPLATES (int64_t) @@ -161,13 +157,11 @@ uint64_t octave_external_uint64_uint64_mul (uint64_t x, uint64_t y) { - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); + unsigned int oldcw = octave_begin_long_double_rounding (); uint64_t retval = octave_int_arith_base<uint64_t, false>::mul_internal (x, y); - END_LONG_DOUBLE_ROUNDING (); + octave_end_long_double_rounding (oldcw); return retval; } @@ -175,13 +169,11 @@ int64_t octave_external_int64_int64_mul (int64_t x, int64_t y) { - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); + unsigned int oldcw = octave_begin_long_double_rounding (); int64_t retval = octave_int_arith_base<int64_t, true>::mul_internal (x, y); - END_LONG_DOUBLE_ROUNDING (); + octave_end_long_double_rounding (oldcw); return retval; } @@ -198,13 +190,11 @@ T \ external_double_ ## T ## _ ## NAME (double x, T y) \ { \ - DECL_LONG_DOUBLE_ROUNDING \ - \ - BEGIN_LONG_DOUBLE_ROUNDING (); \ + unsigned int oldcw = octave_begin_long_double_rounding (); \ \ T retval = T (x OP static_cast<long double> (y.value ())); \ \ - END_LONG_DOUBLE_ROUNDING (); \ + octave_end_long_double_rounding (oldcw); \ \ return retval; \ } \ @@ -212,13 +202,11 @@ T \ external_ ## T ## _double_ ## NAME (T x, double y) \ { \ - DECL_LONG_DOUBLE_ROUNDING \ - \ - BEGIN_LONG_DOUBLE_ROUNDING (); \ + unsigned int oldcw = octave_begin_long_double_rounding (); \ \ T retval = T (static_cast<long double> (x.value ()) OP y); \ \ - END_LONG_DOUBLE_ROUNDING (); \ + octave_end_long_double_rounding (oldcw); \ \ return retval; \ }
--- a/liboctave/util/oct-inttypes.h Thu Jul 07 16:27:21 2016 -0400 +++ b/liboctave/util/oct-inttypes.h Thu Jul 07 18:24:50 2016 -0400 @@ -28,12 +28,12 @@ #include <cstdlib> +#include <iosfwd> #include <limits> -#include <iosfwd> -#include "lo-traits.h" #include "lo-math.h" #include "lo-mappers.h" +#include "lo-traits.h" template <typename T> class octave_int;
--- a/liboctave/wrappers/fpucw-wrapper.c Thu Jul 07 16:27:21 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - -Copyright (C) 2016 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -// The fpucw macros are provided by gnulib. We don't include gnulib -// headers directly in Octave's C++ source files to avoid problems that -// may be caused by the way that gnulib overrides standard library -// functions. - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#if defined (HAVE_FPU_CONTROL_H) -# include <fpu_control.h> -#endif - -#include "fpucw.h" - -#include "fpucw-wrapper.h" - -#if ! defined (_FPU_DEFAULT) -# if defined __i386__ || defined __x86_64__ -# define _FPU_DEFAULT 0x037f -# else -# define _FPU_DEFAULT 0 -# endif -#endif - -void -octave_set_default_fpucw (void) -{ - fpucw_t cw = GET_FPUCW (); - - if (cw != _FPU_DEFAULT) - SET_FPUCW (_FPU_DEFAULT); -}
--- a/liboctave/wrappers/fpucw-wrapper.h Thu Jul 07 16:27:21 2016 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - -Copyright (C) 2016 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#if ! defined (octave_fpucw_wrapper_h) -#define octave_fpucw_wrapper_h 1 - -#if defined __cplusplus -extern "C" { -#endif - -/* For now, all we need to be able to do is set the control word to - the default value. */ - -extern void octave_set_default_fpucw (void); - -#if defined __cplusplus -} -#endif - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/fpucw-wrappers.c Thu Jul 07 18:24:50 2016 -0400 @@ -0,0 +1,73 @@ +/* + +Copyright (C) 2016 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +// The fpucw macros are provided by gnulib. We don't include gnulib +// headers directly in Octave's C++ source files to avoid problems that +// may be caused by the way that gnulib overrides standard library +// functions. + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#if defined (HAVE_FPU_CONTROL_H) +# include <fpu_control.h> +#endif + +#include "fpucw.h" + +#include "fpucw-wrappers.h" + +#if ! defined (_FPU_DEFAULT) +# if defined __i386__ || defined __x86_64__ +# define _FPU_DEFAULT 0x037f +# else +# define _FPU_DEFAULT 0 +# endif +#endif + +void +octave_set_default_fpucw (void) +{ + fpucw_t cw = GET_FPUCW (); + + if (cw != _FPU_DEFAULT) + SET_FPUCW (_FPU_DEFAULT); +} + +// OLDCW is the name used by the fpucw.h macros. + +unsigned int +octave_begin_long_double_rounding (void) +{ + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + return oldcw; +} + +void +octave_end_long_double_rounding (unsigned int oldcw) +{ + END_LONG_DOUBLE_ROUNDING (); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/fpucw-wrappers.h Thu Jul 07 18:24:50 2016 -0400 @@ -0,0 +1,42 @@ +/* + +Copyright (C) 2016 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#if ! defined (octave_fpucw_wrappers_h) +#define octave_fpucw_wrappers_h 1 + +#if defined __cplusplus +extern "C" { +#endif + +extern void octave_set_default_fpucw (void); + +// unsigned int must match the actual type of fpucw_t. + +extern unsigned int octave_begin_long_double_rounding (void); + +extern void octave_end_long_double_rounding (unsigned int); + +#if defined __cplusplus +} +#endif + +#endif
--- a/liboctave/wrappers/module.mk Thu Jul 07 16:27:21 2016 -0400 +++ b/liboctave/wrappers/module.mk Thu Jul 07 18:24:50 2016 -0400 @@ -5,7 +5,7 @@ liboctave/wrappers/dirent-wrappers.h \ liboctave/wrappers/fcntl-wrappers.h \ liboctave/wrappers/filepos-wrappers.h \ - liboctave/wrappers/fpucw-wrapper.h \ + liboctave/wrappers/fpucw-wrappers.h \ liboctave/wrappers/gen-tempname-wrapper.h \ liboctave/wrappers/getopt-wrapper.h \ liboctave/wrappers/glob-wrappers.h \ @@ -38,7 +38,7 @@ liboctave/wrappers/dirent-wrappers.c \ liboctave/wrappers/fcntl-wrappers.c \ liboctave/wrappers/filepos-wrappers.c \ - liboctave/wrappers/fpucw-wrapper.c \ + liboctave/wrappers/fpucw-wrappers.c \ liboctave/wrappers/gen-tempname-wrapper.c \ liboctave/wrappers/getopt-wrapper.c \ liboctave/wrappers/glob-wrappers.c \