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 | include mdef.inc |
||
34 | include struct.inc |
||
35 | |||
36 | modstart i8fs386 |
||
37 | |||
38 | xref __I8LS |
||
39 | xref __I8RS |
||
40 | |||
41 | ; Convert signed 64-bit integer to single precision float |
||
42 | ; Input: [EDX, EAX] = 64-bit integer |
||
43 | ; Output: [EAX] = 32-bit float |
||
44 | |||
45 | xdefp __I8FS |
||
46 | defp __I8FS |
||
47 | or EDX,EDX ; check sign |
||
48 | jns __U8FS ; if positive, just convert |
||
49 | neg EDX ; |
||
50 | neg EAX ; take absolute value of number |
||
51 | sbb EDX,0 ; |
||
52 | call __U8FS ; convert to FS |
||
53 | or EAX,80000000h ; set sign bit on |
||
54 | ret ; return |
||
55 | endproc __I8FS |
||
56 | |||
57 | ; Convert unsigned 64-bit integer to single precision float |
||
58 | ; Input: [EDX, EAX] = 64-bit integer |
||
59 | ; Output: [EAX] = 32-bit float |
||
60 | |||
61 | xdefp __U8FS |
||
62 | defp __U8FS |
||
63 | or EAX,EAX ; if lo is zero |
||
64 | _if e ; |
||
65 | or EDX,EDX ; and if hi is zero |
||
66 | _if e ; |
||
67 | ret ; - return |
||
68 | _endif |
||
69 | _endif ; endif |
||
70 | push ECX ; save ECX |
||
71 | push EBX ; save EBX |
||
72 | bsr ECX,EDX ; find most significant non-zero bit in hi |
||
73 | _if e ; if all zero bits |
||
74 | bsr ECX,EAX ; - find most significant non-zero bit in lo |
||
75 | _else ; else |
||
76 | add CL,32 ; - adjust shift count since hi was not 0 |
||
77 | _endif ; endif |
||
78 | push ECX ; save shift count |
||
79 | neg CL ; calculate # of bits to shift by |
||
80 | add CL,63-8 ; ... |
||
81 | mov EBX,ECX ; set up for call |
||
82 | or CL,CL ; if mantissa should move left |
||
83 | _if ge ; then |
||
84 | call __I8LS ; - shift left |
||
85 | _else ; else |
||
86 | neg BL ; - make positive |
||
87 | call __I8RS ; - shift right |
||
88 | _endif ; endif |
||
89 | pop ECX ; restore shift count |
||
90 | and EDX,007FFFFFh ; mask out sign and exponent bits |
||
91 | add CL,127 ; calculate exponent (excess 127) |
||
92 | ; and ECX,0FFh ; isolate exponent (not required) |
||
93 | shl ECX,23 ; shift exponent into position |
||
94 | or EDX,ECX ; place into result |
||
95 | mov EAX,EDX ; single precision is only 32 bits |
||
96 | pop EBX ; restore EBX |
||
97 | pop ECX ; restore ECX |
||
98 | ret ; return |
||
99 | endproc __U8FS |
||
100 | |||
101 | endmod |
||
102 | end |