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 | ; from double to signed/unsigned int64 |
||
35 | ; |
||
36 | include mdef.inc |
||
37 | include struct.inc |
||
38 | |||
39 | modstart fdi8386 |
||
40 | |||
41 | xref __U8LS |
||
42 | xref __U8RS |
||
43 | |||
44 | ; Convert double precision float to unsigned 64-bit integer with truncation |
||
45 | ; Input: [EDX, EAX] = 64-bit float |
||
46 | ; Output: [EDX, EAX] = 64-bit integer |
||
47 | |||
48 | xdefp __FDU8 |
||
49 | defp __FDU8 |
||
50 | push ECX ; save ECX |
||
51 | mov CX,3ffh+64 ; maximum number 2^64-1 |
||
52 | call __FDU ; convert float to unsigned __int64 |
||
53 | pop ECX ; restore ECX |
||
54 | ret ; return |
||
55 | endproc __FDU8 |
||
56 | |||
57 | ; Convert double precision float to signed 64-bit integer with truncation |
||
58 | ; Input: [EDX, EAX] = 64-bit float |
||
59 | ; Output: [EDX, EAX] = 64-bit integer |
||
60 | |||
61 | xdefp __FDI8 |
||
62 | defp __FDI8 |
||
63 | push ECX ; save ECX |
||
64 | mov CX,3ffh+63 ; maximum number 2^63-1 |
||
65 | call __FDI ; convert float to signed __int64 |
||
66 | pop ECX ; restore ECX |
||
67 | ret ; return |
||
68 | endproc __FDI8 |
||
69 | |||
70 | __FDI proc near |
||
71 | __FDU: ; what? they both do the same thing |
||
72 | or EDX,EDX ; check sign bit |
||
73 | jns short __FDAbs ; treat as unsigned if positive |
||
74 | call __FDAbs ; otherwise convert number |
||
75 | neg EDX ; negate the result |
||
76 | neg EAX ; |
||
77 | sbb EDX,0 ; |
||
78 | ret ; return |
||
79 | endproc __FDI |
||
80 | |||
81 | __FDAbs proc near |
||
82 | or EAX,EAX ; check if number 0 |
||
83 | jne short notzero ; |
||
84 | or EDX,EDX ; check if number 0 |
||
85 | jne short notzero ; |
||
86 | ret |
||
87 | notzero: |
||
88 | push EBX ; save EBX |
||
89 | _shl EDX,1 ; shift mantissa over |
||
90 | rol EDX,11 ; get exponent to bottom |
||
91 | mov BX,DX ; copy and isolate |
||
92 | and BX,07ffh ; exponent |
||
93 | cmp BX,3ffh ; quit if number < 1.0 |
||
94 | jb short dbluflow ; ... |
||
95 | stc ; set carry for implied bit |
||
96 | rcr EDX,1 ; put implied '1' bit in |
||
97 | shr EDX,11 ; remove exponent and extra bit |
||
98 | cmp BX,CX ; check if exponent exceeds maximum |
||
99 | jae short dblmax ; return maximum value if so |
||
100 | sub BX,3ffh+52 ; calculate amount to shift (+ve -> left) |
||
101 | jae short dblm_left ; jump if left shift/no shift |
||
102 | neg BX ; make positive |
||
103 | call __U8RS ; shift mantissa right |
||
104 | pop EBX ; restore EBX |
||
105 | ret ; return |
||
106 | |||
107 | dblm_left: |
||
108 | _if ne ; done if exponent exactly 55 |
||
109 | call __U8LS ; - shift mantissa left |
||
110 | _endif ; endif |
||
111 | pop EBX ; restore EBX |
||
112 | ret ; return |
||
113 | |||
114 | ; CX = 3ffh+64 for unsigned |
||
115 | ; 3ffh+63 for signed |
||
116 | dblmax: |
||
117 | mov EAX,0FFFFFFFFh ; return maximum value |
||
118 | mov EDX,EAX ; |
||
119 | sub CX,3fFh+64 ; subtract bias + 64, results in 0 or -1 |
||
120 | neg CX ; get shift count |
||
121 | mov BX,CX ; set shift count |
||
122 | call __U8RS ; shift mantissa right 1 bit for signed |
||
123 | pop EBX ; restore EBX |
||
124 | ret ; return |
||
125 | |||
126 | dbluflow: |
||
127 | sub EAX,EAX ; ensure entire number 0 |
||
128 | sub EDX,EDX ; |
||
129 | pop EBX ; restore EBX |
||
130 | ret ; return |
||
131 | |||
132 | endproc __FDAbs |
||
133 | |||
134 | ; Convert double precision float to unsigned 64-bit integer with rounding |
||
135 | ; Input: [EDX, EAX] = 64-bit float |
||
136 | |||
137 | ; xdefp __RDU8 |
||
138 | ; defp __RDU8 |
||
139 | ; not implemented |
||
140 | ; endproc __RDU8 |
||
141 | |||
142 | ; Convert double precision float to signed 64-bit integer with rounding |
||
143 | ; Input: [EDX, EAX] = 64-bit float |
||
144 | |||
145 | ; xdefp __RDI8 |
||
146 | ; defp __RDI8 |
||
147 | ; not implemented |
||
148 | ; endproc __RDI8 |
||
149 | |||
150 | endmod |
||
151 | end> |