@@ -153,6 +153,46 @@ To support simplifying round-trip conversion, the following simplifications are
153153 [simplification, preserves-definedness, symbolic(VAL)]
154154```
155155
156+ For the case where the (symbolic) byte values are first converted to a number, the round-trip simplification requires different matching.
157+ First, the bit-masking with ` &Int 255 ` eliminates ` Bytes2Int(Int2Bytes(1, ..) +Bytes ..) ` enclosing a byte-valued variable:
158+
159+ ``` k
160+ rule Bytes2Int(Int2Bytes(1, X, LE) +Bytes _, LE, Unsigned) &Int 255 => X
161+ requires 0 <=Int X andBool X <=Int 255
162+ [simplification]
163+ rule Bytes2Int(Int2Bytes(1, X, LE), LE, Unsigned) &Int 255 => X
164+ requires 0 <=Int X andBool X <=Int 255
165+ [simplification]
166+ ```
167+
168+ Conversely, bit shifts by 8 interact with nests of ` Bytes2Int(Int2Bytes(..) +Bytes Rest) ` by eliminating the first byte:
169+ ``` k
170+ rule Bytes2Int(Int2Bytes(1, _:Int, _) +Bytes REST, LE, SIGNEDNESS) >>Int 8 => Bytes2Int(REST, LE, SIGNEDNESS)
171+ [simplification, preserves-definedness] // bit-shift by positive number
172+ ```
173+
174+ Finally, the magnitude of a value converted from bytes is known to be within the limit for the byte count:
175+ ``` k
176+ rule [u64-bytes-within-limit]:
177+ BYTE0 +Int (256 *Int (
178+ BYTE1 +Int (256 *Int (
179+ BYTE2 +Int (256 *Int (
180+ BYTE3 +Int (256 *Int (
181+ BYTE4 +Int (256 *Int (
182+ BYTE5 +Int (256 *Int (
183+ BYTE6 +Int (256 *Int (
184+ BYTE7)))))))))))))) <=Int bitmask64 => true
185+ requires 0 <=Int BYTE0 andBool BYTE0 <=Int 255
186+ andBool 0 <=Int BYTE1 andBool BYTE1 <=Int 255
187+ andBool 0 <=Int BYTE2 andBool BYTE2 <=Int 255
188+ andBool 0 <=Int BYTE3 andBool BYTE3 <=Int 255
189+ andBool 0 <=Int BYTE4 andBool BYTE4 <=Int 255
190+ andBool 0 <=Int BYTE5 andBool BYTE5 <=Int 255
191+ andBool 0 <=Int BYTE6 andBool BYTE6 <=Int 255
192+ andBool 0 <=Int BYTE7 andBool BYTE7 <=Int 255
193+ [simplification]
194+ ```
195+
156196
157197``` k
158198endmodule
0 commit comments