Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DivModHelpers.asm « i386 « Runtime « Native « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91229c26e4bda9542612df41327b63d73c4f57ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
;; Licensed to the .NET Foundation under one or more agreements.
;; The .NET Foundation licenses this file to you under the MIT license.
;; See the LICENSE file in the project root for more information.


        .586
        .model  flat
        option  casemap:none
        .code


include AsmMacros.inc

EXTERN RhExceptionHandling_ThrowClasslibOverflowException                              : PROC
EXTERN RhExceptionHandling_ThrowClasslibDivideByZeroException                          : PROC
EXTERN __alldiv : PROC
EXTERN __allrem : PROC
EXTERN __aulldiv : PROC
EXTERN __aullrem : PROC
EXTERN __aulldvrm : PROC
EXTERN __alldvrm : PROC

esp_offsetof_dividend_low     equ 4
esp_offsetof_dividend_high    equ 8
esp_offsetof_divisor_low      equ 12
esp_offsetof_divisor_high     equ 16

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhpLDiv
;;
;; INPUT:  [ESP+4]: dividend low
;;         [ESP+8]: dividend high
;;         [ESP+12]: divisor low
;;         [ESP+16]: divisor high
;;
;; OUTPUT: EAX: result low
;;         EDX: result high
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FASTCALL_FUNC  RhpLDiv, 16

        ;; pretest for the problematic cases of overflow and divide by zero
        ;; overflow: dividend = 0x80000000`00000000 and divisor = -1l = 0xffffffff`ffffffff
        ;; divide by zero: divisor = 0x00000000`00000000
        ;;
        ;; quick pretest - if the two halves of the divisor are unequal, we cannot
        ;; have one of the problematic cases
        mov     eax,[esp+esp_offsetof_divisor_low]
        cmp     eax,[esp+esp_offsetof_divisor_high]
        je      LDivDoMoreTests
LDivOkToDivide:
        ;; tailcall to the actual divide routine
        jmp     __alldiv
LDivDoMoreTests:
        ;; we know the high and low halves of the divisor are equal
        ;;
        ;; check for the divide by zero case
        test    eax,eax
        je      ThrowClasslibDivideByZeroException
        ;;
        ;; is the divisor == -1l? I.e., can we have the overflow case?
        cmp     eax,-1
        jne     LDivOkToDivide
        ;;
        ;; is the dividend == 0x80000000`00000000?
        cmp     dword ptr [esp+esp_offsetof_dividend_low],0
        jne     LDivOkToDivide
        cmp     dword ptr [esp+esp_offsetof_dividend_high],80000000h
        jne     LDivOkToDivide
FASTCALL_ENDFUNC

        ;; make it look like the managed code called this directly
        ;; by popping the parameters and putting the return address in the proper place
ThrowClasslibOverflowException proc
        pop     ecx
        add     esp,16
        push    ecx
        ;; passing return address in ecx
        jmp     RhExceptionHandling_ThrowClasslibOverflowException
ThrowClasslibOverflowException endp

ThrowClasslibDivideByZeroException proc
        pop     ecx
        add     esp,16
        push    ecx
        ;; passing return address in ecx
        jmp     RhExceptionHandling_ThrowClasslibDivideByZeroException
ThrowClasslibDivideByZeroException endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhpLMod
;;
;; INPUT:  [ESP+4]: dividend low
;;         [ESP+8]: dividend high
;;         [ESP+12]: divisor low
;;         [ESP+16]: divisor high
;;
;; OUTPUT: EAX: result low
;;         EDX: result high
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FASTCALL_FUNC  RhpLMod, 16

        ;; pretest for the problematic cases of overflow and divide by zero
        ;; overflow: dividend = 0x80000000`00000000 and divisor = -1l = 0xffffffff`ffffffff
        ;; divide by zero: divisor = 0x00000000`00000000
        ;;
        ;; quick pretest - if the two halves of the divisor are unequal, we cannot
        ;; have one of the problematic cases
        mov     eax,[esp+esp_offsetof_divisor_low]
        cmp     eax,[esp+esp_offsetof_divisor_high]
        je      LModDoMoreTests
LModOkToDivide:
        jmp     __allrem
LModDoMoreTests:
        ;; we know the high and low halves of the divisor are equal
        ;;
        ;; check for the divide by zero case
        test    eax,eax
        je      ThrowClasslibDivideByZeroException
        ;;
        ;; is the divisor == -1l? I.e., can we have the overflow case?
        cmp     eax,-1
        jne     LModOkToDivide
        ;;
        ;; is the dividend == 0x80000000`00000000?
        cmp     dword ptr [esp+esp_offsetof_dividend_low],0
        jne     LModOkToDivide
        cmp     dword ptr [esp+esp_offsetof_dividend_high],80000000h
        jne     LModOkToDivide
        jmp     ThrowClasslibOverflowException

FASTCALL_ENDFUNC

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhpLDivMod
;;
;; INPUT:  [ESP+4]: dividend low
;;         [ESP+8]: dividend high
;;         [ESP+12]: divisor low
;;         [ESP+16]: divisor high
;;
;; OUTPUT: EAX: quotient low
;;         EDX: quotient high
;;         ECX: remainder high
;;         EBX: remainder high
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FASTCALL_FUNC  RhpLDivMod, 16

        ;; pretest for the problematic cases of overflow and divide by zero
        ;; overflow: dividend = 0x80000000`00000000 and divisor = -1l = 0xffffffff`ffffffff
        ;; divide by zero: divisor = 0x00000000`00000000
        ;;
        ;; quick pretest - if the two halves of the divisor are unequal, we cannot
        ;; have one of the problematic cases
        mov     eax,[esp+esp_offsetof_divisor_low]
        cmp     eax,[esp+esp_offsetof_divisor_high]
        je      LDivModDoMoreTests
LDivModOkToDivide:
        jmp     __alldvrm
LDivModDoMoreTests:
        ;; we know the high and low halves of the divisor are equal
        ;;
        ;; check for the divide by zero case
        test    eax,eax
        je      ThrowClasslibDivideByZeroException
        ;;
        ;; is the divisor == -1l? I.e., can we have the overflow case?
        cmp     eax,-1
        jne     LDivModOkToDivide
        ;;
        ;; is the dividend == 0x80000000`00000000?
        cmp     dword ptr [esp+esp_offsetof_dividend_low],0
        jne     LDivModOkToDivide
        cmp     dword ptr [esp+esp_offsetof_dividend_high],80000000h
        jne     LDivModOkToDivide
        jmp     ThrowClasslibOverflowException

FASTCALL_ENDFUNC

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhpULDiv
;;
;; INPUT:  [ESP+4]: dividend low
;;         [ESP+8]: dividend high
;;         [ESP+12]: divisor low
;;         [ESP+16]: divisor high
;;
;; OUTPUT: EAX: result low
;;         EDX: result high
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FASTCALL_FUNC  RhpULDiv, 16

        ;; pretest for divide by zero
        mov     eax,[esp+esp_offsetof_divisor_low]
        or      eax,[esp+esp_offsetof_divisor_high]
        jne     __aulldiv
        jmp     ThrowClasslibDivideByZeroException        

FASTCALL_ENDFUNC

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhpULMod
;;
;; INPUT:  [ESP+4]: dividend low
;;         [ESP+8]: dividend high
;;         [ESP+12]: divisor low
;;         [ESP+16]: divisor high
;;
;; OUTPUT: EAX: result low
;;         EDX: result high
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FASTCALL_FUNC  RhpULMod, 16

        ;; pretest for divide by zero
        mov     eax,[esp+esp_offsetof_divisor_low]
        or      eax,[esp+esp_offsetof_divisor_high]
        jne     __aullrem
        jmp     ThrowClasslibDivideByZeroException        

FASTCALL_ENDFUNC

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; RhpULDivMod
;;
;; INPUT:  [ESP+4]: dividend low
;;         [ESP+8]: dividend high
;;         [ESP+12]: divisor low
;;         [ESP+16]: divisor high
;;
;; OUTPUT: EAX: quotient low
;;         EDX: quotient high
;;         ECX: remainder high
;;         EBX: remainder high
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FASTCALL_FUNC  RhpULDivMod, 16

        ;; pretest for divide by zero
        mov     eax,[esp+esp_offsetof_divisor_low]
        or      eax,[esp+esp_offsetof_divisor_high]
        jne     __aulldvrm
        jmp     ThrowClasslibDivideByZeroException        

FASTCALL_ENDFUNC


        end