@@ -6,7 +6,7 @@ macro_rules! impl_unary_op_test {
6
6
{ $scalar: ty, $trait: ident :: $fn: ident, $scalar_fn: expr } => {
7
7
test_helpers:: test_lanes! {
8
8
fn $fn<const LANES : usize >( ) {
9
- test_helpers:: test_unary_elementwise (
9
+ test_helpers:: test_unary_elementwise_flush_subnormals (
10
10
& <core_simd:: simd:: Simd <$scalar, LANES > as core:: ops:: $trait>:: $fn,
11
11
& $scalar_fn,
12
12
& |_| true ,
@@ -31,15 +31,15 @@ macro_rules! impl_binary_op_test {
31
31
32
32
test_helpers:: test_lanes! {
33
33
fn normal<const LANES : usize >( ) {
34
- test_helpers:: test_binary_elementwise (
34
+ test_helpers:: test_binary_elementwise_flush_subnormals (
35
35
& <Simd <$scalar, LANES > as core:: ops:: $trait>:: $fn,
36
36
& $scalar_fn,
37
37
& |_, _| true ,
38
38
) ;
39
39
}
40
40
41
41
fn assign<const LANES : usize >( ) {
42
- test_helpers:: test_binary_elementwise (
42
+ test_helpers:: test_binary_elementwise_flush_subnormals (
43
43
& |mut a, b| { <Simd <$scalar, LANES > as core:: ops:: $trait_assign>:: $fn_assign( & mut a, b) ; a } ,
44
44
& $scalar_fn,
45
45
& |_, _| true ,
@@ -126,19 +126,23 @@ macro_rules! impl_common_integer_tests {
126
126
127
127
fn reduce_sum<const LANES : usize >( ) {
128
128
test_helpers:: test_1( & |x| {
129
+ use test_helpers:: subnormals:: { flush, flush_in} ;
129
130
test_helpers:: prop_assert_biteq! (
130
131
$vector:: <LANES >:: from_array( x) . reduce_sum( ) ,
131
132
x. iter( ) . copied( ) . fold( 0 as $scalar, $scalar:: wrapping_add) ,
133
+ flush( x. iter( ) . copied( ) . map( flush_in) . fold( 0 as $scalar, $scalar:: wrapping_add) ) ,
132
134
) ;
133
135
Ok ( ( ) )
134
136
} ) ;
135
137
}
136
138
137
139
fn reduce_product<const LANES : usize >( ) {
138
140
test_helpers:: test_1( & |x| {
141
+ use test_helpers:: subnormals:: { flush, flush_in} ;
139
142
test_helpers:: prop_assert_biteq! (
140
143
$vector:: <LANES >:: from_array( x) . reduce_product( ) ,
141
144
x. iter( ) . copied( ) . fold( 1 as $scalar, $scalar:: wrapping_mul) ,
145
+ flush( x. iter( ) . copied( ) . map( flush_in) . fold( 1 as $scalar, $scalar:: wrapping_mul) ) ,
142
146
) ;
143
147
Ok ( ( ) )
144
148
} ) ;
@@ -463,15 +467,15 @@ macro_rules! impl_float_tests {
463
467
}
464
468
465
469
fn to_degrees<const LANES : usize >( ) {
466
- test_helpers:: test_unary_elementwise (
470
+ test_helpers:: test_unary_elementwise_flush_subnormals (
467
471
& Vector :: <LANES >:: to_degrees,
468
472
& Scalar :: to_degrees,
469
473
& |_| true ,
470
474
)
471
475
}
472
476
473
477
fn to_radians<const LANES : usize >( ) {
474
- test_helpers:: test_unary_elementwise (
478
+ test_helpers:: test_unary_elementwise_flush_subnormals (
475
479
& Vector :: <LANES >:: to_radians,
476
480
& Scalar :: to_radians,
477
481
& |_| true ,
@@ -541,7 +545,12 @@ macro_rules! impl_float_tests {
541
545
}
542
546
543
547
fn simd_clamp<const LANES : usize >( ) {
548
+ if cfg!( all( target_arch = "powerpc64" , target_feature = "vsx" ) ) {
549
+ // https://gitlab.com/qemu-project/qemu/-/issues/1780
550
+ return ;
551
+ }
544
552
test_helpers:: test_3( & |value: [ Scalar ; LANES ] , mut min: [ Scalar ; LANES ] , mut max: [ Scalar ; LANES ] | {
553
+ use test_helpers:: subnormals:: flush_in;
545
554
for ( min, max) in min. iter_mut( ) . zip( max. iter_mut( ) ) {
546
555
if max < min {
547
556
core:: mem:: swap( min, max) ;
@@ -558,8 +567,20 @@ macro_rules! impl_float_tests {
558
567
for i in 0 ..LANES {
559
568
result_scalar[ i] = value[ i] . clamp( min[ i] , max[ i] ) ;
560
569
}
570
+ let mut result_scalar_flush = [ Scalar :: default ( ) ; LANES ] ;
571
+ for i in 0 ..LANES {
572
+ // Comparisons flush-to-zero, but return value selection is _not_ flushed.
573
+ let mut value = value[ i] ;
574
+ if flush_in( value) < flush_in( min[ i] ) {
575
+ value = min[ i] ;
576
+ }
577
+ if flush_in( value) > flush_in( max[ i] ) {
578
+ value = max[ i] ;
579
+ }
580
+ result_scalar_flush[ i] = value
581
+ }
561
582
let result_vector = Vector :: from_array( value) . simd_clamp( min. into( ) , max. into( ) ) . to_array( ) ;
562
- test_helpers:: prop_assert_biteq!( result_scalar, result_vector ) ;
583
+ test_helpers:: prop_assert_biteq!( result_vector , result_scalar, result_scalar_flush ) ;
563
584
Ok ( ( ) )
564
585
} )
565
586
}
0 commit comments