Merge remote-tracking branch 'remotes/origin/cairocanvas' into windows
[ardour.git] / msvc_extra_headers / ardourext / float_cast.h.input
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 #ifndef __FLOAT_CAST_H__  // Added by JE - 30-11-2009
38 #define __FLOAT_CAST_H__
39 #if (defined (WIN32) || defined (_WIN32))
40
41         #include        <math.h>
42
43         /*      Win32 doesn't seem to have these functions.
44         **      Therefore implement inline versions of these functions here.
45         */
46
47         __inline long int
48         lrint (double flt)
49         {       int intgr;
50
51                 _asm
52                 {       fld flt
53                         fistp intgr
54                         } ;
55
56                 return intgr ;
57         }
58
59         __inline long int
60         lrintf (float flt)
61         {       int intgr;
62
63                 _asm
64                 {       fld flt
65                         fistp intgr
66                         } ;
67
68                 return intgr ;
69         }
70
71         __inline long long int 
72         llrint (double flt)
73         {       long long int intgr;
74
75                 _asm
76                 {       fld flt
77                         fistp intgr
78                         } ;
79                         
80                 return intgr ;
81         } 
82         
83         __inline long long int 
84         llrintf (float flt)
85         {       long long int intgr;
86
87                 _asm
88                 {       fld flt
89                         fistp intgr
90                         } ;
91                         
92                 return intgr ;
93         }
94 #endif
95
96 #endif  // __FLOAT_CAST_H__