source: trunk/src/NTDLL/arith64.asm@ 5280

Last change on this file since 5280 was 2159, checked in by sandervl, 26 years ago

Added qsort, ftol, CIpow, ltoa, ultoa

File size: 19.2 KB
Line 
1; $Id: arith64.asm,v 1.3 1999-12-20 11:47:00 sandervl Exp $
2
3;/*
4; * 64-bit integer apis
5; *
6; * Copyright 1999 Patrick Haller
7; *
8; *
9; * Project Odin Software License can be found in LICENSE.TXT
10; *
11; */
12.586P
13 NAME arith64
14
15CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
16 align 4
17
18; ----------------------------------------------------------------------------
19
20 public _RtlLargeIntegerDivide@20
21 public _RtlLargeIntegerAdd@16
22 public _RtlEnlargedIntegerMultiply@8
23 public _RtlEnlargedUnsignedMultiply@8
24 public _RtlEnlargedUnsignedDivide@16
25 public _RtlExtendedLargeIntegerDivide@16
26 public _RtlExtendedMagicDivide@20
27 public _RtlExtendedIntegerMultiply@12
28 public _RtlLargeIntegerShiftLeft@12
29 public _RtlLargeIntegerShiftRight@12
30 public _RtlLargeIntegerArithmeticShift@12
31 public _RtlLargeIntegerNegate@8
32 public _RtlLargeIntegerSubtract@16
33 public _RtlConvertLongToLargeInteger@4
34 public _RtlConvertUlongToLargeInteger@4
35
36; ----------------------------------------------------------------------------
37
38
39 extrn RtlRaiseStatus : near
40
41; ----------------------------------------------------------------------------
42
43
44; ----------------------------------------------------------------------------
45; Name : RtlLargeIntegerDivide
46; Purpose :
47; Parameters:
48; Variables :
49; Result :
50; Remark : NTDLL.462
51; Status : VERIFIED
52;
53; Author : Patrick Haller [Mon, 1999/11/08 23:44]
54; ----------------------------------------------------------------------------
55_RtlLargeIntegerDivide@20 proc near
56
57var_10 = dword ptr -10h
58var_C = dword ptr -0Ch
59var_8 = dword ptr -8
60var_4 = dword ptr -4
61arg_0 = dword ptr 8
62arg_4 = dword ptr 0Ch
63arg_8 = dword ptr 10h
64arg_C = dword ptr 14h
65arg_10 = dword ptr 18h
66
67 push ebp
68 xor eax, eax
69 mov ebp, esp
70 sub esp, 10h
71 push esi
72 mov [ebp+var_8], eax
73 push edi
74 mov esi, 40h
75 mov edi, [ebp+arg_C]
76 mov [ebp+var_4], eax
77 mov eax, [ebp+arg_8]
78 or eax, edi
79 jnz short _rtl_lrgintdiv_1
80 push 0C0000094h
81 call RtlRaiseStatus
82
83_rtl_lrgintdiv_1:
84 mov eax, [ebp+arg_0]
85 mov ecx, [ebp+arg_4]
86 mov [ebp+var_10], eax
87 mov [ebp+var_C], ecx
88
89_rtl_lrgintdiv_2:
90 mov eax, [ebp+var_8]
91 mov ecx, [ebp+var_4]
92 shr eax, 1Fh
93 add ecx, ecx
94 or eax, ecx
95 mov ecx, [ebp+var_8]
96 add ecx, ecx
97 mov [ebp+var_4], eax
98 mov eax, [ebp+var_C]
99 shr eax, 1Fh
100 or eax, ecx
101 mov ecx, [ebp+var_C]
102 add ecx, ecx
103 mov [ebp+var_8], eax
104 mov eax, [ebp+var_10]
105 shl [ebp+var_10], 1
106 shr eax, 1Fh
107 or eax, ecx
108 cmp [ebp+var_4], edi
109 mov [ebp+var_C], eax
110 ja short _rtl_lrgintdiv_3
111 mov eax, [ebp+arg_C]
112 cmp [ebp+var_4], eax
113 jnz short _rtl_lrgintdiv_5
114 mov eax, [ebp+arg_8]
115 cmp [ebp+var_8], eax
116 jb short _rtl_lrgintdiv_5
117
118_rtl_lrgintdiv_3:
119 mov eax, [ebp+arg_C]
120 mov ecx, [ebp+arg_8]
121 or byte ptr [ebp+var_10], 1
122 sub [ebp+var_4], eax
123 cmp [ebp+var_8], ecx
124 jnb short _rtl_lrgintdiv_4
125 dec [ebp+var_4]
126
127_rtl_lrgintdiv_4:
128 mov eax, [ebp+arg_8]
129 sub [ebp+var_8], eax
130
131_rtl_lrgintdiv_5:
132 dec esi
133 jnz short _rtl_lrgintdiv_2
134 mov eax, [ebp+arg_10]
135 test eax, eax
136 jz short _rtl_lrgintdiv_6
137 mov ecx, [ebp+var_8]
138 mov edx, [ebp+var_4]
139 mov [eax], ecx
140 mov [eax+4], edx
141
142_rtl_lrgintdiv_6:
143 mov eax, [ebp+var_10]
144 mov edx, [ebp+var_C]
145 pop edi
146 pop esi
147 mov esp, ebp
148 pop ebp
149 retn 14h
150_RtlLargeIntegerDivide@20 endp
151
152
153; ----------------------------------------------------------------------------
154; Name : RtlLargeIntegerAdd
155; Purpose :
156; Parameters:
157; Variables :
158; Result :
159; Remark : NTDLL.460
160; Status : VERIFIED
161;
162; Author : Patrick Haller [Mon, 1999/11/08 23:44]
163; ----------------------------------------------------------------------------
164_RtlLargeIntegerAdd@16 proc near
165
166arg_0 = dword ptr 4
167arg_4 = dword ptr 8
168arg_8 = dword ptr 0Ch
169arg_C = dword ptr 10h
170
171 mov eax, [esp+arg_0]
172 add eax, [esp+arg_8]
173 mov edx, [esp+arg_4]
174 adc edx, [esp+arg_C]
175 retn 10h
176_RtlLargeIntegerAdd@16 endp
177
178
179; ----------------------------------------------------------------------------
180; Name : RtlEnlargedIntegerMultiply
181; Purpose :
182; Parameters:
183; Variables :
184; Result :
185; Remark : NTDLL.371
186; Status : VERIFIED
187;
188; Author : Patrick Haller [Mon, 1999/11/08 23:44]
189; ----------------------------------------------------------------------------
190_RtlEnlargedIntegerMultiply@8 proc near
191
192arg_0 = dword ptr 4
193arg_4 = dword ptr 8
194
195 mov eax, [esp+arg_0]
196 imul [esp+arg_4]
197 retn 8
198_RtlEnlargedIntegerMultiply@8 endp
199
200
201; ----------------------------------------------------------------------------
202; Name : RtlEnlargedUnsignedMultiply
203; Purpose :
204; Parameters:
205; Variables :
206; Result :
207; Remark : NTDLL.373
208; Status : VERIFIED
209;
210; Author : Patrick Haller [Mon, 1999/11/08 23:44]
211; ----------------------------------------------------------------------------
212_RtlEnlargedUnsignedMultiply@8 proc near
213
214arg_0 = dword ptr 4
215arg_4 = dword ptr 8
216 mov eax, [esp+arg_0]
217 mul [esp+arg_4]
218 retn 8
219_RtlEnlargedUnsignedMultiply@8 endp
220
221
222; ----------------------------------------------------------------------------
223; Name : RtlEnlargedUnsignedDivide
224; Purpose :
225; Parameters:
226; Variables :
227; Result :
228; Remark : NTDLL.372
229; Status : VERIFIED
230;
231; Author : Patrick Haller [Mon, 1999/11/08 23:44]
232; ----------------------------------------------------------------------------
233_RtlEnlargedUnsignedDivide@16 proc near
234
235arg_0 = dword ptr 4
236arg_4 = dword ptr 8
237arg_8 = dword ptr 0Ch
238arg_C = dword ptr 10h
239
240 mov eax, [esp+arg_0]
241 mov edx, [esp+arg_4]
242 mov ecx, [esp+arg_C]
243 div [esp+arg_8]
244 or ecx, ecx
245 jnz short _rtl_enlunsdiv_1
246 retn 10h
247
248_rtl_enlunsdiv_1:
249 mov [ecx], edx
250 retn 10h
251_RtlEnlargedUnsignedDivide@16 endp
252
253
254; ----------------------------------------------------------------------------
255; Name : RtlExtendedLargeIntegerDivide
256; Purpose :
257; Parameters:
258; Variables :
259; Result :
260; Remark : NTDLL.390
261; Status : VERIFIED
262;
263; Author : Patrick Haller [Mon, 1999/11/08 23:44]
264; ----------------------------------------------------------------------------
265_RtlExtendedLargeIntegerDivide@16 proc near
266
267arg_0 = dword ptr 10h
268arg_4 = dword ptr 14h
269arg_8 = dword ptr 18h
270arg_C = dword ptr 1Ch
271
272 push esi
273 push edi
274 push ebx
275 mov eax, [esp+arg_0]
276 mov edx, [esp+arg_4]
277 mov ebx, [esp+arg_8]
278 or ebx, ebx
279 jz short _rtl_extlrgintdiv_2
280 push ebp
281 mov ecx, 40h
282 xor esi, esi
283 nop
284
285_rtl_extlrgintdiv_1:
286 shl eax, 1
287 rcl edx, 1
288 rcl esi, 1
289 sbb edi, edi
290 cmp esi, ebx
291 cmc
292 sbb ebp, ebp
293 or edi, ebp
294 sub eax, edi
295 and edi, ebx
296 sub esi, edi
297 dec ecx
298 jnz short _rtl_extlrgintdiv_1
299 pop ebp
300 pop ebx
301 pop edi
302 mov ecx, [esp+0FFFFFFF8h+arg_C]
303 or ecx, ecx
304 jnz short _rtl_extlrgintdiv_3
305 pop esi
306 retn 10h
307
308_rtl_extlrgintdiv_3:
309 mov [ecx], esi
310 pop esi
311 retn 10h
312
313_rtl_extlrgintdiv_2:
314 push 0C0000094h
315 call RtlRaiseStatus
316 pop ebx
317 pop edi
318 pop esi
319 retn 10h
320_RtlExtendedLargeIntegerDivide@16 endp
321
322
323
324; ----------------------------------------------------------------------------
325; Name : RtlExtendedMagicDivide
326; Purpose :
327; Parameters:
328; Variables :
329; Result :
330; Remark : NTDLL.391
331; Status : VERIFIED
332;
333; Author : Patrick Haller [Mon, 1999/11/08 23:44]
334; ----------------------------------------------------------------------------
335_RtlExtendedMagicDivide@20 proc near
336
337var_C = dword ptr -0Ch
338var_8 = dword ptr -8
339var_4 = dword ptr -4
340arg_0 = dword ptr 8
341arg_4 = dword ptr 0Ch
342arg_8 = dword ptr 10h
343arg_C = dword ptr 14h
344arg_10 = byte ptr 18h
345
346 push ebp
347 mov ebp, esp
348 sub esp, 0Ch
349 push esi
350 mov esi, [ebp+arg_4]
351 test esi, 80000000h
352 jz short _rtl_extmagicdiv_1
353 neg [ebp+arg_4]
354 neg [ebp+arg_0]
355 sbb [ebp+arg_4], 0
356
357_rtl_extmagicdiv_1:
358 mov eax, [ebp+arg_8]
359 mul [ebp+arg_0]
360 mov [ebp+var_4], edx
361 mov eax, [ebp+arg_8]
362 mul [ebp+arg_4]
363 mov [ebp+var_8], eax
364 mov [ebp+var_C], edx
365 mov eax, [ebp+arg_C]
366 mul [ebp+arg_0]
367 xor ecx, ecx
368 add eax, [ebp+var_4]
369 adc ecx, 0
370 add eax, [ebp+var_8]
371 adc ecx, 0
372 mov [ebp+var_4], edx
373 mov eax, [ebp+arg_C]
374 mul [ebp+arg_4]
375 add eax, [ebp+var_4]
376 adc edx, 0
377 add eax, [ebp+var_C]
378 adc edx, 0
379 add eax, ecx
380 adc edx, 0
381 mov cl, [ebp+arg_10]
382
383_rtl_extmagicdiv_3:
384 cmp cl, 1Fh
385 jbe short _rtl_extmagicdiv_2
386 sub cl, 1Fh
387 shrd eax, edx, 1Fh
388 shr edx, 1Fh
389 jmp short _rtl_extmagicdiv_3
390
391_rtl_extmagicdiv_2:
392 shrd eax, edx, cl
393 shr edx, cl
394 test esi, 80000000h
395 jz short _rtl_extmagicdiv_4
396 neg edx
397 neg eax
398 sbb edx, 0
399
400_rtl_extmagicdiv_4:
401 pop esi
402 mov esp, ebp
403 pop ebp
404 retn 14h
405_RtlExtendedMagicDivide@20 endp
406
407
408; ----------------------------------------------------------------------------
409; Name : RtlExtendedIntegerMultiply
410; Purpose :
411; Parameters:
412; Variables :
413; Result :
414; Remark : NTDLL.389
415; Status : VERIFIED
416;
417; Author : Patrick Haller [Mon, 1999/11/08 23:44]
418; ----------------------------------------------------------------------------
419_RtlExtendedIntegerMultiply@12 proc near
420
421var_8 = dword ptr -8
422arg_0 = dword ptr 8
423arg_4 = dword ptr 0Ch
424arg_8 = dword ptr 10h
425
426 push ebp
427 mov ebp, esp
428 push esi
429 mov esi, [ebp+arg_8]
430 xor esi, [ebp+arg_4]
431 test [ebp+arg_4], 80000000h
432 jz short _rtl_extintmply_1
433 neg [ebp+arg_4]
434 neg [ebp+arg_0]
435 sbb [ebp+arg_4], 0
436
437_rtl_extintmply_1:
438 test [ebp+arg_8], 80000000h
439 jz short _rtl_extintmply_2
440 neg [ebp+arg_8]
441
442_rtl_extintmply_2:
443 mov eax, [ebp+arg_8]
444 mul [ebp+arg_0]
445 push edx
446 mov ecx, eax
447 mov eax, [ebp+arg_8]
448 mul [ebp+arg_4]
449 add eax, [esp+8+var_8]
450 test esi, 80000000h
451 jz short _rtl_extintmply_3
452 neg eax
453 neg ecx
454 sbb eax, 0
455
456_rtl_extintmply_3:
457 add esp, 4
458 pop esi
459 mov edx, eax
460 mov eax, ecx
461 pop ebp
462 retn 0Ch
463_RtlExtendedIntegerMultiply@12 endp
464
465
466; ----------------------------------------------------------------------------
467; Name : RtlLargeIntegerShiftLeft
468; Purpose :
469; Parameters:
470; Variables :
471; Result :
472; Remark : NTDLL.464
473; Status : VERIFIED
474;
475; Author : Patrick Haller [Mon, 1999/11/08 23:44]
476; ----------------------------------------------------------------------------
477_RtlLargeIntegerShiftLeft@12 proc near
478
479arg_0 = dword ptr 4
480arg_4 = dword ptr 8
481arg_8 = dword ptr 0Ch
482
483 mov ecx, [esp+arg_8]
484 and ecx, 3Fh
485 cmp ecx, 20h
486 jnb short _rtl_lrgintshl_1
487 mov eax, [esp+arg_0]
488 mov edx, [esp+arg_4]
489 shld edx, eax, cl
490 shl eax, cl
491 retn 0Ch
492
493_rtl_lrgintshl_1:
494 mov edx, [esp+arg_0]
495 xor eax, eax
496 shl edx, cl
497 retn 0Ch
498_RtlLargeIntegerShiftLeft@12 endp
499
500
501; ----------------------------------------------------------------------------
502; Name : RtlLargeIntegerShiftRight
503; Purpose :
504; Parameters:
505; Variables :
506; Result :
507; Remark : NTDLL.465
508; Status : VERIFIED
509;
510; Author : Patrick Haller [Mon, 1999/11/08 23:44]
511; ----------------------------------------------------------------------------
512_RtlLargeIntegerShiftRight@12 proc near
513
514arg_0 = dword ptr 4
515arg_4 = dword ptr 8
516arg_8 = dword ptr 0Ch
517
518 mov ecx, [esp+arg_8]
519 and ecx, 3Fh
520 cmp ecx, 20h
521 jnb short _rtl_lrgintshr_1
522 mov eax, [esp+arg_0]
523 mov edx, [esp+arg_4]
524 shrd eax, edx, cl
525 shr edx, cl
526 retn 0Ch
527
528_rtl_lrgintshr_1:
529 mov eax, [esp+arg_4]
530 xor edx, edx
531 shr eax, cl
532 retn 0Ch
533_RtlLargeIntegerShiftRight@12 endp
534
535
536; ----------------------------------------------------------------------------
537; Name : RtlLargeIntegerArithmeticShift
538; Purpose :
539; Parameters:
540; Variables :
541; Result :
542; Remark : NTDLL.461
543; Status : VERIFIED
544;
545; Author : Patrick Haller [Mon, 1999/11/08 23:44]
546; ----------------------------------------------------------------------------
547
548_RtlLargeIntegerArithmeticShift@12 proc near
549
550arg_0 = dword ptr 4
551arg_4 = dword ptr 8
552arg_8 = dword ptr 0Ch
553
554 mov ecx, [esp+arg_8]
555 and ecx, 3Fh
556 cmp ecx, 20h
557 jb short _rtl_lrgintarithshft_1
558 mov eax, [esp+arg_4]
559 sar eax, cl
560 bt eax, 1Fh
561 sbb edx, edx
562 retn 0Ch
563
564_rtl_lrgintarithshft_1:
565 mov eax, [esp+arg_0]
566 mov edx, [esp+arg_4]
567 shrd eax, edx, cl
568 sar edx, cl
569 retn 0Ch
570_RtlLargeIntegerArithmeticShift@12 endp
571
572
573; ----------------------------------------------------------------------------
574; Name : RtlLargeIntegerNegate
575; Purpose :
576; Parameters:
577; Variables :
578; Result :
579; Remark : NTDLL.463
580; Status : VERIFIED
581;
582; Author : Patrick Haller [Mon, 1999/11/08 23:44]
583; ----------------------------------------------------------------------------
584_RtlLargeIntegerNegate@8 proc near
585
586arg_0 = dword ptr 4
587arg_4 = dword ptr 8
588
589 mov eax, [esp+arg_0]
590 mov edx, [esp+arg_4]
591 neg edx
592 neg eax
593 sbb edx, 0
594 retn 8
595_RtlLargeIntegerNegate@8 endp
596
597
598; ----------------------------------------------------------------------------
599; Name : RtlLargeIntegerSubtract
600; Purpose :
601; Parameters:
602; Variables :
603; Result :
604; Remark : NTDLL.466
605; Status : VERIFIED
606;
607; Author : Patrick Haller [Mon, 1999/11/08 23:44]
608; ----------------------------------------------------------------------------
609_RtlLargeIntegerSubtract@16 proc near
610
611arg_0 = dword ptr 4
612arg_4 = dword ptr 8
613arg_8 = dword ptr 0Ch
614arg_C = dword ptr 10h
615
616 mov eax, [esp+arg_0]
617 sub eax, [esp+arg_8]
618 mov edx, [esp+arg_4]
619 sbb edx, [esp+arg_C]
620 retn 10h
621_RtlLargeIntegerSubtract@16 endp
622
623
624; ----------------------------------------------------------------------------
625; Name : RtlConvertLongToLargeInteger
626; Purpose :
627; Parameters:
628; Variables :
629; Result :
630; Remark : NTDLL.316
631; Status : VERIFIED
632;
633; Author : Patrick Haller [Mon, 1999/11/08 23:44]
634; ----------------------------------------------------------------------------
635_RtlConvertLongToLargeInteger@4 proc near
636
637arg_0 = dword ptr 4
638
639 mov eax, [esp+arg_0]
640 cdq
641 retn 4
642_RtlConvertLongToLargeInteger@4 endp
643
644
645; ----------------------------------------------------------------------------
646; Name : RtlConvertUlongToLargeInteger
647; Purpose :
648; Parameters:
649; Variables :
650; Result :
651; Remark : NTDLL.320
652; Status : VERIFIED
653;
654; Author : Patrick Haller [Mon, 1999/11/08 23:44]
655; ----------------------------------------------------------------------------
656_RtlConvertUlongToLargeInteger@4 proc near
657
658arg_0 = dword ptr 4
659
660 mov eax, [esp+arg_0]
661 xor edx, edx
662 retn 4
663_RtlConvertUlongToLargeInteger@4 endp
664
665
666
667; ----------------------------------------------------------------------------
668
669PUBLIC _POP_FPU
670_POP_FPU proc near
671 mov eax, [esp+4]
672 fstp qword ptr [eax]
673 ret
674_POP_FPU endp
675
676CODE32 ENDS
677
678 END
Note: See TracBrowser for help on using the repository browser.