You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR is introduced to simplify the process of loading multiple bytes, simplifying the result of loadbytes for symbolic execution.
------
Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
For symbolic execution, we need to tackle the patterns of `#bytes(B +Bytes _) _` and `#bytes(B +Bytes BS) EF` to obtain as exact as possible values for `readByte`.
15
+
For symbolic execution, we need to tackle the patterns of `#bytes(B +Bytes _) _` and `#bytes(B +Bytes BS) EF` to obtain as exact as possible values for `pickFront`.
Copy file name to clipboardExpand all lines: src/kriscv/kdist/riscv-semantics/riscv.md
+8-18Lines changed: 8 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,32 +99,22 @@ module RISCV-MEMORY
99
99
100
100
syntax Memory = SparseBytes
101
101
```
102
-
We abstract the particular memory representation behind `loadBytes` and `storeBytes` functions.
102
+
We abstract the particular memory representation behind `loadBytes` and `storeBytes` functions. For multi-byte loads and stores, we presume a little-endian architecture.
103
103
```k
104
-
syntax Int ::= loadByte(memory: Memory, address: Word) [function, symbol(Memory:loadByte)]
@@ -323,7 +313,7 @@ The remaining branch instructions proceed analogously, but performing different
323
313
`LB`, `LH`, and `LW` load `1`, `2`, and `4` bytes respectively from the memory address which is `OFFSET` greater than the value in register `RS1`, then sign extends the loaded bytes and places them in register `RD`.
rule dropFront(.SparseBytes, I) => .SparseBytes requires I >Int 0
55
69
rule dropFront(#empty(N) BF, I) => #empty(N -Int I) BF requires I >Int 0 andBool I <Int N
56
-
rule dropFront(#empty(N) BF, I) => dropFront(BF, I -Int N) requires I >Int 0 andBool I >=Int N
70
+
rule dropFront(#empty(N) BF, I) => dropFront(BF, I -Int N) requires I >Int 0 andBool I >=Int N
57
71
rule dropFront(#bytes(B) EF, I) => dropFront(#bytes(substrBytes(B, I, lengthBytes(B))) EF, 0)
58
72
requires I >Int 0 andBool I <Int lengthBytes(B)
59
73
rule dropFront(#bytes(B) EF, I) => dropFront(EF, I -Int lengthBytes(B)) requires I >=Int lengthBytes(B)
60
74
```
61
-
`readByte` reads a single byte from a given index in `O(E)` time, where `E` is the number of `#empty(_)` or `#bytes(_)` entries in the list up to the location of the index. The result is either
62
-
- an `Int` in the range `[0, 255)` giving the byte value at the index, or
63
-
-`.Byte` if the index does not point to initialized data
75
+
`readBytes(SBS, I, NUM)` reads `NUM` bytes from a given index `I` in `O(E)` time, where `E` is the number of `#empty(_)` or `#bytes(_)` entries in the list up to the location of the index.
64
76
```k
65
-
syntax MaybeByte ::=
66
-
Int
67
-
| ".Byte"
68
-
69
-
syntax Int ::= MaybeByte2Int(MaybeByte) [function, total]
rule readByteEF(#empty(N) _ , I) => .Byte requires I <Int N
83
-
rule readByteEF(#empty(N) BF, I) => readByteBF(BF, I -Int N) requires I >=Int N
77
+
syntax Int ::= readBytes(SparseBytes, Int, Int) [function, total]
84
78
85
-
rule readByteBF(#bytes(_) _ , I) => .Byte requires I <Int 0 // error case for totality
86
-
rule readByteBF(#bytes(B) _ , I) => B[ I ] requires I >=Int 0 andBool I <Int lengthBytes(B)
87
-
rule readByteBF(#bytes(B) EF, I) => readByteEF(EF, I -Int lengthBytes(B))
88
-
requires I >=Int lengthBytes(B)
79
+
rule readBytes(SBS, I, NUM) => Bytes2Int(pickFront(dropFront(SBS, I), NUM), LE, Unsigned)
89
80
```
90
81
`writeBytes(SBS, I, V, NUM)` writes value `V` with length `NUM` bytes to a given index `I`. With regards to time complexity,
91
82
- If the index is in the middle of an existing `#empty(_)` or `#bytes(_)` region, time complexity is `O(E)` where `E` is the number of entries up to the index.
0 commit comments