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 {
534
534
/// Returns the greatest x with alignment `align` so that x <= addr. The alignment must be
535
535
/// a power of 2.
536
536
#[ 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" ) ]
538
539
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
+
539
543
addr & !( align - 1 )
540
544
}
541
545
@@ -544,8 +548,12 @@ pub fn align_down(addr: u64, align: u64) -> u64 {
544
548
/// Returns the smallest x with alignment `align` so that x >= addr. The alignment must be
545
549
/// a power of 2.
546
550
#[ 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" ) ]
548
553
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
+
549
557
let align_mask = align - 1 ;
550
558
if addr & align_mask == 0 {
551
559
addr // already aligned
You can’t perform that action at this time.
0 commit comments