Skip to content

Commit

Permalink
write/line: avoid division if minimum instruction length is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Mar 27, 2020
1 parent 15bea8e commit a2c68c4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/write/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,14 @@ impl LineProgram {

fn op_advance(&self) -> u64 {
debug_assert!(self.row.address_offset >= self.prev_row.address_offset);
debug_assert_eq!(
self.row.address_offset % u64::from(self.line_encoding.minimum_instruction_length),
0
);
let address_advance = (self.row.address_offset - self.prev_row.address_offset)
/ u64::from(self.line_encoding.minimum_instruction_length);
let mut address_advance = (self.row.address_offset - self.prev_row.address_offset);
if self.line_encoding.minimum_instruction_length != 1 {
debug_assert_eq!(
self.row.address_offset % u64::from(self.line_encoding.minimum_instruction_length),
0
);
address_advance /= u64::from(self.line_encoding.minimum_instruction_length);
}
address_advance * u64::from(self.line_encoding.maximum_operations_per_instruction)
+ self.row.op_index
- self.prev_row.op_index
Expand Down

0 comments on commit a2c68c4

Please sign in to comment.