File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -79,12 +79,20 @@ impl Heap {
7979 }
8080}
8181
82- /// Align downwards. Returns the greatest x with alignment `align` so that x<=value.
83- fn align_down ( value : usize , align : usize ) -> usize {
84- value / align * align
82+ /// Align downwards. Returns the greatest x with alignment `align`
83+ /// so that x <= addr. The alignment must be a power of 2.
84+ pub fn align_down ( addr : usize , align : usize ) -> usize {
85+ if align. is_power_of_two ( ) {
86+ addr & !( align - 1 )
87+ } else if align == 0 {
88+ addr
89+ } else {
90+ panic ! ( "`align` must be a power of 2" ) ;
91+ }
8592}
8693
87- /// Align upwards. Returns the smallest x with alignment `align` so that value<=x.
88- fn align_up ( value : usize , align : usize ) -> usize {
89- align_down ( value + align - 1 , align)
94+ /// Align upwards. Returns the smallest x with alignment `align`
95+ /// so that x >= addr. The alignment must be a power of 2.
96+ pub fn align_up ( addr : usize , align : usize ) -> usize {
97+ align_down ( addr + align - 1 , align)
9098}
You can’t perform that action at this time.
0 commit comments