Skip to content

Commit 749e9d4

Browse files
committed
added a function for reducing repetition of bit operation
1 parent cf3c9a7 commit 749e9d4

File tree

1 file changed

+6
-0
lines changed
  • src/librustc/mir/interpret

1 file changed

+6
-0
lines changed

src/librustc/mir/interpret/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,9 @@ pub fn truncate(value: u128, size: Size) -> u128 {
434434
// truncate (shift left to drop out leftover values, shift right to fill with zeroes)
435435
(value << shift) >> shift
436436
}
437+
438+
pub fn mask(size: Size) -> u128 {
439+
let size = size.bits();
440+
let shift = 128 - size;
441+
!0u128 >> shift
442+
}

0 commit comments

Comments
 (0)