1 /*
2 Copyright (c) 2007 Dave Korn
3 
4 
5 x87 FP implementation contributed to Newlib by
6 Dave Korn, November 2007.  This file is placed in the
7 public domain.  Permission to use, copy, modify, and
8 distribute this software is freely granted.
9  */
10 /*
11  * ====================================================
12  * x87 FP implementation contributed to Newlib by
13  * Dave Korn, November 2007.  This file is placed in the
14  * public domain.  Permission to use, copy, modify, and
15  * distribute this software is freely granted.
16  * ====================================================
17  */
18 
19 #if defined(__GNUC__) && !defined(_SOFT_FLOAT)
20 
21 #include <math.h>
22 
23 /*
24 FUNCTION
25 <<lrint>>, <<lrintf>>, <<lrintl>>---round and convert to long integer
26 INDEX
27 	lrint
28 INDEX
29 	lrintf
30 INDEX
31 	lrintl
32 
33 SYNOPSIS
34 	#include <math.h>
35 	long int lrint(double x);
36         long int lrintf(float x);
37         long int lrintl(long double x);
38 
39 DESCRIPTION
40 The <<lrint>>, <<lrintf>> and <<lrintl>> functions round <[x]> to the nearest integer value,
41 according to the current rounding direction. If the rounded value is outside the
42 range of the return type, the numeric result is unspecified. A range error may
43 occur if the magnitude of <[x]> is too large.
44 
45 RETURNS
46 These functions return the rounded integer value of <[x]>.
47 <<lrint>>, <<lrintf>> and <<lrintl>> return the result as a long integer.
48 
49 PORTABILITY
50 <<lrint>>, <<lrintf>>, and <<lrintl>> are ANSI.
51 <<lrint>> and <<lrintf>> are available on all platforms.
52 <<lrintl>> is only available on i386 platforms when hardware
53 floating point support is available and when compiling with GCC.
54 
55 */
56 
57 /*
58  * Fast math version of lrint(x)
59  * Return x rounded to integral value according to the prevailing
60  * rounding mode.
61  * Method:
62  *	Using inline x87 asms.
63  * Exception:
64  *	Governed by x87 FPCR.
65  */
66 
_f_lrint(double x)67 long int _f_lrint (double x)
68 {
69   long int _result;
70   __asm__("fistpl %0" : "=m" (_result) : "t" (x) : "st");
71   return _result;
72 }
73 
74 #endif  /* !__GNUC__ || _SOFT_FLOAT */
75 
76