@@ -3,18 +3,34 @@ use std::simd::*;
33
44fn simd_ops_f32 ( ) {
55 let a = f32x4:: splat ( 10.0 ) ;
6- let b = f32x4:: from_array ( [ 1.0 , 2.0 , 3.0 , 4.0 ] ) ;
7- assert_eq ! ( a + b, f32x4:: from_array( [ 11.0 , 12.0 , 13.0 , 14.0 ] ) ) ;
8- assert_eq ! ( a - b, f32x4:: from_array( [ 9.0 , 8.0 , 7.0 , 6.0 ] ) ) ;
9- assert_eq ! ( a * b, f32x4:: from_array( [ 10.0 , 20.0 , 30.0 , 40.0 ] ) ) ;
10- assert_eq ! ( b / a, f32x4:: from_array( [ 0.1 , 0.2 , 0.3 , 0.4 ] ) ) ;
6+ let b = f32x4:: from_array ( [ 1.0 , 2.0 , 3.0 , -4.0 ] ) ;
7+ assert_eq ! ( -b, f32x4:: from_array( [ -1.0 , -2.0 , -3.0 , 4.0 ] ) ) ;
8+ assert_eq ! ( a + b, f32x4:: from_array( [ 11.0 , 12.0 , 13.0 , 6.0 ] ) ) ;
9+ assert_eq ! ( a - b, f32x4:: from_array( [ 9.0 , 8.0 , 7.0 , 14.0 ] ) ) ;
10+ assert_eq ! ( a * b, f32x4:: from_array( [ 10.0 , 20.0 , 30.0 , -40.0 ] ) ) ;
11+ assert_eq ! ( b / a, f32x4:: from_array( [ 0.1 , 0.2 , 0.3 , -0.4 ] ) ) ;
1112 assert_eq ! ( a / f32x4:: splat( 2.0 ) , f32x4:: splat( 5.0 ) ) ;
1213 assert_eq ! ( a % b, f32x4:: from_array( [ 0.0 , 0.0 , 1.0 , 2.0 ] ) ) ;
14+ assert_eq ! ( b. abs( ) , f32x4:: from_array( [ 1.0 , 2.0 , 3.0 , 4.0 ] ) ) ;
15+ }
16+
17+ fn simd_ops_f64 ( ) {
18+ let a = f64x4:: splat ( 10.0 ) ;
19+ let b = f64x4:: from_array ( [ 1.0 , 2.0 , 3.0 , -4.0 ] ) ;
20+ assert_eq ! ( -b, f64x4:: from_array( [ -1.0 , -2.0 , -3.0 , 4.0 ] ) ) ;
21+ assert_eq ! ( a + b, f64x4:: from_array( [ 11.0 , 12.0 , 13.0 , 6.0 ] ) ) ;
22+ assert_eq ! ( a - b, f64x4:: from_array( [ 9.0 , 8.0 , 7.0 , 14.0 ] ) ) ;
23+ assert_eq ! ( a * b, f64x4:: from_array( [ 10.0 , 20.0 , 30.0 , -40.0 ] ) ) ;
24+ assert_eq ! ( b / a, f64x4:: from_array( [ 0.1 , 0.2 , 0.3 , -0.4 ] ) ) ;
25+ assert_eq ! ( a / f64x4:: splat( 2.0 ) , f64x4:: splat( 5.0 ) ) ;
26+ assert_eq ! ( a % b, f64x4:: from_array( [ 0.0 , 0.0 , 1.0 , 2.0 ] ) ) ;
27+ assert_eq ! ( b. abs( ) , f64x4:: from_array( [ 1.0 , 2.0 , 3.0 , 4.0 ] ) ) ;
1328}
1429
1530fn simd_ops_i32 ( ) {
1631 let a = i32x4:: splat ( 10 ) ;
1732 let b = i32x4:: from_array ( [ 1 , 2 , 3 , 4 ] ) ;
33+ assert_eq ! ( -b, i32x4:: from_array( [ -1 , -2 , -3 , -4 ] ) ) ;
1834 assert_eq ! ( a + b, i32x4:: from_array( [ 11 , 12 , 13 , 14 ] ) ) ;
1935 assert_eq ! ( a - b, i32x4:: from_array( [ 9 , 8 , 7 , 6 ] ) ) ;
2036 assert_eq ! ( a * b, i32x4:: from_array( [ 10 , 20 , 30 , 40 ] ) ) ;
@@ -52,6 +68,7 @@ fn simd_intrinsics() {
5268
5369fn main ( ) {
5470 simd_ops_f32 ( ) ;
71+ simd_ops_f64 ( ) ;
5572 simd_ops_i32 ( ) ;
5673 simd_intrinsics ( ) ;
5774}
0 commit comments