From 749e9d460a14da95a77072b259441e3ea2539244 Mon Sep 17 00:00:00 2001 From: kenta7777 Date: Mon, 11 Mar 2019 22:31:25 +0900 Subject: [PATCH] added a function for reducing repetition of bit operation --- src/librustc/mir/interpret/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 0c43fe4a79f..c07b8e236fa 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -434,3 +434,9 @@ pub fn truncate(value: u128, size: Size) -> u128 { // truncate (shift left to drop out leftover values, shift right to fill with zeroes) (value << shift) >> shift } + +pub fn mask(size: Size) -> u128 { + let size = size.bits(); + let shift = 128 - size; + !0u128 >> shift +}