uint64 multiplier,
uint32 shift)
{
- uint64 resLow, resHi;
-
- asm("mul %0, %2, %3" "\n\t"
- "umulh %1, %2, %3"
- : "=&r" (resLow), "=r" (resHi)
- : "r" (multiplicand), "r" (multiplier));
-
if (shift == 0) {
- return resLow;
+ return multiplicand * multiplier;
} else {
- return (resLow >> shift) +
- (resHi << (64 - shift)) +
- ((resLow >> (shift - 1)) & 1);
+ uint64 lo, hi;
+
+ asm("mul %0, %2, %3" "\n\t"
+ "umulh %1, %2, %3"
+ : "=&r" (lo), "=r" (hi)
+ : "r" (multiplicand), "r" (multiplier));
+ return (hi << (64 - shift) | lo >> shift) + (lo >> (shift - 1) & 1);
}
}
int64 multiplier,
uint32 shift)
{
- uint64 resLow, resHi;
-
- asm("mul %0, %2, %3" "\n\t"
- "smulh %1, %2, %3"
- : "=&r" (resLow), "=r" (resHi)
- : "r" (multiplicand), "r" (multiplier));
-
if (shift == 0) {
- return resLow;
+ return multiplicand * multiplier;
} else {
- return (resLow >> shift) +
- (resHi << (64 - shift)) +
- ((resLow >> (shift - 1)) & 1);
+ uint64 lo, hi;
+
+ asm("mul %0, %2, %3" "\n\t"
+ "smulh %1, %2, %3"
+ : "=&r" (lo), "=r" (hi)
+ : "r" (multiplicand), "r" (multiplier));
+ return (hi << (64 - shift) | lo >> shift) + (lo >> (shift - 1) & 1);
}
}
* discarded by the shift.
* Return the low-order 64 bits of the above.
*/
- uint64 tmplo, tmphi;
- tmplo = _umul128(multiplicand, multiplier, &tmphi);
if (shift == 0) {
- return tmplo;
+ return multiplicand * multiplier;
} else {
- return __shiftright128(tmplo, tmphi, (uint8) shift) +
- ((tmplo >> (shift - 1)) & 1);
+ uint64 lo, hi;
+
+ lo = _umul128(multiplicand, multiplier, &hi);
+ return __shiftright128(lo, hi, (uint8)shift) + (lo >> (shift - 1) & 1);
}
}
* Note: using an unsigned shift is correct because shift < 64 and
* we return only the low 64 bits of the shifted result.
*/
- int64 tmplo, tmphi;
- tmplo = _mul128(multiplicand, multiplier, &tmphi);
if (shift == 0) {
- return tmplo;
+ return multiplicand * multiplier;
} else {
- return __shiftright128(tmplo, tmphi, (uint8) shift) +
- ((tmplo >> (shift - 1)) & 1);
+ int64 lo, hi;
+
+ lo = _mul128(multiplicand, multiplier, &hi);
+ return __shiftright128(lo, hi, (uint8)shift) + (lo >> (shift - 1) & 1);
}
}