@@ -4196,7 +4196,8 @@ mod tests {
4196
4196
let mut buf = Align :: < [ u8 ; 8 ] , AU64 > :: default ( ) ;
4197
4197
// `buf.t` should be aligned to 8, so this should always succeed.
4198
4198
test_new_helper ( Ref :: < _ , AU64 > :: new ( & mut buf. t [ ..] ) . unwrap ( ) ) ;
4199
- buf. t = [ 0xFFu8 ; 8 ] ;
4199
+ let ascending: [ u8 ; 8 ] = ( 0 ..8 ) . collect :: < Vec < _ > > ( ) . try_into ( ) . unwrap ( ) ;
4200
+ buf. t = ascending;
4200
4201
test_new_helper ( Ref :: < _ , AU64 > :: new_zeroed ( & mut buf. t [ ..] ) . unwrap ( ) ) ;
4201
4202
{
4202
4203
// In a block so that `r` and `suffix` don't live too long.
@@ -4206,7 +4207,7 @@ mod tests {
4206
4207
test_new_helper ( r) ;
4207
4208
}
4208
4209
{
4209
- buf. t = [ 0xFFu8 ; 8 ] ;
4210
+ buf. t = ascending ;
4210
4211
let ( r, suffix) = Ref :: < _ , AU64 > :: new_from_prefix_zeroed ( & mut buf. t [ ..] ) . unwrap ( ) ;
4211
4212
assert ! ( suffix. is_empty( ) ) ;
4212
4213
test_new_helper ( r) ;
@@ -4218,46 +4219,54 @@ mod tests {
4218
4219
test_new_helper ( r) ;
4219
4220
}
4220
4221
{
4221
- buf. t = [ 0xFFu8 ; 8 ] ;
4222
+ buf. t = ascending ;
4222
4223
let ( prefix, r) = Ref :: < _ , AU64 > :: new_from_suffix_zeroed ( & mut buf. t [ ..] ) . unwrap ( ) ;
4223
4224
assert ! ( prefix. is_empty( ) ) ;
4224
4225
test_new_helper ( r) ;
4225
4226
}
4226
4227
4227
- // A buffer with alignment 8 and length 16.
4228
- let mut buf = Align :: < [ u8 ; 16 ] , AU64 > :: default ( ) ;
4228
+ // A buffer with alignment 8 and length 24. We choose this length very
4229
+ // intentionally: if we instead used length 16, then the prefix and
4230
+ // suffix lengths would be identical. In the past, we used length 16,
4231
+ // which resulted in this test failing to discover the bug uncovered in
4232
+ // #506.
4233
+ let mut buf = Align :: < [ u8 ; 24 ] , AU64 > :: default ( ) ;
4229
4234
// `buf.t` should be aligned to 8 and have a length which is a multiple
4230
4235
// of `size_of::<AU64>()`, so this should always succeed.
4231
- test_new_helper_slice ( Ref :: < _ , [ AU64 ] > :: new_slice ( & mut buf. t [ ..] ) . unwrap ( ) , 2 ) ;
4232
- buf. t = [ 0xFFu8 ; 16 ] ;
4233
- test_new_helper_slice ( Ref :: < _ , [ AU64 ] > :: new_slice_zeroed ( & mut buf. t [ ..] ) . unwrap ( ) , 2 ) ;
4236
+ test_new_helper_slice ( Ref :: < _ , [ AU64 ] > :: new_slice ( & mut buf. t [ ..] ) . unwrap ( ) , 3 ) ;
4237
+ let ascending: [ u8 ; 24 ] = ( 0 ..24 ) . collect :: < Vec < _ > > ( ) . try_into ( ) . unwrap ( ) ;
4238
+ // 16 ascending bytes followed by 8 zeros.
4239
+ let mut ascending_prefix = ascending;
4240
+ ascending_prefix[ 16 ..] . copy_from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
4241
+ // 8 zeros followed by 16 ascending bytes.
4242
+ let mut ascending_suffix = ascending;
4243
+ ascending_suffix[ ..8 ] . copy_from_slice ( & [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
4244
+ test_new_helper_slice ( Ref :: < _ , [ AU64 ] > :: new_slice_zeroed ( & mut buf. t [ ..] ) . unwrap ( ) , 3 ) ;
4234
4245
4235
4246
{
4236
- buf. set_default ( ) ;
4237
- buf. t [ 8 ..] . fill ( 0xFF ) ;
4247
+ buf. t = ascending_suffix;
4238
4248
let ( r, suffix) = Ref :: < _ , [ AU64 ] > :: new_slice_from_prefix ( & mut buf. t [ ..] , 1 ) . unwrap ( ) ;
4239
- assert_eq ! ( suffix, [ 0xFF ; 8 ] ) ;
4249
+ assert_eq ! ( suffix, & ascending [ 8 .. ] ) ;
4240
4250
test_new_helper_slice ( r, 1 ) ;
4241
4251
}
4242
4252
{
4243
- buf. t = [ 0xFFu8 ; 16 ] ;
4253
+ buf. t = ascending_suffix ;
4244
4254
let ( r, suffix) =
4245
4255
Ref :: < _ , [ AU64 ] > :: new_slice_from_prefix_zeroed ( & mut buf. t [ ..] , 1 ) . unwrap ( ) ;
4246
- assert_eq ! ( suffix, [ 0xFF ; 8 ] ) ;
4256
+ assert_eq ! ( suffix, & ascending [ 8 .. ] ) ;
4247
4257
test_new_helper_slice ( r, 1 ) ;
4248
4258
}
4249
4259
{
4250
- buf. set_default ( ) ;
4251
- buf. t [ ..8 ] . fill ( 0xFF ) ;
4260
+ buf. t = ascending_prefix;
4252
4261
let ( prefix, r) = Ref :: < _ , [ AU64 ] > :: new_slice_from_suffix ( & mut buf. t [ ..] , 1 ) . unwrap ( ) ;
4253
- assert_eq ! ( prefix, [ 0xFF ; 8 ] ) ;
4262
+ assert_eq ! ( prefix, & ascending [ .. 16 ] ) ;
4254
4263
test_new_helper_slice ( r, 1 ) ;
4255
4264
}
4256
4265
{
4257
- buf. t = [ 0xFFu8 ; 16 ] ;
4266
+ buf. t = ascending_prefix ;
4258
4267
let ( prefix, r) =
4259
4268
Ref :: < _ , [ AU64 ] > :: new_slice_from_suffix_zeroed ( & mut buf. t [ ..] , 1 ) . unwrap ( ) ;
4260
- assert_eq ! ( prefix, [ 0xFF ; 8 ] ) ;
4269
+ assert_eq ! ( prefix, & ascending [ .. 16 ] ) ;
4261
4270
test_new_helper_slice ( r, 1 ) ;
4262
4271
}
4263
4272
}
@@ -4835,5 +4844,58 @@ mod tests {
4835
4844
assert_impls ! ( [ NotZerocopy ; 0 ] : !FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
4836
4845
assert_impls ! ( [ u8 ; 1 ] : FromZeroes , FromBytes , AsBytes , Unaligned ) ;
4837
4846
assert_impls ! ( [ NotZerocopy ; 1 ] : !FromZeroes , !FromBytes , !AsBytes , !Unaligned ) ;
4847
+
4848
+ #[ cfg( feature = "simd" ) ]
4849
+ {
4850
+ macro_rules! test_simd_arch_mod {
4851
+ ( $arch: ident, $( $typ: ident) ,* ) => {
4852
+ {
4853
+ use core:: arch:: $arch:: { $( $typ) ,* } ;
4854
+ use crate :: * ;
4855
+ $( assert_impls!( $typ: KnownLayout , FromZeroes , FromBytes , AsBytes , !Unaligned ) ; ) *
4856
+ }
4857
+ } ;
4858
+ }
4859
+ #[ cfg( target_arch = "x86" ) ]
4860
+ test_simd_arch_mod ! ( x86, __m128, __m128d, __m128i, __m256, __m256d, __m256i) ;
4861
+
4862
+ #[ cfg( target_arch = "x86_64" ) ]
4863
+ test_simd_arch_mod ! ( x86_64, __m128, __m128d, __m128i, __m256, __m256d, __m256i) ;
4864
+
4865
+ #[ cfg( target_arch = "wasm32" ) ]
4866
+ test_simd_arch_mod ! ( wasm32, v128) ;
4867
+
4868
+ #[ cfg( all( feature = "simd-nightly" , target_arch = "powerpc" ) ) ]
4869
+ test_simd_arch_mod ! (
4870
+ powerpc,
4871
+ vector_bool_long,
4872
+ vector_double,
4873
+ vector_signed_long,
4874
+ vector_unsigned_long
4875
+ ) ;
4876
+
4877
+ #[ cfg( all( feature = "simd-nightly" , target_arch = "powerpc64" ) ) ]
4878
+ test_simd_arch_mod ! (
4879
+ powerpc64,
4880
+ vector_bool_long,
4881
+ vector_double,
4882
+ vector_signed_long,
4883
+ vector_unsigned_long
4884
+ ) ;
4885
+ #[ cfg( target_arch = "aarch64" ) ]
4886
+ #[ rustfmt:: skip]
4887
+ test_simd_arch_mod ! (
4888
+ aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,
4889
+ int8x8x3_t, int8x8x4_t, int8x16_t, int8x16x2_t, int8x16x3_t, int8x16x4_t, int16x4_t,
4890
+ int16x8_t, int32x2_t, int32x4_t, int64x1_t, int64x2_t, poly8x8_t, poly8x8x2_t, poly8x8x3_t,
4891
+ poly8x8x4_t, poly8x16_t, poly8x16x2_t, poly8x16x3_t, poly8x16x4_t, poly16x4_t, poly16x8_t,
4892
+ poly64x1_t, poly64x2_t, uint8x8_t, uint8x8x2_t, uint8x8x3_t, uint8x8x4_t, uint8x16_t,
4893
+ uint8x16x2_t, uint8x16x3_t, uint8x16x4_t, uint16x4_t, uint16x8_t, uint32x2_t, uint32x4_t,
4894
+ uint64x1_t, uint64x2_t
4895
+ ) ;
4896
+ #[ cfg( all( feature = "simd-nightly" , target_arch = "arm" ) ) ]
4897
+ #[ rustfmt:: skip]
4898
+ test_simd_arch_mod ! ( arm, int8x4_t, uint8x4_t) ;
4899
+ }
4838
4900
}
4839
4901
}
0 commit comments