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 #include "f_math.h"
23 
24 /*
25 FUNCTION
26 <<lrint>>, <<lrintf>>, <<lrintl>>---round and convert to long integer
27 INDEX
28 	lrint
29 INDEX
30 	lrintf
31 INDEX
32 	lrintl
33 
34 SYNOPSIS
35 	#include <math.h>
36 	long int lrint(double x);
37         long int lrintf(float x);
38         long int lrintl(long double x);
39 
40 DESCRIPTION
41 The <<lrint>>, <<lrintf>> and <<lrintl>> functions round <[x]> to the nearest integer value,
42 according to the current rounding direction. If the rounded value is outside the
43 range of the return type, the numeric result is unspecified. A range error may
44 occur if the magnitude of <[x]> is too large.
45 
46 RETURNS
47 These functions return the rounded integer value of <[x]>.
48 <<lrint>>, <<lrintf>> and <<lrintl>> return the result as a long integer.
49 
50 PORTABILITY
51 <<lrint>>, <<lrintf>>, and <<lrintl>> are ANSI.
52 <<lrint>> and <<lrintf>> are available on all platforms.
53 <<lrintl>> is only available on i386 platforms when hardware
54 floating point support is available and when compiling with GCC.
55 
56 */
57 
58 /*
59  * Fast math version of lrint(x)
60  * Return x rounded to integral value according to the prevailing
61  * rounding mode.
62  * Method:
63  *	Using inline x87 asms.
64  * Exception:
65  *	Governed by x87 FPCR.
66  */
67 
_f_lrint(double x)68 long int _f_lrint (double x)
69 {
70   long int _result;
71   __asm__("fistpl %0" : "=m" (_result) : "t" (x) : "st");
72   return _result;
73 }
74 
75 #endif  /* !__GNUC__ || _SOFT_FLOAT */
76 
77