Skip to content

Commit

Permalink
Merge pull request #35 from visitorckw/fix-signed-integer-oveflow
Browse files Browse the repository at this point in the history
Fix signed integer overflow in RV32M
  • Loading branch information
jserv authored Jan 8, 2024
2 parents ed4fe8f + d1c1d7d commit 90ddf1c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,11 @@ static uint32_t op_mul(uint32_t insn, uint32_t a, uint32_t b)
{
/* TODO: Test ifunc7 zeros */
switch (decode_func3(insn)) {
case 0b000: /* MUL */
return a * b;
case 0b000: { /* MUL */
const int64_t _a = (int32_t) a;
const int64_t _b = (int32_t) b;
return ((uint64_t) (_a * _b)) & ((1ULL << 32) - 1);
}
case 0b001: { /* MULH */
const int64_t _a = (int32_t) a;
const int64_t _b = (int32_t) b;
Expand Down

0 comments on commit 90ddf1c

Please sign in to comment.