VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc32-U8M.asm@ 93115

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1; $Id: bs3-wc32-U8M.asm 93115 2022-01-01 11:31:46Z vboxsync $
2;; @file
3; BS3Kit - 32-bit Watcom C/C++, 64-bit integer multiplication.
4;
5
6;
7; Copyright (C) 2007-2022 Oracle Corporation
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; The contents of this file may alternatively be used under the terms
18; of the Common Development and Distribution License Version 1.0
19; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20; VirtualBox OSE distribution, in which case the provisions of the
21; CDDL are applicable instead of those of the GPL.
22;
23; You may elect to license modified versions of this file under the
24; terms and conditions of either the GPL or the CDDL or both.
25;
26
27%include "bs3kit-template-header.mac"
28
29
30;;
31; 64-bit unsigned & signed integer multiplication.
32;
33; @returns EDX:EAX as the product.
34; @param EDX:EAX Factor 1 - edx=F1H, eax=F1L.
35; @param ECX:EBX Factor 2 - ecx=F2H, ebx=F2L.
36;
37global $??I8M
38$??I8M:
39global $??U8M
40$??U8M:
41 ;
42 ; If both the high dwords are zero, we can get away with
43 ; a simple 32-bit multiplication.
44 ;
45 test ecx, ecx
46 jnz .big
47 test edx, edx
48 jnz .big
49 mul ebx
50 ret
51
52.big:
53 ;
54 ; Imagine we use 4294967296-base (2^32), so each factor has two
55 ; digits H and L, thus we have: F1H:F1L * F2H:F1L which we can
56 ; multipy like we learned in primary school. Since the result
57 ; is limited to 64-bit, we can skip F1H*F2H and discard the
58 ; high 32-bit in F1L*F2H and F1H*F2L.
59 ; result = ((F1L*F2H) << 32)
60 ; + ((F1H*F2L) << 32)
61 ; + (F1L*F2L);
62 ;
63 push ecx ; Preserve ECX just to be nice.
64 push eax ; Stash F1L for later.
65 push edx ; Stash F1H for later.
66
67 ; ECX = F1L*F2H
68 mul ecx
69 mov ecx, eax
70
71 ; ECX += F1H * F2L
72 pop eax
73 mul ebx
74 add ecx, eax
75
76 ; EDX:EAX = F1L * F2L
77 pop eax
78 mul ebx
79 add edx, ecx
80
81 pop ecx
82 ret
83
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette