Mercurial > hg > octave-lojdl
changeset 9603:8bea4e89326f
implement FLOAT_STORE to allow safer complex comparisons on x87
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 02 Sep 2009 14:18:20 +0200 |
parents | dba091e1ee39 |
children | 4dd8fc7c106c |
files | ChangeLog configure.in liboctave/ChangeLog liboctave/oct-cmplx.h |
diffstat | 4 files changed, 51 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-09-02 Jaroslav Hajek <highegg@gmail.com> + + * configure.in (FLOAT_STORE): New config macro. + 2009-09-02 Jaroslav Hajek <highegg@gmail.com> * acx_blas_f77_func.m4 (ACX_BLAS_F77_FUNC): Check for correct INTEGER
--- a/configure.in +++ b/configure.in @@ -289,6 +289,23 @@ AC_SUBST(CARBON_LIBS) fi +### When compiling math for x87, problems may arise in some code comparing +### floating-point intermediate results. +### Generally, it helps to store the result in a local volatile variable, +### but it also degrades performance. +### Thus, we provide a FLOAT_TRUNCATE macro that may be defined to "volatile" +### when compiling for x87 target, or left empty for modern SSE math, that +### doesn't suffer from this problem at all. +AC_ARG_ENABLE(float-truncate, + [AS_HELP_STRING([--enable-float-truncate], + [enables truncating intermediate FP results.])], + [if test "$enableval" = yes; then ac_float_truncate=volatile; + else ac_float_truncate=; fi], + ac_float_truncate=) + +AC_DEFINE_UNQUOTED(FLOAT_TRUNCATE, $ac_float_truncate, + [Define to volatile if you need truncating intermediate FP results]) + ### On Intel systems with gcc, we may need to compile with -mieee-fp ### and -ffloat-store to get full support for IEEE floating point. ###
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2009-09-02 Jaroslav Hajek <highegg@gmail.com> + + * oct-cmplx.h: Rewrite the comaprison ops. Use FLOAT_STORE. + 2009-09-01 Jaroslav Hajek <highegg@gmail.com> * oct-cmplx.h: Correct strict operators in macros.
--- a/liboctave/oct-cmplx.h +++ b/liboctave/oct-cmplx.h @@ -2,6 +2,7 @@ Copyright (C) 1995, 1996, 1997, 2000, 2001, 2004, 2005, 2007, 2008, 2009 John W. Eaton +Copyright (C) 2009 VZLU Prague, a.s. This file is part of Octave. @@ -40,21 +41,39 @@ template <class T> \ inline bool operator OP (const std::complex<T>& a, const std::complex<T>& b) \ { \ - T ax = std::abs (a), bx = std::abs (b); \ - return ax OPS bx || (ax == bx && std::arg (a) OP std::arg (b)); \ + FLOAT_TRUNCATE const T ax = std::abs (a), bx = std::abs (b); \ + if (ax == bx) \ + { \ + FLOAT_TRUNCATE const T ay = std::arg (a), by = std::arg (b); \ + return ay OP by; \ + } \ + else \ + return ax OPS bx; \ } \ template <class T> \ inline bool operator OP (const std::complex<T>& a, T b) \ { \ - T ax = std::abs (a); \ - return ax OPS b || (ax == b && std::arg (a) OP 0); \ + FLOAT_TRUNCATE const T ax = std::abs (a); \ + if (ax == b) \ + { \ + FLOAT_TRUNCATE const T ay = std::arg (a); \ + return ay OP 0; \ + } \ + else \ + return ax OPS b; \ } \ template <class T> \ inline bool operator OP (T a, const std::complex<T>& b) \ { \ - T bx = std::abs (b); \ - return a OPS bx || (a == bx && 0 OP std::arg (b)); \ -} \ + FLOAT_TRUNCATE const T bx = std::abs (b); \ + if (a == bx) \ + { \ + FLOAT_TRUNCATE const T by = std::arg (b); \ + return 0 OP by; \ + } \ + else \ + return a OPS bx; \ +} DEF_COMPLEXR_COMP (>, >) DEF_COMPLEXR_COMP (<, <)