VirtualBox

Changeset 52443 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Aug 21, 2014 4:16:19 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95651
Message:

Runtime: added ASMMultU32ByU32DivByU32() and fixed early clobber operands in ASMMultU64ByU32DivByU32

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm-math.h

    r52294 r52443  
    322322
    323323/**
     324 * Multiple a 32-bit by a 32-bit integer and divide the result by a 32-bit integer
     325 * using a 64 bit intermediate result.
     326 * @note    Don't use 64-bit C arithmetic here since some gcc compilers generate references to
     327 *          __udivdi3 and __umoddi3 even if this inline function is not used.
     328 *
     329 * @returns (u32A * u32B) / u32C.
     330 * @param   u32A    The 32-bit value (A).
     331 * @param   u32B    The 32-bit value to multiple by A.
     332 * @param   u32C    The 32-bit value to divide A*B by.
     333 *
     334 * @remarks Architecture specific.
     335 */
     336#if RT_INLINE_ASM_EXTERNAL || !defined(__GNUC__) || (!defined(RT_ARCH_AMD64) && !defined(RT_ARCH_X86))
     337DECLASM(uint32_t) ASMMultU32ByU32DivByU32(uint32_t u32A, uint32_t u32B, uint32_t u32C);
     338#else
     339DECLINLINE(uint32_t) ASMMultU32ByU32DivByU32(uint32_t u32A, uint32_t u32B, uint32_t u32C)
     340{
     341# if RT_INLINE_ASM_GNU_STYLE
     342    uint32_t u32Result, u32Spill;
     343    __asm__ __volatile__("mul %2\n\t"
     344                         "div %3\n\t"
     345                         : "=&a" (u32Result),
     346                           "=&d" (u32Spill)
     347                         : "r" (u32B),
     348                           "r" (u32C),
     349                           "0" (u32A),
     350                           "1" (0));
     351    return u32Result;
     352# else
     353    return (uint32_t)(((uint64_t)u32A * u32B) / u32C);
     354# endif
     355}
     356#endif
     357
     358
     359/**
    324360 * Multiple a 64-bit by a 32-bit integer and divide the result by a 32-bit integer
    325361 * using a 96 bit intermediate result.
     
    344380    __asm__ __volatile__("mulq %2\n\t"
    345381                         "divq %3\n\t"
    346                          : "=a" (u64Result),
    347                            "=d" (u64Spill)
     382                         : "=&a" (u64Result),
     383                           "=&d" (u64Spill)
    348384                         : "r" ((uint64_t)u32B),
    349385                           "r" ((uint64_t)u32C),
Note: See TracChangeset for help on using the changeset viewer.

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