Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/i386/src/round.s
+++ new/usr/src/lib/libm/i386/src/round.s
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
23 23 */
24 24 /*
25 25 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 29 .file "round.s"
30 30
31 31 #include "libm.h"
32 32 LIBM_ANSI_PRAGMA_WEAK(round,function)
33 -#include "libm_synonyms.h"
34 -#undef fabs
35 33
36 34 .section .rodata
37 35 .align 4
38 36 .Lhalf: .float 0.5
39 37
40 38 ENTRY(round)
41 39 movl %esp,%ecx
42 40 subl $8,%esp
43 41 fstcw -8(%ecx)
44 42 fldl 4(%ecx)
45 43 movw -8(%ecx),%dx
46 44 andw $0xf3ff,%dx
47 45 movw %dx,-4(%ecx)
48 46 fldcw -4(%ecx) / set RD = to_nearest
49 47 fld %st(0)
50 48 frndint / [x],x
51 49 fstcw -4(%ecx)
52 50 movw -4(%ecx),%dx
53 51 andw $0xf3ff,%dx
54 52 movw -8(%ecx),%ax
55 53 andw $0x0c00,%ax
56 54 orw %dx,%ax
57 55 movw %ax,-8(%ecx)
58 56 fldcw -8(%ecx) / restore RD
59 57 fucom / check if x is already an integer
60 58 fstsw %ax
61 59 sahf
62 60 jp 0f
63 61 je 0f
64 62 fxch / x,[x]
65 63 fsub %st(1),%st / x-[x],[x]
66 64 fabs / |x-[x]|,[x]
67 65 PIC_SETUP(1)
68 66 fcoms PIC_L(.Lhalf)
69 67 PIC_WRAPUP
70 68 fnstsw %ax
71 69 sahf
72 70 jae 2f / if |x-[x]| = 0.5 goto halfway,
73 71 / most cases will not take branch.
74 72 0:
75 73 addl $8,%esp
76 74 fstp %st(0)
77 75 ret
78 76 2:
79 77 / x = n+0.5, recompute round(x) as x+sign(x)*0.5
80 78 fldl 4(%ecx) / x, 0.5, [x]
81 79 movl 8(%ecx),%eax / high part of x
82 80 andl $0x80000000,%eax
83 81 jnz 3f
84 82 faddp
85 83 addl $8,%esp
86 84 fstp %st(1)
87 85 ret
88 86 3:
89 87 / here, x is negative, so return x-0.5
90 88 fsubp %st,%st(1) / x-0.5,[x]
91 89 addl $8,%esp
92 90 fstp %st(1)
93 91 ret
94 92 .align 4
95 93 SET_SIZE(round)
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX