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