From 373c512397dde9c767ac65453780931a84704ce4 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 18 Apr 2025 20:34:39 +1200 Subject: Implement operator for expressions The operator returns the width of an integer in bits, using the same calculation as for packing an integer into a bit field. --- src/stages/bytecode.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/stages') diff --git a/src/stages/bytecode.rs b/src/stages/bytecode.rs index e4464a1..1d27b28 100644 --- a/src/stages/bytecode.rs +++ b/src/stages/bytecode.rs @@ -162,11 +162,7 @@ impl BytecodeParser { *value } }; - let value_width = match field_value.cmp(&0) { - std::cmp::Ordering::Less => (-field_value).ilog2() + 2, - std::cmp::Ordering::Equal => 0, - std::cmp::Ordering::Greater => field_value.ilog2() + 1, - }; + let value_width = width(field_value); if field.width < value_width { let error = BytecodeError::ValueTooWide(field.width, value_width); self.errors.push(Tracked::from(error, field_source.clone())); -- cgit v1.2.3-70-g09d2