|
12 | 12 |
|
13 | 13 | use std::unstable::simd::{i32x4, f32x4, u32x4};
|
14 | 14 |
|
15 |
| -fn test_int(e: i32) -> i32 { |
16 |
| - let v = i32x4(e, 0i32, 0i32, 0i32); |
17 |
| - let i32x4(e2, _, _, _) = v * v + v - v; |
18 |
| - e2 |
| 15 | +fn eq_u32x4(u32x4(x0, x1, x2, x3): u32x4, u32x4(y0, y1, y2, y3): u32x4) -> bool { |
| 16 | + (x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3) |
19 | 17 | }
|
20 | 18 |
|
21 |
| -fn test_float(e: f32) -> f32 { |
22 |
| - let v = f32x4(e, 0f32, 0f32, 0f32); |
23 |
| - let f32x4(e2, _, _, _) = v * v + v - v; |
24 |
| - e2 |
| 19 | +fn eq_f32x4(f32x4(x0, x1, x2, x3): f32x4, f32x4(y0, y1, y2, y3): f32x4) -> bool { |
| 20 | + (x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3) |
25 | 21 | }
|
26 | 22 |
|
27 |
| -pub fn test_shift(e: u32) -> u32 { |
28 |
| - let v = u32x4(e, 0u32, 0u32, 0u32); |
29 |
| - let one = u32x4(1u32, 0u32, 0u32, 0u32); |
30 |
| - let u32x4(e2, _, _, _) = v << one >> one; |
31 |
| - e2 |
| 23 | +fn eq_i32x4(i32x4(x0, x1, x2, x3): i32x4, i32x4(y0, y1, y2, y3): i32x4) -> bool { |
| 24 | + (x0 == y0) && (x1 == y1) && (x2 == y2) && (x3 == y3) |
32 | 25 | }
|
33 | 26 |
|
34 | 27 | pub fn main() {
|
35 |
| - assert_eq!(test_int(3i32), 9i32); |
36 |
| - assert_eq!(test_float(3f32), 9f32); |
37 |
| - assert_eq!(test_shift(3u32), 3u32); |
| 28 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) + u32x4(4, 3, 2, 1), u32x4(5, 5, 5, 5))); |
| 29 | + assert!(eq_u32x4(u32x4(4, 5, 6, 7) - u32x4(4, 3, 2, 1), u32x4(0, 2, 4, 6))); |
| 30 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) * u32x4(4, 3, 2, 1), u32x4(4, 6, 6, 4))); |
| 31 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) & u32x4(4, 3, 2, 1), u32x4(0, 2, 2, 0))); |
| 32 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) | u32x4(4, 3, 2, 1), u32x4(5, 3, 3, 5))); |
| 33 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) ^ u32x4(4, 3, 2, 1), u32x4(5, 1, 1, 5))); |
| 34 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) << u32x4(4, 3, 2, 1), u32x4(16, 16, 12, 8))); |
| 35 | + assert!(eq_u32x4(u32x4(1, 2, 3, 4) >> u32x4(4, 3, 2, 1), u32x4(0, 0, 0, 2))); |
| 36 | + |
| 37 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) + i32x4(4, 3, 2, 1), i32x4(5, 5, 5, 5))); |
| 38 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) - i32x4(4, 3, 2, 1), i32x4(-3, -1, 1, 3))); |
| 39 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) * i32x4(4, 3, 2, 1), i32x4(4, 6, 6, 4))); |
| 40 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) & i32x4(4, 3, 2, 1), i32x4(0, 2, 2, 0))); |
| 41 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) | i32x4(4, 3, 2, 1), i32x4(5, 3, 3, 5))); |
| 42 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) ^ i32x4(4, 3, 2, 1), i32x4(5, 1, 1, 5))); |
| 43 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) << i32x4(4, 3, 2, 1), i32x4(16, 16, 12, 8))); |
| 44 | + assert!(eq_i32x4(i32x4(1, 2, 3, 4) >> i32x4(4, 3, 2, 1), i32x4(0, 0, 0, 2))); |
| 45 | + |
| 46 | + assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) + f32x4(4.0, 3.0, 2.0, 1.0), f32x4(5.0, 5.0, 5.0, 5.0))); |
| 47 | + assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) - f32x4(4.0, 3.0, 2.0, 1.0), f32x4(-3.0, -1.0, 1.0, 3.0))); |
| 48 | + assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) * f32x4(4.0, 3.0, 2.0, 1.0), f32x4(4.0, 6.0, 6.0, 4.0))); |
| 49 | + assert!(eq_f32x4(f32x4(1.0, 2.0, 3.0, 4.0) / f32x4(4.0, 4.0, 2.0, 1.0), f32x4(0.25, 0.5, 1.5, 4.0))); |
38 | 50 | }
|
0 commit comments