Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signed integer overflow in RV32M #35

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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