History

float_cast.h : Update to include Cygwin specific fixes.

Erik de Castro Lopo committed 21 years ago

Commit 07411551 parent ace89ad1 file · +61 −9Browse files

Unified · Split

src/float_cast.h+61−9
@@ -1,23 +1,25 @@
11 /*
2−** Copyright (C) 2001-2003 Erik de Castro Lopo <erikd@mega-nerd.com>
2+** Copyright (C) 2001-2004 Erik de Castro Lopo <erikd@mega-nerd.com>
33 **
44 ** This program is free software; you can redistribute it and/or modify
5−** it under the terms of the GNU General Public License as published by
6−** the Free Software Foundation; either version 2 of the License, or
5+** it under the terms of the GNU Lesser General Public License as published by
6+** the Free Software Foundation; either version 2.1 of the License, or
77 ** (at your option) any later version.
88 **
99 ** This program is distributed in the hope that it will be useful,
1010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
1111 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12−** GNU General Public License for more details.
12+** GNU Lesser General Public License for more details.
1313 **
14−** You should have received a copy of the GNU General Public License
14+** You should have received a copy of the GNU Lesser General Public License
1515 ** along with this program; if not, write to the Free Software
16−** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717 */
1818
19−/* Version 1.3 */
19+/* Version 1.4 */
2020
21+#ifndef FLOAT_CAST_HEADER
22+#define FLOAT_CAST_HEADER
2123
2224 /*============================================================================
2325 ** On Intel Pentium processors (especially PIII and probably P4), converting
@@ -71,10 +73,59 @@ · 47 unmodified lines
7173
7274 #include <math.h>
7375
76+#elif (defined (__CYGWIN__))
77+
78+ #include <math.h>
79+
80+ #undef HAVE_LRINT_REPLACEMENT
81+ #define HAVE_LRINT_REPLACEMENT 1
82+
83+ #undef lrint
84+ #undef lrintf
85+
86+ #define lrint double2int
87+ #define lrintf float2int
88+
89+ /*
90+ ** The native CYGWIN lrint and lrintf functions are buggy:
91+ ** http://sourceware.org/ml/cygwin/2005-06/msg00153.html
92+ ** http://sourceware.org/ml/cygwin/2005-09/msg00047.html
93+ ** and slow.
94+ ** These functions (pulled from the Public Domain MinGW math.h header)
95+ ** replace the native versions.
96+ */
97+
98+ static inline long double2int (double in)
99+ { long retval ;
100+
101+ __asm__ __volatile__
102+ ( "fistpl %0"
103+ : "=m" (retval)
104+ : "t" (in)
105+ : "st"
106+ ) ;
107+
108+ return retval ;
109+ } /* double2int */
110+
111+ static inline long float2int (float in)
112+ { long retval ;
113+
114+ __asm__ __volatile__
115+ ( "fistpl %0"
116+ : "=m" (retval)
117+ : "t" (in)
118+ : "st"
119+ ) ;
120+
121+ return retval ;
122+ } /* float2int */
123+
74124 #elif (defined (WIN32) || defined (_WIN32))
75125
76126 #undef HAVE_LRINT_REPLACEMENT
77127 #define HAVE_LRINT_REPLACEMENT 1
128+
78129 #include <math.h>
79130
80131 /*
@@ -156,7 +207,7 @@ · 75 unmodified lines
156207 #define lrint double2int
157208 #define lrintf float2int
158209
159− inline static long int
210+ inline static long
160211 float2int (register float in)
161212 { int res [2] ;
162213
@@ -171,7 +222,7 @@ · 8 unmodified lines
171222 return res [1] ;
172223 } /* lrintf */
173224
174− inline static long int
225+ inline static long
175226 double2int (register double in)
176227 { int res [2] ;
177228
@@ -200,6 +251,7 @@ · 22 unmodified lines
200251 #endif
201252
202253
254+#endif /* FLOAT_CAST_HEADER */
203255
204256 /*
205257 ** Do not edit or modify anything in this comment block.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t