diff options
| author | Robert Norton | 2016-01-27 13:32:49 +0000 |
|---|---|---|
| committer | Robert Norton | 2016-01-27 13:47:47 +0000 |
| commit | 7412f2f6c3c6bba2c43bc6fb042d58001e94bc79 (patch) | |
| tree | 29dba3b9bc7d716b46bdf03d4c3dde4a250a6f6c /mips/mips.sail | |
| parent | e3a00ca2fbdb6b3fb45568ac69a3b2b87ae97b60 (diff) | |
mips.sail: produce undefined result for division by zero instead of crashing.
Diffstat (limited to 'mips/mips.sail')
| -rw-r--r-- | mips/mips.sail | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/mips/mips.sail b/mips/mips.sail index 7c3a4db1..6d5371cf 100644 --- a/mips/mips.sail +++ b/mips/mips.sail @@ -972,7 +972,7 @@ function clause execute (DIV(rs, rt)) = { rsVal := rGPR(rs); rtVal := rGPR(rt); - let ((bit[32]) q, (bit[32])r) = (if (NotWordVal(rsVal) | NotWordVal(rtVal)) then + let ((bit[32]) q, (bit[32])r) = (if (NotWordVal(rsVal) | NotWordVal(rtVal) | (rtVal == 0)) then (undefined, undefined) else ((rsVal[31..0]) quot_s (rtVal[31..0]), (rsVal[31..0]) mod (rtVal[31..0]))) @@ -991,7 +991,7 @@ function clause execute (DIVU(rs, rt)) = { rsVal := rGPR(rs); rtVal := rGPR(rt); - let ((bit[32]) q, (bit[32])r) = (if (NotWordVal(rsVal) | NotWordVal(rtVal)) then + let ((bit[32]) q, (bit[32])r) = (if (NotWordVal(rsVal) | NotWordVal(rtVal) | rtVal == 0) then (undefined, undefined) else ((rsVal[31..0]) quot (rtVal[31..0]), (rsVal[31..0]) mod (rtVal[31..0]))) @@ -1010,8 +1010,13 @@ function clause execute (DDIV(rs, rt)) = { rsVal := rGPR(rs); rtVal := rGPR(rt); - LO := rsVal quot_s rtVal; - HI := rsVal mod rtVal; (* signed? *) + let ((bit[64])q, (bit[64])r) = (if (rtVal == 0) + then (undefined, undefined) + else (rsVal quot_s rtVal, rsVal mod rtVal)) in + { + LO := q; + HI := r; (* signed? *) + } } (* DDIV 64-bit divide into HI/LO *) @@ -1022,8 +1027,13 @@ function clause execute (DDIVU(rs, rt)) = { rsVal := rGPR(rs); rtVal := rGPR(rt); - LO := rsVal quot rtVal; - HI := rsVal mod rtVal; + let ((bit[64])q, (bit[64])r) = (if (rtVal == 0) + then (undefined, undefined) + else (rsVal quot rtVal, rsVal mod rtVal)) in + { + LO := q; + HI := r; + } } (**************************************************************************************) |
