File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -534,8 +534,12 @@ impl Sub<PhysAddr> for PhysAddr {
534534/// Returns the greatest x with alignment `align` so that x <= addr. The alignment must be
535535/// a power of 2.
536536#[ inline]
537- pub fn align_down ( addr : u64 , align : u64 ) -> u64 {
537+ pub const fn align_down ( addr : u64 , align : u64 ) -> u64 {
538+ #[ cfg( feature = "const_fn" ) ]
538539 assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
540+ #[ cfg( not( feature = "const_fn" ) ) ]
541+ [ ( ) ; 1 ] [ !align. is_power_of_two ( ) as usize ] ;
542+
539543 addr & !( align - 1 )
540544}
541545
@@ -544,8 +548,12 @@ pub fn align_down(addr: u64, align: u64) -> u64 {
544548/// Returns the smallest x with alignment `align` so that x >= addr. The alignment must be
545549/// a power of 2.
546550#[ inline]
547- pub fn align_up ( addr : u64 , align : u64 ) -> u64 {
551+ pub const fn align_up ( addr : u64 , align : u64 ) -> u64 {
552+ #[ cfg( feature = "const_fn" ) ]
548553 assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
554+ #[ cfg( not( feature = "const_fn" ) ) ]
555+ [ ( ) ; 1 ] [ !align. is_power_of_two ( ) as usize ] ;
556+
549557 let align_mask = align - 1 ;
550558 if addr & align_mask == 0 {
551559 addr // already aligned
You can’t perform that action at this time.
0 commit comments