Merge branch 'master' into cairocanvas
[ardour.git] / libs / rubberband / src / bsd-3rdparty / float_cast / float_cast.h
1 /*
2 ** Copyright (C) 2001 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
3 **
4 ** Permission to use, copy, modify, distribute, and sell this file for any 
5 ** purpose is hereby granted without fee, provided that the above copyright 
6 ** and this permission notice appear in all copies.  No representations are
7 ** made about the suitability of this software for any purpose.  It is 
8 ** provided "as is" without express or implied warranty.
9 */
10
11 /* Version 1.1 */
12
13
14 /*============================================================================ 
15 **      On Intel Pentium processors (especially PIII and probably P4), converting
16 **      from float to int is very slow. To meet the C specs, the code produced by 
17 **      most C compilers targeting Pentium needs to change the FPU rounding mode 
18 **      before the float to int conversion is performed. 
19 **
20 **      Changing the FPU rounding mode causes the FPU pipeline to be flushed. It 
21 **      is this flushing of the pipeline which is so slow.
22 **
23 **      Fortunately the ISO C99 specifications define the functions lrint, lrintf,
24 **      llrint and llrintf which fix this problem as a side effect. 
25 **
26 **      On Unix-like systems, the configure process should have detected the 
27 **      presence of these functions. If they weren't found we have to replace them 
28 **      here with a standard C cast.
29 */
30
31 /*      
32 **      The C99 prototypes for lrint and lrintf are as follows:
33 **      
34 **              long int lrintf (float x) ;
35 **              long int lrint  (double x) ;
36 */
37
38 #if (defined (WIN32) || defined (_WIN32))
39
40         #include        <math.h>
41
42         /*      Win32 doesn't seem to have these functions. 
43         **      Therefore implement inline versions of these functions here.
44         */
45         
46         __inline long int 
47         lrint (double flt) 
48         {       int intgr;
49
50                 _asm
51                 {       fld flt
52                         fistp intgr
53                         } ;
54                         
55                 return intgr ;
56         } 
57         
58         __inline long int 
59         lrintf (float flt)
60         {       int intgr;
61
62                 _asm
63                 {       fld flt
64                         fistp intgr
65                         } ;
66                         
67                 return intgr ;
68         }
69
70 #endif
71
72
73