From dc1aa62411649b73f3e3fb2ee5ec425a2bfeb645 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Wed, 26 Jan 2011 18:05:11 -0800 Subject: [PATCH] [sim] changed divide-by-0 semantics now it always gives -1, no matter the signedness. --- riscv/insns/div.h | 11 ++++------- riscv/insns/divw.h | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/riscv/insns/div.h b/riscv/insns/div.h index aa67134..96d9e10 100644 --- a/riscv/insns/div.h +++ b/riscv/insns/div.h @@ -1,9 +1,6 @@ -if(RS2 == 0 || (sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1)) -{ - if(xpr64) - RD = sreg_t(RS1) < 0 ? INT64_MIN : INT64_MAX; - else - RD = sreg_t(RS1) < 0 ? sext32(INT32_MIN) : INT32_MAX; -} +if(RS2 == 0) + RD = UINT64_MAX; +else if(sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1) + RD = RS1; else RD = sext_xprlen(sreg_t(RS1) / sreg_t(RS2)); diff --git a/riscv/insns/divw.h b/riscv/insns/divw.h index 9c732b5..ee940da 100644 --- a/riscv/insns/divw.h +++ b/riscv/insns/divw.h @@ -1,7 +1,9 @@ require_xpr64; +if(RS2 == 0) + RD = UINT64_MAX; // INT64_MIN/-1 corner case shouldn't occur in correct code, since // INT64_MIN is not a proper 32-bit signed value -if(RS2 == 0 || (sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1)) - RD = sext32(sreg_t(RS1) < 0 ? INT32_MIN : INT32_MAX); +else if(sreg_t(RS1) == INT64_MIN && sreg_t(RS2) == -1) + RD = RS1; else RD = sext32(sreg_t(RS1) / sreg_t(RS2)); -- 2.30.2