ref: 07411559135b98e48b53f68d81ff11bccefd11f8
parent: ace89ad7cca307fd24225c672f613c6d40587588
author: Erik de Castro Lopo <erikd@miles>
date: Tue Sep 6 07:04:35 EDT 2005
float_cast.h : Update to include Cygwin specific fixes.
--- a/src/float_cast.h
+++ b/src/float_cast.h
@@ -1,23 +1,25 @@
/*
-** Copyright (C) 2001-2003 Erik de Castro Lopo <[email protected]>
+** Copyright (C) 2001-2004 Erik de Castro Lopo <[email protected]>
**
** This program 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 2 of the License, or
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 2.1 of the License, or
** (at your option) any later version.
**
** This program 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.
+** GNU Lesser General Public License for more details.
**
-** You should have received a copy of the GNU General Public License
+** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/* Version 1.3 */
+/* Version 1.4 */
+#ifndef FLOAT_CAST_HEADER
+#define FLOAT_CAST_HEADER
/*============================================================================
** On Intel Pentium processors (especially PIII and probably P4), converting
@@ -71,10 +73,59 @@
#include <math.h>
+#elif (defined (__CYGWIN__))
+
+ #include <math.h>
+
+ #undef HAVE_LRINT_REPLACEMENT
+ #define HAVE_LRINT_REPLACEMENT 1
+
+ #undef lrint
+ #undef lrintf
+
+ #define lrint double2int
+ #define lrintf float2int
+
+ /*
+ ** The native CYGWIN lrint and lrintf functions are buggy:
+ ** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
+ ** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
+ ** and slow.
+ ** These functions (pulled from the Public Domain MinGW math.h header)
+ ** replace the native versions.
+ */
+
+ static inline long double2int (double in)
+ { long retval ;
+
+ __asm__ __volatile__
+ ( "fistpl %0"
+ : "=m" (retval)
+ : "t" (in)
+ : "st"
+ ) ;
+
+ return retval ;
+ } /* double2int */
+
+ static inline long float2int (float in)
+ { long retval ;
+
+ __asm__ __volatile__
+ ( "fistpl %0"
+ : "=m" (retval)
+ : "t" (in)
+ : "st"
+ ) ;
+
+ return retval ;
+ } /* float2int */
+
#elif (defined (WIN32) || defined (_WIN32))
#undef HAVE_LRINT_REPLACEMENT
#define HAVE_LRINT_REPLACEMENT 1
+
#include <math.h>
/*
@@ -156,7 +207,7 @@
#define lrint double2int
#define lrintf float2int
- inline static long int
+ inline static long
float2int (register float in)
{ int res [2] ;
@@ -171,7 +222,7 @@
return res [1] ;
} /* lrintf */
- inline static long int
+ inline static long
double2int (register double in)
{ int res [2] ;
@@ -200,6 +251,7 @@
#endif
+#endif /* FLOAT_CAST_HEADER */
/*
** Do not edit or modify anything in this comment block.