| 1 |
use wide::*; |
| 2 |
|
| 3 |
#[test] |
| 4 |
fn size_align() { |
| 5 |
assert_eq!(core::mem::size_of::<i64x2>(), 16); |
| 6 |
assert_eq!(core::mem::align_of::<i64x2>(), 16); |
| 7 |
} |
| 8 |
|
| 9 |
#[test] |
| 10 |
fn basic_traits() { |
| 11 |
crate::test_basic_traits::<i64x2, _, 2>(); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn impl_add_for_i64x2() { |
| 16 |
let a = i64x2::from([i64::MAX - 1, i64::MAX - 1]); |
| 17 |
let b = i64x2::from([1, 2]); |
| 18 |
let expected = i64x2::from([i64::MAX, i64::MIN]); |
| 19 |
let actual = a + b; |
| 20 |
assert_eq!(expected, actual); |
| 21 |
} |
| 22 |
|
| 23 |
#[test] |
| 24 |
fn impl_sub_for_i64x2() { |
| 25 |
let a = i64x2::from([i64::MIN + 1, i64::MIN]); |
| 26 |
let b = i64x2::from([1, 1]); |
| 27 |
let expected = i64x2::from([i64::MIN, i64::MAX]); |
| 28 |
let actual = a - b; |
| 29 |
assert_eq!(expected, actual); |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn impl_mul_for_i64x2() { |
| 34 |
let a = i64x2::from([i64::MIN + 1, 24]); |
| 35 |
let b = i64x2::from([1, -26]); |
| 36 |
let expected = i64x2::from([i64::MIN + 1, 24 * -26]); |
| 37 |
let actual = a * b; |
| 38 |
assert_eq!(expected, actual); |
| 39 |
} |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn impl_bitand_for_i64x2() { |
| 43 |
let a = i64x2::from([1, 1]); |
| 44 |
let b = i64x2::from([0, 1]); |
| 45 |
let expected = i64x2::from([0, 1]); |
| 46 |
let actual = a & b; |
| 47 |
assert_eq!(expected, actual); |
| 48 |
} |
| 49 |
|
| 50 |
#[test] |
| 51 |
fn impl_bitor_for_i64x2() { |
| 52 |
let a = i64x2::from([1, 1]); |
| 53 |
let b = i64x2::from([0, 1]); |
| 54 |
let expected = i64x2::from([1, 1]); |
| 55 |
let actual = a | b; |
| 56 |
assert_eq!(expected, actual); |
| 57 |
} |
| 58 |
|
| 59 |
#[test] |
| 60 |
fn impl_bitxor_for_i64x2() { |
| 61 |
let a = i64x2::from([1, 1]); |
| 62 |
let b = i64x2::from([0, 1]); |
| 63 |
let expected = i64x2::from([1, 0]); |
| 64 |
let actual = a ^ b; |
| 65 |
assert_eq!(expected, actual); |
| 66 |
} |
| 67 |
|
| 68 |
#[test] |
| 69 |
fn impl_shl_for_i64x2() { |
| 70 |
let a = i64x2::from([i64::MAX - 1, i64::MAX - 1]); |
| 71 |
let b = 2; |
| 72 |
let expected = i64x2::from([(i64::MAX - 1) << 2, (i64::MAX - 1) << 2]); |
| 73 |
let actual = a << b; |
| 74 |
assert_eq!(expected, actual); |
| 75 |
} |
| 76 |
|
| 77 |
#[test] |
| 78 |
fn impl_i64x2_blend() { |
| 79 |
let use_t: i64 = -1; |
| 80 |
let t = i64x2::from([1, 2]); |
| 81 |
let f = i64x2::from([17, 18]); |
| 82 |
let mask = i64x2::from([use_t, 0]); |
| 83 |
let expected = i64x2::from([1, 18]); |
| 84 |
let actual = mask.blend(t, f); |
| 85 |
assert_eq!(expected, actual); |
| 86 |
} |
| 87 |
|
| 88 |
#[test] |
| 89 |
fn impl_i64x2_abs() { |
| 90 |
let a = i64x2::from([-1, i64::MIN]); |
| 91 |
let expected = i64x2::from([1, i64::MIN]); |
| 92 |
let actual = a.abs(); |
| 93 |
assert_eq!(expected, actual); |
| 94 |
} |
| 95 |
|
| 96 |
#[test] |
| 97 |
fn impl_i64x2_unsigned_abs() { |
| 98 |
let a = i64x2::from([-1, i64::MIN]); |
| 99 |
let expected = u64x2::from([1, i64::MIN as u64]); |
| 100 |
let actual = a.unsigned_abs(); |
| 101 |
assert_eq!(expected, actual); |
| 102 |
} |
| 103 |
|
| 104 |
#[test] |
| 105 |
fn impl_i64x2_cmp_eq() { |
| 106 |
let a = i64x2::from([1_i64, 4]); |
| 107 |
let b = i64x2::from([3_i64, 4]); |
| 108 |
let expected = i64x2::from([0, -1]); |
| 109 |
let actual = a.cmp_eq(b); |
| 110 |
assert_eq!(expected, actual); |
| 111 |
} |
| 112 |
|
| 113 |
#[test] |
| 114 |
fn impl_i64x2_cmp_gt() { |
| 115 |
let a = i64x2::from([3_i64, 4]); |
| 116 |
let b = i64x2::from([1_i64, 4]); |
| 117 |
let expected = i64x2::from([-1, 0]); |
| 118 |
let actual = a.cmp_gt(b); |
| 119 |
assert_eq!(expected, actual); |
| 120 |
} |
| 121 |
|
| 122 |
#[test] |
| 123 |
fn test_i64x2_any() { |
| 124 |
let a = i64x2::from([3, -1]); |
| 125 |
assert!(a.any()); |
| 126 |
// |
| 127 |
let a = i64x2::from([1, 0]); |
| 128 |
assert!(!a.any()); |
| 129 |
} |
| 130 |
|
| 131 |
#[test] |
| 132 |
fn test_i64x2_all() { |
| 133 |
let a = i64x2::from([-1, -1]); |
| 134 |
assert!(a.all(), "{:?}", a); |
| 135 |
// |
| 136 |
let a = i64x2::from([1, -1]); |
| 137 |
assert!(!a.all()); |
| 138 |
} |
| 139 |
|
| 140 |
#[test] |
| 141 |
fn test_i64x2_none() { |
| 142 |
let a = i64x2::from([1, 0]); |
| 143 |
assert!(a.none()); |
| 144 |
// |
| 145 |
let a = i64x2::from([1, -1]); |
| 146 |
assert!(!a.none()); |
| 147 |
} |
| 148 |
|
| 149 |
#[test] |
| 150 |
fn test_i64x2_move_mask() { |
| 151 |
let a = i64x2::from([-1, 0]); |
| 152 |
let expected = 0b01; |
| 153 |
let actual = a.move_mask(); |
| 154 |
assert_eq!(expected, actual); |
| 155 |
// |
| 156 |
let a = i64x2::from([1, -1]); |
| 157 |
let expected = 0b10; |
| 158 |
let actual = a.move_mask(); |
| 159 |
assert_eq!(expected, actual); |
| 160 |
|
| 161 |
crate::test_random_vector_vs_scalar_reduce( |
| 162 |
|a: i64x2| a.move_mask(), |
| 163 |
0i32, |
| 164 |
|acc, a, idx| acc | if a < 0 { 1 << idx } else { 0 }, |
| 165 |
); |
| 166 |
} |
| 167 |
|
| 168 |
#[cfg(feature = "serde")] |
| 169 |
#[test] |
| 170 |
fn impl_i64x2_ser_de_roundtrip() { |
| 171 |
let serialized = |
| 172 |
bincode::serialize(&i64x2::ZERO).expect("serialization failed"); |
| 173 |
let deserialized = |
| 174 |
bincode::deserialize(&serialized).expect("deserializaion failed"); |
| 175 |
assert_eq!(i64x2::ZERO, deserialized); |
| 176 |
} |