1 // See LICENSE for license details.
8 inline uint64_t mulhu(uint64_t a
, uint64_t b
)
12 uint64_t a0
= (uint32_t)a
, a1
= a
>> 32;
13 uint64_t b0
= (uint32_t)b
, b1
= b
>> 32;
15 t
= a1
*b0
+ ((a0
*b0
) >> 32);
22 t
= a1
*b1
+ y2
+ (t
>> 32);
26 return ((uint64_t)y3
<< 32) | y2
;
29 inline int64_t mulh(int64_t a
, int64_t b
)
31 int negate
= (a
< 0) != (b
< 0);
32 uint64_t res
= mulhu(a
< 0 ? -a
: a
, b
< 0 ? -b
: b
);
33 return negate
? ~res
+ (a
* b
== 0) : res
;
36 inline int64_t mulhsu(int64_t a
, uint64_t b
)
39 uint64_t res
= mulhu(a
< 0 ? -a
: a
, b
);
40 return negate
? ~res
+ (a
* b
== 0) : res
;