From b5f4f0ef3139b103d7406c897cb67224625f4c2b Mon Sep 17 00:00:00 2001 From: Yunsup Lee Date: Mon, 30 Jan 2012 14:38:23 -0800 Subject: [PATCH] fix divide by zero bugs --- riscv/insns/divuw.h | 2 +- riscv/insns/divw.h | 2 +- riscv/insns/remuw.h | 2 +- riscv/insns/remw.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/riscv/insns/divuw.h b/riscv/insns/divuw.h index 0ceb040..2cf0511 100644 --- a/riscv/insns/divuw.h +++ b/riscv/insns/divuw.h @@ -1,5 +1,5 @@ require_xpr64; -if(RS2 == 0) +if(zext32(RS2) == 0) RD = UINT64_MAX; else RD = sext32(zext32(RS1) / zext32(RS2)); diff --git a/riscv/insns/divw.h b/riscv/insns/divw.h index 51c3d80..84f42a9 100644 --- a/riscv/insns/divw.h +++ b/riscv/insns/divw.h @@ -1,5 +1,5 @@ require_xpr64; -if(RS2 == 0) +if(int32_t(RS2) == 0) RD = UINT64_MAX; else if(int32_t(RS1) == INT32_MIN && int32_t(RS2) == -1) RD = RS1; diff --git a/riscv/insns/remuw.h b/riscv/insns/remuw.h index 8234af3..1cc015d 100644 --- a/riscv/insns/remuw.h +++ b/riscv/insns/remuw.h @@ -1,5 +1,5 @@ require_xpr64; -if(RS2 == 0) +if(zext_xprlen(RS2) == 0) RD = RS1; else RD = sext32(zext_xprlen(RS1) % zext_xprlen(RS2)); diff --git a/riscv/insns/remw.h b/riscv/insns/remw.h index 93c3858..1093533 100644 --- a/riscv/insns/remw.h +++ b/riscv/insns/remw.h @@ -1,5 +1,5 @@ require_xpr64; -if(RS2 == 0) +if(int32_t(RS2) == 0) RD = RS1; else if(int32_t(RS1) == INT32_MIN && int32_t(RS2) == -1) RD = 0; -- 2.30.2