@@ -69,6 +69,7 @@ impl VirtAddr {
69
69
/// This function performs sign extension of bit 47 to make the address canonical, so
70
70
/// bits 48 to 64 are overwritten. If you want to check that these bits contain no data,
71
71
/// use `new` or `try_new`.
72
+ #[ inline]
72
73
pub const fn new_unchecked ( addr : u64 ) -> VirtAddr {
73
74
// Rust doesn't accept shift operators in const functions at the moment,
74
75
// so we use a multiplication and division by 0x1_0000 instead of `<< 16` and `>> 16`.
@@ -78,11 +79,13 @@ impl VirtAddr {
78
79
}
79
80
80
81
/// Creates a virtual address that points to `0`.
82
+ #[ inline]
81
83
pub const fn zero ( ) -> VirtAddr {
82
84
VirtAddr ( 0 )
83
85
}
84
86
85
87
/// Converts the address to an `u64`.
88
+ #[ inline]
86
89
pub const fn as_u64 ( self ) -> u64 {
87
90
self . 0
88
91
}
@@ -93,25 +96,29 @@ impl VirtAddr {
93
96
// on this function. At least for 32- and 64-bit we know the `as u64` cast
94
97
// doesn't truncate.
95
98
#[ cfg( any( target_pointer_width = "32" , target_pointer_width = "64" ) ) ]
99
+ #[ inline]
96
100
pub fn from_ptr < T > ( ptr : * const T ) -> Self {
97
101
Self :: new ( ptr as u64 )
98
102
}
99
103
100
104
/// Converts the address to a raw pointer.
101
105
#[ cfg( target_pointer_width = "64" ) ]
106
+ #[ inline]
102
107
pub fn as_ptr < T > ( self ) -> * const T {
103
108
self . as_u64 ( ) as * const T
104
109
}
105
110
106
111
/// Converts the address to a mutable raw pointer.
107
112
#[ cfg( target_pointer_width = "64" ) ]
113
+ #[ inline]
108
114
pub fn as_mut_ptr < T > ( self ) -> * mut T {
109
115
self . as_ptr :: < T > ( ) as * mut T
110
116
}
111
117
112
118
/// Aligns the virtual address upwards to the given alignment.
113
119
///
114
120
/// See the `align_up` function for more information.
121
+ #[ inline]
115
122
pub fn align_up < U > ( self , align : U ) -> Self
116
123
where
117
124
U : Into < u64 > ,
@@ -122,6 +129,7 @@ impl VirtAddr {
122
129
/// Aligns the virtual address downwards to the given alignment.
123
130
///
124
131
/// See the `align_down` function for more information.
132
+ #[ inline]
125
133
pub fn align_down < U > ( self , align : U ) -> Self
126
134
where
127
135
U : Into < u64 > ,
@@ -130,6 +138,7 @@ impl VirtAddr {
130
138
}
131
139
132
140
/// Checks whether the virtual address has the demanded alignment.
141
+ #[ inline]
133
142
pub fn is_aligned < U > ( self , align : U ) -> bool
134
143
where
135
144
U : Into < u64 > ,
@@ -138,26 +147,31 @@ impl VirtAddr {
138
147
}
139
148
140
149
/// Returns the 12-bit page offset of this virtual address.
150
+ #[ inline]
141
151
pub fn page_offset ( & self ) -> PageOffset {
142
152
PageOffset :: new_truncate ( self . 0 as u16 )
143
153
}
144
154
145
155
/// Returns the 9-bit level 1 page table index.
156
+ #[ inline]
146
157
pub fn p1_index ( & self ) -> PageTableIndex {
147
158
PageTableIndex :: new_truncate ( ( self . 0 >> 12 ) as u16 )
148
159
}
149
160
150
161
/// Returns the 9-bit level 2 page table index.
162
+ #[ inline]
151
163
pub fn p2_index ( & self ) -> PageTableIndex {
152
164
PageTableIndex :: new_truncate ( ( self . 0 >> 12 >> 9 ) as u16 )
153
165
}
154
166
155
167
/// Returns the 9-bit level 3 page table index.
168
+ #[ inline]
156
169
pub fn p3_index ( & self ) -> PageTableIndex {
157
170
PageTableIndex :: new_truncate ( ( self . 0 >> 12 >> 9 >> 9 ) as u16 )
158
171
}
159
172
160
173
/// Returns the 9-bit level 4 page table index.
174
+ #[ inline]
161
175
pub fn p4_index ( & self ) -> PageTableIndex {
162
176
PageTableIndex :: new_truncate ( ( self . 0 >> 12 >> 9 >> 9 >> 9 ) as u16 )
163
177
}
@@ -252,6 +266,7 @@ impl PhysAddr {
252
266
}
253
267
254
268
/// Creates a new physical address, throwing bits 52..64 away.
269
+ #[ inline]
255
270
pub const fn new_truncate ( addr : u64 ) -> PhysAddr {
256
271
PhysAddr ( addr % ( 1 << 52 ) )
257
272
}
@@ -267,18 +282,21 @@ impl PhysAddr {
267
282
}
268
283
269
284
/// Converts the address to an `u64`.
285
+ #[ inline]
270
286
pub fn as_u64 ( self ) -> u64 {
271
287
self . 0
272
288
}
273
289
274
290
/// Convenience method for checking if a physical address is null.
291
+ #[ inline]
275
292
pub fn is_null ( & self ) -> bool {
276
293
self . 0 == 0
277
294
}
278
295
279
296
/// Aligns the physical address upwards to the given alignment.
280
297
///
281
298
/// See the `align_up` function for more information.
299
+ #[ inline]
282
300
pub fn align_up < U > ( self , align : U ) -> Self
283
301
where
284
302
U : Into < u64 > ,
@@ -289,6 +307,7 @@ impl PhysAddr {
289
307
/// Aligns the physical address downwards to the given alignment.
290
308
///
291
309
/// See the `align_down` function for more information.
310
+ #[ inline]
292
311
pub fn align_down < U > ( self , align : U ) -> Self
293
312
where
294
313
U : Into < u64 > ,
@@ -297,6 +316,7 @@ impl PhysAddr {
297
316
}
298
317
299
318
/// Checks whether the physical address has the demanded alignment.
319
+ #[ inline]
300
320
pub fn is_aligned < U > ( self , align : U ) -> bool
301
321
where
302
322
U : Into < u64 > ,
@@ -402,6 +422,7 @@ impl Sub<PhysAddr> for PhysAddr {
402
422
///
403
423
/// Returns the greatest x with alignment `align` so that x <= addr. The alignment must be
404
424
/// a power of 2.
425
+ #[ inline]
405
426
pub fn align_down ( addr : u64 , align : u64 ) -> u64 {
406
427
assert ! ( align. is_power_of_two( ) , "`align` must be a power of two" ) ;
407
428
addr & !( align - 1 )
0 commit comments