VirtualBox

source: vbox/trunk/src/VBox/Devices/muldiv64.c@ 217

Last change on this file since 217 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1
2/* from vl.c */
3/*
4 * QEMU System Emulator
5 *
6 * Copyright (c) 2003-2004 Fabrice Bellard
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27#include "vl_vbox.h"
28
29
30/* compute with 96 bit intermediate result: (a*b)/c */
31uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
32{
33 union {
34 uint64_t ll;
35 struct {
36#ifdef WORDS_BIGENDIAN
37 uint32_t high, low;
38#else
39 uint32_t low, high;
40#endif
41 } l;
42 } u, res;
43 uint64_t rl, rh;
44
45 u.ll = a;
46 rl = (uint64_t)u.l.low * (uint64_t)b;
47 rh = (uint64_t)u.l.high * (uint64_t)b;
48 rh += (rl >> 32);
49 res.l.high = rh / c;
50 res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
51 return res.ll;
52}
53
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