Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
554 | 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 fdmd386 |
||
37 | |||
38 | xdefp "C",_dieeetomsbin |
||
39 | defpe _dieeetomsbin |
||
40 | |||
41 | ifdef __STACK__ |
||
42 | mov eax,dword ptr +4H[esp] ; load src double ptr |
||
43 | mov edx,dword ptr +8H[esp] ; load dst double ptt |
||
44 | else |
||
45 | push ecx ; save register |
||
46 | endif |
||
47 | |||
48 | ; At this point: |
||
49 | ; eax - ptr to IEEE source double |
||
50 | ; edx - ptr to MBF dest double |
||
51 | ; ecx - spare register |
||
52 | |||
53 | ; Check for IEEE Underflow first |
||
54 | mov ecx,+4h[eax] ; load IEEE double (hi) |
||
55 | rol ecx,1 ; rotate sign bit away for comparisons |
||
56 | cmp ecx,6fe00000H ; exponent < 1023 - 128 ? |
||
57 | jae IEEENoUnderflow ; yes, jump |
||
58 | |||
59 | ; IEEE Underflow, store MBF 0.0 |
||
60 | xor eax,eax ; make 0 |
||
61 | mov [edx],eax ; store MBF 0.0 (lo) |
||
62 | mov +4h[edx],eax ; store MBF 0.0 (hi) |
||
63 | ifndef __STACK__ |
||
64 | pop ecx ; clean up |
||
65 | endif |
||
66 | ret ; return 0 (no overflow) |
||
67 | |||
68 | ; Check for IEEE Overflow |
||
69 | IEEENoUnderflow: |
||
70 | cmp ecx,8fc00000H ; exponent >= 1023 + 127 ? |
||
71 | jae IEEEOverflow ; yes, jump |
||
72 | |||
73 | ; General IEEE case, load rest of double |
||
74 | mov eax,[eax] ; load IEEE double (lo) |
||
75 | ror ecx,1 ; rotate sign bit back into place |
||
76 | |||
77 | ; At this point: |
||
78 | ; ecx:eax - IEEE source double |
||
79 | ; edx - ptr to MBF dest double |
||
80 | |||
81 | push ecx ; save sign bit |
||
82 | |||
83 | ; shift exponent & mantissa into place |
||
84 | shld ecx,eax,3 ; shift exponent and mantissa |
||
85 | shl eax,3 ; : |
||
86 | mov [edx],eax ; save mantissa |
||
87 | rol ecx,9 ; convert IEEE exponent to MBF |
||
88 | shr ecx,1 ; : |
||
89 | adc cl,cl ; : |
||
90 | add cl,82h ; correct MBF exponent |
||
91 | pop eax ; restore sign bit |
||
92 | add eax,eax ; shift sign bit into carry |
||
93 | adc ecx,ecx ; add in sign bit |
||
94 | ror ecx,9 ; MBF double (hi) |
||
95 | mov +4h[edx],ecx ; store MBF double (hi) |
||
96 | xor eax,eax ; 0 |
||
97 | ifndef __STACK__ |
||
98 | pop ecx ; clean up |
||
99 | endif |
||
100 | ret ; return 0 (no overflow) |
||
101 | |||
102 | ; IEEE Overflow, store maximum MBF, preserving sign |
||
103 | IEEEOverflow: or ecx,0FFFFFFFFEh ; set MBF exponent and mantissa to maximum |
||
104 | mov eax,ecx ; : |
||
105 | ror ecx,9 ; rotate sign bit into place for MBF |
||
106 | sar eax,1 ; now -1 |
||
107 | mov +4h[edx],ecx ; store IEEE double (hi) |
||
108 | mov [edx],eax ; store IEEE double (lo) |
||
109 | neg eax ; 1 |
||
110 | ifndef __STACK__ |
||
111 | pop ecx ; clean up |
||
112 | endif |
||
113 | ret ; return 1 (overflow) |
||
114 | |||
115 | endproc _dieeetomsbin |
||
116 | |||
117 | endmod |
||
118 | end> |