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