aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKushal Pal <kushalpal109@gmail.com>2024-07-31 10:53:35 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-19 15:32:02 +0100
commitec9d9b6b2cbab28d58c5fe0d3f2e03845d8e00db (patch)
treee5f85c103081ff51a054b070500faecedd31e1a1 /gcc
parent03e7521c90abe2f592640a2ad9d3b26ef91ab5a5 (diff)
downloadgcc-ec9d9b6b2cbab28d58c5fe0d3f2e03845d8e00db.zip
gcc-ec9d9b6b2cbab28d58c5fe0d3f2e03845d8e00db.tar.gz
gcc-ec9d9b6b2cbab28d58c5fe0d3f2e03845d8e00db.tar.bz2
gccrs: Improve compressed point bit manipulation
gcc/rust/ChangeLog: * checks/errors/borrowck/polonius/rust-polonius.h (struct FullPoint): Added comments and made extraction of statement more verbose for better understanding. * checks/errors/borrowck/ffi-polonius/src/lib.rs: Likewise. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs17
-rw-r--r--gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h21
2 files changed, 35 insertions, 3 deletions
diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
index c5c0ae9..b21dee3 100644
--- a/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
+++ b/gcc/rust/checks/errors/borrowck/ffi-polonius/src/lib.rs
@@ -105,9 +105,24 @@ impl From<gccrs_ffi::FactsView> for AllFacts<GccrsFacts> {
fn print_point(point: GccrsAtom) {
let val: usize = point.into();
+ // Point is a 32 bit unsigned integer
+ // 16 15 1
+ // xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx x
+ // ^~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~ ^
+ // | | |
+ // basic_block | start/mid
+ // statement
+ // the left most 16 bits store the basic block number
+ // the right most bit, represents the start/mid status
+ // the remaining 15 bits between these two represent the statement
let mid = val % 2 == 1;
let bb = val >> 16;
- let stmt = (val >> 1) & ((1 << 15) - 1);
+ // firstly we can get rid of right most bit by performing left shift once
+ let hide_left_most_bit = val >> 1;
+ // now we only need the 15 bits on the right
+ // we can mask the remaining bits by performing bitwise AND with fifteen
+ // 1's which in hexadecimal is 0x7FFF
+ let stmt = hide_left_most_bit & 0x7FFF;
eprint!("{}(bb{}[{}])", if mid { "Mid" } else { "Start" }, bb, stmt);
}
diff --git a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
index 4447ad5..0ce2142 100644
--- a/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
+++ b/gcc/rust/checks/errors/borrowck/polonius/rust-polonius.h
@@ -35,7 +35,7 @@ struct FullPoint
bool mid;
/** Expands a compressed `Point` into its components.
- * See `Point` docs for encoding details.
+ * See `Point` docs for encoding details in ./rust-polonius-ffi.h
*/
explicit FullPoint (Point point)
: bb (extract_bb (point)), stmt (extract_stmt (point)),
@@ -45,7 +45,24 @@ struct FullPoint
static uint32_t extract_bb (Point point) { return point >> 16; }
static uint32_t extract_stmt (Point point)
{
- return (point >> 1) & ((1 << 15) - 1);
+ // Point is a 32 bit unsigned integer
+ // 16 15 1
+ // xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx x
+ // ^~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~ ^
+ // | | |
+ // basic_block | start/mid
+ // statement
+ // the left most 16 bits store the basic block number
+ // the right most bit, represents the start/mid status
+ // the remaining 15 bits between these two represent the statement number
+ // which we need to extract in this fucntion
+ //
+ // firstly we can get rid of right most bit by performing left shift once
+ auto hide_left_most_bit = point >> 1;
+ // now we only need the 15 bits on the right
+ // we can mask the remaining bits by performing bitwise AND with fifteen
+ // 1's which in hexadecimal is 0x7FFF
+ return hide_left_most_bit & 0x7FFF;
}
static bool extract_mid (Point point) { return point & 1; }