|
|
1.1 root 1: //////////
2: / libc/crt/i386/_modf.s
3: / i386 C compiler library.
4: / IEEE software floating point support.
5: //////////
6:
7: //////////
8: / double _modf(real, dp, exp) double real; double *dp; int exp;
9: /
10: / Stores g == greatest integer <= real through dp and returns real - g.
11: / This assumes real >= 0, 1 <= exp = exponent(real) <= DMBITS+1,
12: / where DMBITS is the number of mantissa bits in a double.
13: / modf.c deals with the other cases.
14: //////////
15:
16: d .equ 4
17: dp .equ d+8
18: exp .equ dp+4
19: EXPMASK .equ 0x7FF00000
20: MANMASK .equ 0x000FFFFF
21: HIDDEN .equ 0x00100000
22: DEFEXP .equ 1022
23: DMBITS .equ 52
24:
25: .globl _modf
26:
27: _modf:
28: movl %edx, d+4(%esp)
29: andl %edx, $MANMASK
30: movl %eax, d(%esp) / mantissa to EDX:EAX
31: movl %ecx, $DMBITS+1 / mantissa bits
32: subl %ecx, exp(%esp) / bits in integer result to ECX
33:
34: / Shift EDX:EAX right to clobber unwanted digits.
35: shrd %eax, %edx, %cl / shift by CL mod 32
36: shrl %edx, %cl
37: cmpl %ecx, $32
38: jl ?L0
39: subl %eax, %eax / zap lo dword, same effect as long shifts
40: ?L0:
41: shld %edx, %eax, %cl / shift back to original position
42: shll %eax, %cl
43:
44: / EDX:EAX contains the integer part mantissa, now supply the exponent.
45: movl %ecx, d+4(%esp)
46: andl %ecx, $EXPMASK / grab old exponent
47: orl %edx, %ecx / combine mantissa and exponent
48: movl %ecx, dp(%esp) / destination to ECX
49: movl 4(%ecx), %edx
50: movl (%ecx), %eax / store integer part through dp
51:
52: / Compute remainder. First, shift away the integer part bits.
53: movl %edx, d+4(%esp)
54: movl %eax, d(%esp) / mantissa to EDX:EAX
55: movl %ecx, exp(%esp) / exponent to ECX
56: cmpl %ecx, $32
57: jl ?L1
58: movl %edx, %eax / shift EDX:EAX 32 bits left
59: subl %eax, %eax
60: ?L1:
61: shld %edx, %eax, %cl / first fraction digit to hidden bit
62: shll %eax, %cl / shift by CL mod 32
63: movl %ecx, $DEFEXP / default exponent to ECX
64: andl %edx, $MANMASK|HIDDEN / mask result
65: jnz ?loop
66: orl %eax, %eax
67: jz ?done / no bits left, return 0
68:
69: / Normalize. This should use "bsrl" but currently uses a loop instead.
70: ?loop:
71: testl %edx, $HIDDEN / watch for hidden bit
72: jnz ?pack
73: shld %edx, %eax, $1
74: shll %eax, $1 / shift left one bit
75: decl %ecx / and adjust the exponent
76: jmp ?loop / and repeat until hidden bit appears
77:
78: ?pack:
79: andl %edx, $MANMASK / mask
80: shll %ecx, $20
81: orl %edx, %ecx / and supply appropriate exponent
82: ?done:
83: ret
84:
85: / end of libc/crt/i386/_modf.s
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.