]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/IntrinsicLib/Ia32/MathLlmul.asm
CryptoPkg: Add instrinsics to support building ECC on IA32 windows
[mirror_edk2.git] / CryptoPkg / Library / IntrinsicLib / Ia32 / MathLlmul.asm
1 ;***
2 ;llmul.asm - long multiply routine
3 ;
4 ; Copyright (c) Microsoft Corporation. All rights reserved.
5 ; SPDX-License-Identifier: BSD-2-Clause-Patent
6 ;
7 ;Purpose:
8 ; Defines long multiply routine
9 ; Both signed and unsigned routines are the same, since multiply's
10 ; work out the same in 2's complement
11 ; creates the following routine:
12 ; __allmul
13 ;
14 ;Original Implemenation: MSVC 14.12.25827
15 ;
16 ;*******************************************************************************
17 .686
18 .model flat,C
19 .code
20
21
22 ;***
23 ;llmul - long multiply routine
24 ;
25 ;Purpose:
26 ; Does a long multiply (same for signed/unsigned)
27 ; Parameters are not changed.
28 ;
29 ;Entry:
30 ; Parameters are passed on the stack:
31 ; 1st pushed: multiplier (QWORD)
32 ; 2nd pushed: multiplicand (QWORD)
33 ;
34 ;Exit:
35 ; EDX:EAX - product of multiplier and multiplicand
36 ; NOTE: parameters are removed from the stack
37 ;
38 ;Uses:
39 ; ECX
40 ;
41 ;Exceptions:
42 ;
43 ;*******************************************************************************
44 _allmul PROC NEAR
45
46 A EQU [esp + 4] ; stack address of a
47 B EQU [esp + 12] ; stack address of b
48
49 HIGH_PART EQU [4] ;
50 LOW_PART EQU [0]
51
52 ;
53 ; AHI, BHI : upper 32 bits of A and B
54 ; ALO, BLO : lower 32 bits of A and B
55 ;
56 ; ALO * BLO
57 ; ALO * BHI
58 ; + BLO * AHI
59 ; ---------------------
60 ;
61
62 mov eax,HIGH_PART(A)
63 mov ecx,HIGH_PART(B)
64 or ecx,eax ;test for both high dwords zero.
65 mov ecx,LOW_PART(B)
66 jnz short hard ;both are zero, just mult ALO and BLO
67
68 mov eax,LOW_PART(A)
69 mul ecx
70
71 ret 16 ; callee restores the stack
72
73 hard:
74 push ebx
75
76 ; must redefine A and B since esp has been altered
77
78 A2 EQU [esp + 8] ; stack address of a
79 B2 EQU [esp + 16] ; stack address of b
80
81 mul ecx ;eax has AHI, ecx has BLO, so AHI * BLO
82 mov ebx,eax ;save result
83
84 mov eax,LOW_PART(A2)
85 mul dword ptr HIGH_PART(B2) ;ALO * BHI
86 add ebx,eax ;ebx = ((ALO * BHI) + (AHI * BLO))
87
88 mov eax,LOW_PART(A2);ecx = BLO
89 mul ecx ;so edx:eax = ALO*BLO
90 add edx,ebx ;now edx has all the LO*HI stuff
91
92 pop ebx
93
94 ret 16 ; callee restores the stack
95
96 _allmul ENDP
97
98 end