@@ -285,11 +285,11 @@ impl Size {
285
285
}
286
286
287
287
/// Alignment of a type in bytes, both ABI-mandated and preferred.
288
- /// Since alignments are always powers of 2, we can pack both in one byte,
289
- /// giving each a nibble (4 bits) for a maximum alignment of 2<sup>15</sup> = 32768.
288
+ /// Each field is a power of two.
290
289
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
291
290
pub struct Align {
292
- raw : u8
291
+ abi : u8 ,
292
+ pref : u8 ,
293
293
}
294
294
295
295
impl Align {
@@ -312,39 +312,36 @@ impl Align {
312
312
}
313
313
if bytes != 1 {
314
314
Err ( format ! ( "`{}` is not a power of 2" , align) )
315
- } else if pow > 0x0f {
316
- Err ( format ! ( "`{}` is too large" , align) )
317
315
} else {
318
316
Ok ( pow)
319
317
}
320
318
} ;
321
319
322
320
Ok ( Align {
323
- raw : pack ( abi) ? | ( pack ( pref) ? << 4 )
321
+ abi : pack ( abi) ?,
322
+ pref : pack ( pref) ?,
324
323
} )
325
324
}
326
325
327
326
pub fn abi ( self ) -> u64 {
328
- 1 << ( self . raw & 0xf )
327
+ 1 << self . abi
329
328
}
330
329
331
330
pub fn pref ( self ) -> u64 {
332
- 1 << ( self . raw >> 4 )
331
+ 1 << self . pref
333
332
}
334
333
335
334
pub fn min ( self , other : Align ) -> Align {
336
- let abi = cmp:: min ( self . raw & 0x0f , other. raw & 0x0f ) ;
337
- let pref = cmp:: min ( self . raw & 0xf0 , other. raw & 0xf0 ) ;
338
335
Align {
339
- raw : abi | pref
336
+ abi : cmp:: min ( self . abi , other. abi ) ,
337
+ pref : cmp:: min ( self . pref , other. pref ) ,
340
338
}
341
339
}
342
340
343
341
pub fn max ( self , other : Align ) -> Align {
344
- let abi = cmp:: max ( self . raw & 0x0f , other. raw & 0x0f ) ;
345
- let pref = cmp:: max ( self . raw & 0xf0 , other. raw & 0xf0 ) ;
346
342
Align {
347
- raw : abi | pref
343
+ abi : cmp:: max ( self . abi , other. abi ) ,
344
+ pref : cmp:: max ( self . pref , other. pref ) ,
348
345
}
349
346
}
350
347
}
0 commit comments