Skip to content

Commit

Permalink
Merge pull request #1546 from nibrunieAtSi5/patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryz123 authored Jan 18, 2025
2 parents 49727e8 + fd07749 commit 58da6a2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions riscv/arith.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ inline uint64_t mulhu(uint64_t a, uint64_t b)
inline int64_t mulh(int64_t a, int64_t b)
{
int negate = (a < 0) != (b < 0);
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);
return negate ? ~res + ((uint64_t)a * (uint64_t)b == 0) : res;
}

inline int64_t mulhsu(int64_t a, uint64_t b)
{
int negate = a < 0;
uint64_t res = mulhu(a < 0 ? -a : a, b);
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;
}

//ref: https://locklessinc.com/articles/sat_arithmetic/
Expand Down

0 comments on commit 58da6a2

Please sign in to comment.