this repo has no description
1// double rint(double x)
2//
3// returns the argument rounded to an integral value using the prevailing
4// rounding mode. rintf is allowed to raise the "inexact" flag if the result
5// differs from the argument (C99 7.12.9.4).
6//
7// -- Stephen Canon, January 2010
8
9.globl _rint
10
11#if defined __i386__
12
13.text
14.align 4
15_rint:
16 fldl 4(%esp)
17 frndint
18 ret
19
20#elif defined __x86_64__
21
22.literal8
23absmask: .quad 0x7fffffffffffffff
24twop52: .quad 0x4330000000000000
25
26.text
27.align 4
28_rint:
29 movd %xmm0, %rcx
30 mov %rcx, %rdx
31 and absmask(%rip), %rcx // |x|
32 xor %rcx, %rdx // signbit(x)
33 movd %rdx, %xmm1
34 cmp twop52(%rip), %rcx // if |x| >= 0x1.0p52 or isnan(x)
35 jae L_xIsIntegral // just return x
36
37 cvtsd2si %xmm0, %rax
38 cvtsi2sd %rax, %xmm0
39 orpd %xmm1, %xmm0 // restore signbit
40L_xIsIntegral:
41 ret
42
43#else
44 #error "this implementation only supports 32- and 64-bit intel."
45#endif