-
Notifications
You must be signed in to change notification settings - Fork 3
Bitwise operations #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+209
−15
Merged
Bitwise operations #579
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6e412c8
Added bitwise ops &,|,^ for integers and booleans
dkcumming 1bea54a
Set Version: 0.3.155
rv-auditor e44294b
Added `Shl` and `Shr` (checked) rs proofs
dkcumming a591f15
Formatting
dkcumming 61b808b
Shl and Shr initial implementation
dkcumming b3d3d6e
Updated tests to include unchecked shifts
dkcumming b3431fa
Merge branch 'master' into dc/bitwise
dkcumming d61ecd3
Set Version: 0.3.158
rv-auditor a3ec9a0
Rule will get stuck if UB would occur
dkcumming df72fda
Added some documentation
dkcumming c09fcf7
Merge branch 'dc/bitwise' of github.com:runtimeverification/mir-seman…
dkcumming e70db11
Removed duplicated bitwise-fail.rs file
dkcumming be4fece
Merge branch 'master' into dc/bitwise
dkcumming f807b7c
Set Version: 0.3.159
rv-auditor b931049
Added extra case to shift tests
dkcumming f13d488
Set Version: 0.3.160
rv-auditor ed1a35f
Merge branch 'master' into dc/bitwise
dkcumming fb95ac1
Added two more shift tests
dkcumming 8f6f391
onShift to use truncate
dkcumming c75ee85
FIX: `SwitchInt` is always unsigned.
dkcumming 66aa6f9
Updated test to include TYPE::MIN
dkcumming 24e2453
Merge branch 'dc/bitwise' of github.com:runtimeverification/mir-seman…
dkcumming 1a0370d
Merge branch 'master' into dc/bitwise
dkcumming 353720f
Set Version: 0.3.162
rv-auditor c86fd7d
Added some documentation
dkcumming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from typing import Final | ||
|
||
VERSION: Final = '0.3.161' | ||
VERSION: Final = '0.3.162' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
kmir/src/tests/integration/data/prove-rs/bitwise-not-shift-fail.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
fn main() { | ||
// Integers | ||
assert!(3_u128 & 7_u128 == 3_u128); | ||
assert!(3_u128 | 7_u128 == 7_u128); | ||
assert!(3_u128 ^ 7_u128 == 4_u128); | ||
|
||
// Booleans | ||
assert!(false | false == false); | ||
assert!(true | false == true); | ||
assert!(true & true == true); | ||
assert!(true & false == false); | ||
assert!(true ^ true == false); | ||
assert!(true ^ false == true); | ||
|
||
// Borrows | ||
assert!(&3 & &7 == 3); | ||
assert!(&3 | &7 == 7); | ||
assert!(&3 ^ &7 == 4); | ||
assert!(&false & &false == false); | ||
assert!(&true | &true == true); | ||
assert!(&false ^ &false == false); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
fn main() { | ||
// Shl basic | ||
assert!(1_u8 << 3_u8 == 8); | ||
assert!(1_u8 << 3_i8 == 8); // Negative on RHS if in 0..size | ||
assert!(1_i8 << 3_u8 == 8); | ||
assert!(1_i8 << 3_i8 == 8); | ||
assert!(1_i8 << 7_u8 == -128_i8); | ||
|
||
// Shl Overflow | ||
assert!(255_u8 << 1_u8 == 254); | ||
assert!(-127_i8 << 1_u8 == 2); | ||
dkcumming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// assert!(-128_i8 << -1_i8 == 2); // Shift must be in 0..size | ||
// assert!(0_u8 << 8_u8 == 0); // Shift must be in 0..size | ||
|
||
// Shr basic | ||
assert!(24_u8 >> 3_u8 == 3); | ||
assert!(24_u8 >> 3_i8 == 3); // Negative on RHS if in 0..size | ||
assert!(24_i8 >> 3_u8 == 3); | ||
assert!(24_i8 >> 3_i8 == 3); | ||
|
||
// Shr Overflow | ||
assert!(255_u8 >> 1_u8 == 127); | ||
assert!(-127_i8 >> 1_u8 == -64); // Arithmetic shift sign extends | ||
// assert!(-128_i8 >> -1_i8 == 2); // Shift must be in 0..size | ||
// assert!(0_u8 >> 8_u8 == 0); // Shift must be in 0..size | ||
|
||
// ShlUnchecked basic | ||
assert!(1_u8.wrapping_shl(3_u32) == 8_u8); // RHS must be u32 | ||
|
||
// ShlUnchecked Overflow | ||
assert!(255_u8.wrapping_shl(1_u32) == 254_u8); | ||
assert!(128_u8.wrapping_shl(1_u32) == 0_u8); | ||
assert!((-128_i8).wrapping_shl(3_u32) == 0_i8); | ||
assert!((-127_i8).wrapping_shl(3_u32) == 8_i8); | ||
|
||
// ShrUnchecked basic | ||
assert!(32_u8.wrapping_shr(2_u32) == 8_u8); // RHS must be u32 | ||
|
||
// ShlUnchecked Overflow | ||
assert!(255_u8.wrapping_shr(1_u32) == 127_u8); | ||
assert!(128_u8.wrapping_shr(1_u32) == 64_u8); | ||
assert!((-128_i8).wrapping_shr(3_u32) == -16_i8); | ||
assert!((-127_i8).wrapping_shr(1_u32) == -64_i8); | ||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
assert!((1_i8 << 7) + 1 == -127_i8); | ||
} |
13 changes: 13 additions & 0 deletions
13
kmir/src/tests/integration/data/prove-rs/shift_negative_min.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn main() { | ||
assert!(1_i8 << 7_u8 == -128); | ||
assert!(1_i16 << 15_u8 == -32768); | ||
assert!(1_i32 << 31_u8 == -2147483648); | ||
assert!(1_i64 << 63_u8 == -9223372036854775808); | ||
assert!(1_i128 << 127_u8 == -170141183460469231731687303715884105728); | ||
|
||
assert!(1_i8 << 7_u8 == i8::MIN); | ||
assert!(1_i16 << 15_u8 == i16::MIN); | ||
assert!(1_i32 << 31_u8 == i32::MIN); | ||
assert!(1_i64 << 63_u8 == i64::MIN); | ||
assert!(1_i128 << 127_u8 == i128::MIN); | ||
} |
16 changes: 16 additions & 0 deletions
16
kmir/src/tests/integration/data/prove-rs/show/bitwise-not-shift-fail.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
┌─ 1 (root, init) | ||
│ #init ( symbol ( "bitwise_not_shift_fail" ) globalAllocEntry ( 8 , Memory ( allo | ||
│ function: main | ||
│ span: 108 | ||
│ | ||
│ (254 steps) | ||
└─ 3 (stuck, leaf) | ||
#readProjection ( typedValue ( Any , ty ( 25 ) , mutabilityNot ) , projectionEle | ||
span: 63 | ||
|
||
|
||
┌─ 2 (root, leaf, target, terminal) | ||
│ #EndProgram | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.3.161 | ||
0.3.162 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on slack, we should prominently document this convention about
SwitchInt
discriminators being an unsigned interpretation of the given number.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a quick description in the section above just for now!