VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/asm/ASMMultU64ByU32DivByU32.asm@ 5490

最後變更 在這個檔案從5490是 5490,由 vboxsync 提交於 17 年 前

Converted gcc ASMMultU64ByU32DivByU32 inline code to nasm in order to speed up the MSC builds (yes, it makes a noticable difference for TSC).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id
檔案大小: 3.3 KB
 
1; $Id: ASMMultU64ByU32DivByU32.asm 5490 2007-10-25 01:45:46Z vboxsync $
2;; @file
3; innotek Portable Runtime - Assembly Functions, ASMMultU64ByU32DivByU32.
4;
5
6;
7; Copyright (C) 2006-2007 InnoTek Systemberatung GmbH
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.alldomusa.eu.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 as published by the Free Software Foundation,
13; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14; distribution. VirtualBox OSE is distributed in the hope that it will
15; be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17;
18
19%include "iprt/asmdefs.mac"
20
21
22;;
23; Multiple a 64-bit by a 32-bit integer and divide the result by a 32-bit integer
24; using a 96 bit intermediate result.
25;
26; @returns (u64A * u32B) / u32C.
27; @param u64A/rcx/rdi The 64-bit value.
28; @param u32B/edx/esi The 32-bit value to multiple by A.
29; @param u32C/r8d/edx The 32-bit value to divide A*B by.
30;
31; @cproto DECLASM(uint64_t) ASMMultU64ByU32DivByU32(uint64_t u64A, uint32_t u32B, uint32_t u32C);
32;
33BEGINPROC_EXPORTED ASMMultU64ByU32DivByU32
34%ifdef RT_ARCH_AMD64
35
36 %ifdef ASM_CALL64_MSC
37 mov rax, rcx ; rax = u64A
38 mov r9d, edx ; should check the specs wrt to the high bits one day...
39 mov r8d, r8d ; be paranoid for the time being.
40 %else
41 mov rax, rdi ; rax = u64A
42 mov r9d, esi ; r9d = u32B
43 mov r8d, edx ; r8d = u32C
44 %endif
45 mul r9
46 div r8
47
48%else ; X86
49 ;
50 ; This implementation is convered from the GCC inline
51 ; version of the code. Nothing additional has been done
52 ; performance wise.
53 ;
54 push esi
55 push edi
56
57%define u64A_Lo [esp + 04h + 08h]
58%define u64A_Hi [esp + 08h + 08h]
59%define u32B [esp + 0ch + 08h]
60%define u32C [esp + 10h + 08h]
61
62 ; Load parameters into registers.
63 mov eax, u64A_Lo
64 mov esi, u64A_Hi
65 mov ecx, u32B
66 mov edi, u32C
67
68 ; The body, just like the in
69 mul ecx ; eax = u64Lo.lo = (u64A.lo * u32B).lo
70 ; edx = u64Lo.hi = (u64A.lo * u32B).hi
71 xchg eax, esi ; esi = u64Lo.lo
72 ; eax = u64A.hi
73 xchg edx, edi ; edi = u64Low.hi
74 ; edx = u32C
75 xchg edx, ecx ; ecx = u32C
76 ; edx = u32B
77 mul edx ; eax = u64Hi.lo = (u64A.hi * u32B).lo
78 ; edx = u64Hi.hi = (u64A.hi * u32B).hi
79 add eax, edi ; u64Hi.lo += u64Lo.hi
80 adc edx, 0 ; u64Hi.hi += carry
81 div ecx ; eax = u64Hi / u32C
82 ; edx = u64Hi % u32C
83 mov edi, eax ; edi = u64Result.hi = u64Hi / u32C
84 mov eax, esi ; eax = u64Lo.lo
85 div ecx ; u64Result.lo
86 mov edx, edi ; u64Result.hi
87
88 ; epilogue
89 pop edi
90 pop esi
91%endif
92 ret
93ENDPROC ASMMultU64ByU32DivByU32
94
95
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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