|
|
1.1 root 1:
2:
3: /* modf.x 4.2 84/02/27 */
4:
5: /*
6: * double modf (value, iptr)
7: * double value, *iptr;
8: *
9: * Modf returns the fractional part of "value",
10: * and stores the integer part indirectly through "iptr".
11: */
12: #include <machine/fp.h>
13:
14: .text
15: .globl _modf
16: _modf: .word 0x1ffc /* we use r2,r3,r4,r5 */
17:
18: /*
19: * Some initializations:
20: */
21: ldd 4(fp) /* load accumulator, for converison */
22: cvdl r2 /* to an integer. */
23: bvs gsb /* iff too big grunt it out */
24: cvld r2 /* float the integer part */
25: std r2
26: ldd 4(fp) /* isolate the fraction */
27: subd r2
28: std r0
29: movl 12(fp),r6 /* get int return address */
30: movl r2,(r6)
31: movl r3,4(r6)
32: ret
33: gsb: clrl r3
34: movl 4(fp),r0 /* fetch operand to r0,r1. */
35: movl 8(fp),r1
36: movl 12(fp),r6 /* fetch addr of int to r6. */
37: /*
38: * get exponent
39: */
40: andl3 $EXPMASK,r0,r2 /* r2 will hold the exponent. */
41: jeql is_reserved /* check for reserved operand. */
42: shrl $EXPSHIFT,r2,r2
43: subl2 $BIAS,r2 /* unbias it. */
44: jleq allfrac /* it's int part is zero. */
45: cmpl r2,$56
46: jgeq allint /* it's fraction part is zero. */
47: /*
48: * get fraction
49: */
50: movl r0,r4 /* remember the original number. */
51: movl r1,r5
52: bbc $31,r0,positive /* if negative remember it. */
53: incl r3
54: positive:
55: /* clear the non fraction parts. */
56: andl2 $(0!(EXPMASK | SIGNBIT)),r0
57: /* add the hidden bit. */
58: orl2 $(0!CLEARHID),r0
59:
60: cmpl r2,$HID_POS /* see if there are bits to clear only in r0 */
61: /* or r1 has to be taken care of. */
62: /* ( for fraction calculation) */
63:
64: jgtr in_r1 /* some bytes in r1. */
65:
66: jeql onlyallr0 /* all r0 must be cleared,r1 unchanged. */
67:
68: /* only r0 must be canged. */
69: mnegl r2,r7 /* r7 - loop counter. */
70: movl $CLEARHID,r8 /* first bit to clear. */
71: 1:
72: andl2 r8,r0 /* clear int. bits from fraction part. */
73: shar $1,r8,r8
74: aoblss $0,r7,1b
75: 1:
76: andl2 r8,r4 /* clear frac bits for int calculation: */
77: shar $1,r8,r8
78: cmpl $0xffffffff,r8
79: jneq 1b
80: clrl r5
81: jmp norm
82:
83: onlyallr0:
84: clrl r0
85: clrl r5
86: jmp norm
87:
88: in_r1:
89: clrl r0 /* clear int part for frac. calculation. */
90: subl3 r2,$HID_POS,r7
91: movl $0x7fffffff,r8
92: 1:
93: andl2 r8,r1
94: shar $1,r8,r8
95: orl2 $0x80000000,r8 /* force the 'sign' bit to be on. */
96: aoblss $0,r7,1b
97: 1:
98: andl2 r8,r5
99: shar $1,r8,r8
100: cmpl $0xffffffff,r8
101: jneq 1b
102:
103: norm:
104: addl2 $BIAS,r2 /* fnorm expects it biased. */
105: callf $4,fnorm /* normelize fraction part. */
106: cmpl $0,r0
107: jeql 1f
108: bbc $0,r3,1f
109: orl2 $0x80000000,r0
110: 1:
111: movl r4,(r6) /* put int part in place. */
112: movl r5,4(r6)
113: ret
114:
115: allint:
116: movl r0,(r6) /* copy the argument to the int addr. */
117: movl r1,4(r6)
118: clrl r0 /* clear the fraction part. */
119: clrl r1
120: ret
121:
122: allfrac:
123: /* the fraction is ready in r0,r1. */
124: clrl (r6) /* zero the int part. */
125: clrl 4(r6)
126: ret
127:
128:
129:
130:
131:
132: ret_zero:
133: clrl (r6)
134: clrl 4(r6)
135: clrl r0
136: clrl r1
137: ret
138:
139: is_reserved:
140: bbc $31,r0,ret_zero
141: callf $4,fpresop
142: ret
143:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.