We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 49727e8 + fd07749 commit 58da6a2Copy full SHA for 58da6a2
riscv/arith.h
@@ -32,15 +32,15 @@ inline uint64_t mulhu(uint64_t a, uint64_t b)
32
inline int64_t mulh(int64_t a, int64_t b)
33
{
34
int negate = (a < 0) != (b < 0);
35
- uint64_t res = mulhu(a < 0 ? -a : a, b < 0 ? -b : b);
+ uint64_t res = mulhu(a < 0 ? -(uint64_t)a : a, b < 0 ? -(uint64_t)b : b);
36
return negate ? ~res + ((uint64_t)a * (uint64_t)b == 0) : res;
37
}
38
39
inline int64_t mulhsu(int64_t a, uint64_t b)
40
41
int negate = a < 0;
42
- uint64_t res = mulhu(a < 0 ? -a : a, b);
43
- return negate ? ~res + (a * b == 0) : res;
+ uint64_t res = mulhu(a < 0 ? -(uint64_t)a : a, b);
+ return negate ? ~res + ((uint64_t)a * b == 0) : res;
44
45
46
//ref: https://locklessinc.com/articles/sat_arithmetic/
0 commit comments