Skip to content

Commit

Permalink
Merge pull request #456 from Freax13/enhancement/faster-from_page_tab…
Browse files Browse the repository at this point in the history
…le_indices

optimize from_page_table_indices
  • Loading branch information
josephlr authored Feb 10, 2024
2 parents 3eb9c22 + d644235 commit f1cb4a0
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/structures/paging/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,10 @@ impl Page<Size1GiB> {
p4_index: PageTableIndex,
p3_index: PageTableIndex,
) -> Self {
use bit_field::BitField;

let mut addr = 0;
addr.set_bits(39..48, u64::from(p4_index));
addr.set_bits(30..39, u64::from(p3_index));
Page::containing_address(VirtAddr::new(addr))
addr |= u64::from(p4_index) << 39;
addr |= u64::from(p3_index) << 30;
Page::containing_address(VirtAddr::new_truncate(addr))
}
}

Expand All @@ -199,13 +197,11 @@ impl Page<Size2MiB> {
p3_index: PageTableIndex,
p2_index: PageTableIndex,
) -> Self {
use bit_field::BitField;

let mut addr = 0;
addr.set_bits(39..48, u64::from(p4_index));
addr.set_bits(30..39, u64::from(p3_index));
addr.set_bits(21..30, u64::from(p2_index));
Page::containing_address(VirtAddr::new(addr))
addr |= u64::from(p4_index) << 39;
addr |= u64::from(p3_index) << 30;
addr |= u64::from(p2_index) << 21;
Page::containing_address(VirtAddr::new_truncate(addr))
}
}

Expand All @@ -218,14 +214,12 @@ impl Page<Size4KiB> {
p2_index: PageTableIndex,
p1_index: PageTableIndex,
) -> Self {
use bit_field::BitField;

let mut addr = 0;
addr.set_bits(39..48, u64::from(p4_index));
addr.set_bits(30..39, u64::from(p3_index));
addr.set_bits(21..30, u64::from(p2_index));
addr.set_bits(12..21, u64::from(p1_index));
Page::containing_address(VirtAddr::new(addr))
addr |= u64::from(p4_index) << 39;
addr |= u64::from(p3_index) << 30;
addr |= u64::from(p2_index) << 21;
addr |= u64::from(p1_index) << 12;
Page::containing_address(VirtAddr::new_truncate(addr))
}

/// Returns the level 1 page table index of this page.
Expand Down

0 comments on commit f1cb4a0

Please sign in to comment.