Skip to content

Commit 0c40c65

Browse files
Make Word shift operations total (#104)
Eliminates Booster aborts on `SLLI` and `SRLI` instructions. --------- Co-authored-by: devops <devops@runtimeverification.com>
1 parent 58d1958 commit 0c40c65

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.72
1+
0.1.73

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "kriscv"
7-
version = "0.1.72"
7+
version = "0.1.73"
88
description = "K tooling for the RISC-V architecture"
99
authors = [
1010
"Runtime Verification, Inc. <contact@runtimeverification.com>",

src/kriscv/kdist/riscv-semantics/riscv.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,15 @@ We then provide rules to consume and execute each instruction from the top of th
198198
```k
199199
rule <instrs> SLLI RD , RS , SHAMT => .K ...</instrs>
200200
<regs> REGS => writeReg(REGS, RD, readReg(REGS, RS) <<Word SHAMT) </regs>
201+
requires 0 <=Int SHAMT
201202
202203
rule <instrs> SRLI RD , RS , SHAMT => .K ...</instrs>
203204
<regs> REGS => writeReg(REGS, RD, readReg(REGS, RS) >>lWord SHAMT) </regs>
205+
requires 0 <=Int SHAMT
204206
205207
rule <instrs> SRAI RD , RS , SHAMT => .K ...</instrs>
206208
<regs> REGS => writeReg(REGS, RD, readReg(REGS, RS) >>aWord SHAMT) </regs>
209+
requires 0 <=Int SHAMT
207210
```
208211
`LUI` builds a 32-bit constant from the 20-bit immediate by setting the 12 least-significant bits to `0`, then sign extends to `XLEN` bits and places the result in register `RD`.
209212
```k

src/kriscv/kdist/riscv-semantics/word.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ is used to zero-out all but the least-significant `XLEN`-bits in case of overflo
101101
syntax Word ::= Word "xorWord" Word [function, total]
102102
rule W(I1) xorWord W(I2) => W(I1 xorInt I2)
103103
104-
syntax Word ::= Word "<<Word" Int [function]
105-
rule W(I1) <<Word I2 => chop(I1 <<Int I2)
104+
syntax Word ::= Word "<<Word" Int [function, total]
105+
rule W(I1) <<Word I2 => chop(I1 <<Int I2) requires 0 <=Int I2
106+
rule _ <<Word I2 => W(0) requires I2 <Int 0
106107
```
107108
For right shifts, we provide both arithmetic and logical variants.
108109

@@ -113,12 +114,14 @@ Counterintuitively, we use the arithmetic right shift operator `>>Int` for `Int`
113114

114115
That is, for any `I:Int` underlying some `W(I):Word`, applying `>>Int` will always pad with `0`s, correctly implementing a logical right shift.
115116
```k
116-
syntax Word ::= Word ">>lWord" Int [function]
117-
rule W(I1) >>lWord I2 => W(I1 >>Int I2)
117+
syntax Word ::= Word ">>lWord" Int [function, total]
118+
rule W(I1) >>lWord I2 => W(I1 >>Int I2) requires 0 <=Int I2
119+
rule _ >>lWord I2 => W(0) requires I2 <Int 0
118120
```
119121
To actually perform an arithmetic shift over `Word`, we first convert to an infinitely sign-extended `Int` of equal value using `Word2SInt`, ensuring `>>Int` will pad with `1`s for a negative `Word`. The final result will still be infinitely sign-extended, so we must `chop` it back to a `Word`.
120122
```k
121-
syntax Word ::= Word ">>aWord" Int [function]
122-
rule W1 >>aWord I2 => chop(Word2SInt(W1) >>Int I2)
123+
syntax Word ::= Word ">>aWord" Int [function, total]
124+
rule W1 >>aWord I2 => chop(Word2SInt(W1) >>Int I2) requires 0 <=Int I2
125+
rule _ >>aWord I2 => W(0) requires I2 <Int 0
123126
endmodule
124127
```

0 commit comments

Comments
 (0)