@@ -28,6 +28,7 @@ use std::mem;
2828use std:: mem:: MaybeUninit ;
2929use std:: ptr;
3030use std:: slice;
31+ use zerocopy:: AsBytes ;
3132use zerocopy:: FromZeroes ;
3233
3334#[ derive( Clone , Copy , Default , PartialEq , Eq ) ]
@@ -38,7 +39,7 @@ pub struct RefMvsTemporalBlock {
3839}
3940const _: ( ) = assert ! ( mem:: size_of:: <RefMvsTemporalBlock >( ) == 5 ) ;
4041
41- #[ derive( Clone , Copy , PartialEq , Eq , FromZeroes ) ]
42+ #[ derive( Clone , Copy , Eq , FromZeroes , AsBytes ) ]
4243// In C, this is packed and is 2 bytes.
4344// In Rust, being packed and aligned is tricky
4445#[ repr( C , align( 2 ) ) ]
@@ -47,19 +48,42 @@ pub struct RefMvsRefPair {
4748}
4849const _: ( ) = assert ! ( mem:: size_of:: <RefMvsRefPair >( ) == 2 ) ;
4950
51+ impl PartialEq for RefMvsRefPair {
52+ #[ inline( always) ]
53+ fn eq ( & self , other : & Self ) -> bool {
54+ // `#[derive(PartialEq)]` compares per-field with `&&`,
55+ // which isn't optimized well and isn't coalesced into wider loads.
56+ // Comparing all of the bytes at once optimizes better with wider loads.
57+ // See <https://github.com/rust-lang/rust/issues/140167>.
58+ self . as_bytes ( ) == other. as_bytes ( )
59+ }
60+ }
61+
5062impl From < [ i8 ; 2 ] > for RefMvsRefPair {
5163 fn from ( from : [ i8 ; 2 ] ) -> Self {
5264 RefMvsRefPair { r#ref : from }
5365 }
5466}
5567
56- #[ derive( Clone , Copy , Default , PartialEq , Eq , FromZeroes ) ]
68+ #[ derive( Clone , Copy , Default , Eq , FromZeroes , AsBytes ) ]
5769#[ repr( C ) ]
70+ #[ repr( align( 4 ) ) ] // Is a `union` with a `uint64_t` in C, so `align(8)`, but `align(8)` doesn't allow `align(4)` for `RefMvsBlock`.
5871pub struct RefMvsMvPair {
5972 pub mv : [ Mv ; 2 ] ,
6073}
6174const _: ( ) = assert ! ( mem:: size_of:: <RefMvsMvPair >( ) == 8 ) ;
6275
76+ impl PartialEq for RefMvsMvPair {
77+ #[ inline( always) ]
78+ fn eq ( & self , other : & Self ) -> bool {
79+ // `#[derive(PartialEq)]` compares per-field with `&&`,
80+ // which isn't optimized well and isn't coalesced into wider loads.
81+ // Comparing all of the bytes at once optimizes better with wider loads.
82+ // See <https://github.com/rust-lang/rust/issues/140167>.
83+ self . as_bytes ( ) == other. as_bytes ( )
84+ }
85+ }
86+
6387#[ derive( Clone , Copy , FromZeroes ) ]
6488// In C, this is packed and is 12 bytes.
6589// In Rust, being packed and aligned is tricky
0 commit comments