Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
553 | serge | 1 | ;***************************************************************************** |
2 | ;* |
||
3 | ;* Open Watcom Project |
||
4 | ;* |
||
5 | ;* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. |
||
6 | ;* |
||
7 | ;* ======================================================================== |
||
8 | ;* |
||
9 | ;* This file contains Original Code and/or Modifications of Original |
||
10 | ;* Code as defined in and that are subject to the Sybase Open Watcom |
||
11 | ;* Public License version 1.0 (the 'License'). You may not use this file |
||
12 | ;* except in compliance with the License. BY USING THIS FILE YOU AGREE TO |
||
13 | ;* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is |
||
14 | ;* provided with the Original Code and Modifications, and is also |
||
15 | ;* available at www.sybase.com/developer/opensource. |
||
16 | ;* |
||
17 | ;* The Original Code and all software distributed under the License are |
||
18 | ;* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
||
19 | ;* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM |
||
20 | ;* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF |
||
21 | ;* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR |
||
22 | ;* NON-INFRINGEMENT. Please see the License for the specific language |
||
23 | ;* governing rights and limitations under the License. |
||
24 | ;* |
||
25 | ;* ======================================================================== |
||
26 | ;* |
||
27 | ;* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE |
||
28 | ;* DESCRIBE IT HERE! |
||
29 | ;* |
||
30 | ;***************************************************************************** |
||
31 | |||
32 | |||
33 | ;======================================================================== |
||
34 | ;== Name: FSI4, FSU4, FSI2, FSU2, FSI1, FSU1 == |
||
35 | ;== Operation: Convert single precision to integer == |
||
36 | ;== Inputs: EAX single precision floating point == |
||
37 | ;== Outputs: EAX integer value == |
||
38 | ;== Volatile: none == |
||
39 | ;== == |
||
40 | ;== == |
||
41 | ;== handle -1.0 -> 0xffffffff == |
||
42 | ;======================================================================== |
||
43 | include mdef.inc |
||
44 | include struct.inc |
||
45 | |||
46 | modstart fsi4386 |
||
47 | |||
48 | xdefp __FSI4 |
||
49 | xdefp __FSU4 |
||
50 | xdefp __FSI2 |
||
51 | xdefp __FSU2 |
||
52 | xdefp __FSI1 |
||
53 | xdefp __FSU1 |
||
54 | |||
55 | defpe __FSI4 |
||
56 | push ECX ; save cx |
||
57 | mov cl,7fh+31 ; maximum number 2^31-1 |
||
58 | call __FSI ; convert to integer |
||
59 | pop ECX ; restore cx |
||
60 | ret ; return (overflow already handled |
||
61 | endproc __FSI4 |
||
62 | |||
63 | defpe __FSU4 |
||
64 | push ECX ; save cx |
||
65 | mov cl,7fh+32 ; maximum number 2^32-1 |
||
66 | call __FSU ; convert to integer |
||
67 | pop ECX ; restore cx |
||
68 | ret ; return if no overflow |
||
69 | endproc __FSU4 |
||
70 | |||
71 | defpe __FSI2 |
||
72 | push ECX ; save cx |
||
73 | mov cl,7fh+15 ; maximum number 2^15-1 |
||
74 | call __FSI ; convert to integer |
||
75 | pop ECX ; restore cx |
||
76 | ret ; return (overflow already handled |
||
77 | endproc __FSI2 |
||
78 | |||
79 | defpe __FSU2 |
||
80 | push ECX ; save cx |
||
81 | mov cl,7fh+16 ; maximum number 2^16-1 |
||
82 | call __FSU ; convert to integer |
||
83 | pop ECX ; restore cx |
||
84 | ret ; return if no overflow |
||
85 | endproc __FSU2 |
||
86 | |||
87 | defpe __FSI1 |
||
88 | push ECX ; save cx |
||
89 | mov cl,7fh+7 ; maximum number 2^7-1 |
||
90 | call __FSI ; convert to integer |
||
91 | pop ECX ; restore cx |
||
92 | ret ; return (overflow already handled |
||
93 | endproc __FSI1 |
||
94 | |||
95 | |||
96 | defpe __FSU1 |
||
97 | push ECX ; save cx |
||
98 | mov cl,7fh+8 ; maximum number 2^8-1 |
||
99 | call __FSU ; convert to integer |
||
100 | pop ECX ; restore cx |
||
101 | ret ; return if no overflow |
||
102 | endproc __FSU1 |
||
103 | |||
104 | __FSI proc near |
||
105 | __FSU: |
||
106 | or EAX,EAX ; check sign bit |
||
107 | jns short __FSAbs ; treat as unsigned if positive |
||
108 | call __FSAbs ; otherwise convert number |
||
109 | neg EAX ; negate the result |
||
110 | ret ; and return |
||
111 | endproc __FSI |
||
112 | |||
113 | ; 18-nov-87 AFS (for WATCOM C) |
||
114 | ;__FSU proc near |
||
115 | ; jmp |
||
116 | ; or dx,dx ; check sign bit |
||
117 | ; jns __FSAbs ; just convert if positive |
||
118 | ; sub ax,ax ; return 0 if negative |
||
119 | ; sub dx,dx ; ... |
||
120 | ; ret |
||
121 | ; endproc __FSU |
||
122 | |||
123 | ;======================================================================== |
||
124 | ;== Name: FSAbs_ == |
||
125 | ;== Inputs: EAX float == |
||
126 | ;== CL maximum exponent excess $7f == |
||
127 | ;== Outputs: EAX integer, absolute value of float == |
||
128 | ;== if exponent >= maximum then 2^max - 1 == |
||
129 | ;== returned == |
||
130 | ;======================================================================== |
||
131 | |||
132 | __FSAbs proc near |
||
133 | or EAX,EAX ; check if number 0 |
||
134 | je short retzero ; if so, just return it |
||
135 | _shl EAX,1 ; shift mantissa over |
||
136 | rol EAX,8 ; get exponent to bottom |
||
137 | cmp AL,7fh ; quit if number < 1.0 15-apr-91 |
||
138 | jb short uflow ; ... |
||
139 | mov CH,AL ; save exponent |
||
140 | stc ; set carry for implied bit |
||
141 | rcr EAX,1 ; put implied '1' bit in |
||
142 | shr EAX,8 ; remove exponent |
||
143 | cmp CH,CL ; check if exponent exceeds maximum |
||
144 | jae short retmax ; return maximum value if so |
||
145 | sub CH,7fh+23 ; calculate amount to shift (+ve -> left) |
||
146 | jae short m_left ; jump if left shift/no shift |
||
147 | xchg CH,CL ; get shift count |
||
148 | neg CL ; make positive |
||
149 | shr EAX,CL ; shift mantissa |
||
150 | ret ; return with number |
||
151 | |||
152 | m_left: |
||
153 | _if ne ; done if exponent exactly 23 |
||
154 | mov CL,CH ; - get shift count |
||
155 | shl EAX,CL ; - shift number left |
||
156 | _endif ; endif |
||
157 | ret ; return |
||
158 | |||
159 | retmax: mov EAX,0FFFFFFFFh ; return maximum value |
||
160 | sub CL,7Fh+32 ; subtract bias + 32 |
||
161 | neg CL ; get shift count |
||
162 | shr EAX,CL ; compute value |
||
163 | ret ; return |
||
164 | |||
165 | uflow: |
||
166 | retzero:sub EAX,EAX ; ensure entire number 0 |
||
167 | ret ; return |
||
168 | endproc __FSAbs |
||
169 | |||
170 | endmod |
||
171 | end> |