|
10 | 10 |
|
11 | 11 | use crate::core_arch::powerpc::*; |
12 | 12 | use crate::core_arch::simd::*; |
| 13 | +use crate::intrinsics::simd::*; |
13 | 14 |
|
14 | 15 | #[cfg(test)] |
15 | 16 | use stdarch_test::assert_instr; |
@@ -173,6 +174,64 @@ mod sealed { |
173 | 174 | vec_mergeeo! { vector_float, mergee, mergeo } |
174 | 175 | } |
175 | 176 |
|
| 177 | +// Macro to implement VectorCmpEq trait for vector types. |
| 178 | +macro_rules! impl_vec_cmpeq { |
| 179 | + ($vec_ty:ident, $result_ty:ident, $mask_ty:ident, $instr:ident) => { |
| 180 | + #[unstable(feature = "stdarch_powerpc", issue = "111145")] |
| 181 | + impl crate::core_arch::powerpc::altivec::sealed::VectorCmpEq<$vec_ty> for $vec_ty { |
| 182 | + type Result = $result_ty; |
| 183 | + #[inline] |
| 184 | + #[target_feature(enable = "vsx")] |
| 185 | + #[cfg_attr(test, assert_instr($instr))] |
| 186 | + unsafe fn vec_cmpeq(self, b: $vec_ty) -> Self::Result { |
| 187 | + let result: $mask_ty = simd_eq(self, b); |
| 188 | + transmute(result) |
| 189 | + } |
| 190 | + } |
| 191 | + }; |
| 192 | +} |
| 193 | +impl_vec_cmpeq!(vector_float, vector_bool_int, m32x4, xvcmpeqsp); |
| 194 | +impl_vec_cmpeq!(vector_double, vector_bool_long, m64x2, xvcmpeqdp); |
| 195 | + |
| 196 | +// Macro to implement VectorCmpGt trait for vector types. |
| 197 | +macro_rules! impl_vec_cmpgt { |
| 198 | + ($vec_ty:ident, $result_ty:ident, $mask_ty:ident, $instr:ident) => { |
| 199 | + #[unstable(feature = "stdarch_powerpc", issue = "111145")] |
| 200 | + impl crate::core_arch::powerpc::altivec::sealed::VectorCmpGt<$vec_ty> for $vec_ty { |
| 201 | + type Result = $result_ty; |
| 202 | + #[inline] |
| 203 | + #[target_feature(enable = "vsx")] |
| 204 | + #[cfg_attr(test, assert_instr($instr))] |
| 205 | + unsafe fn vec_cmpgt(self, b: $vec_ty) -> Self::Result { |
| 206 | + let result: $mask_ty = simd_gt(self, b); |
| 207 | + transmute(result) |
| 208 | + } |
| 209 | + } |
| 210 | + }; |
| 211 | +} |
| 212 | +impl_vec_cmpgt!(vector_float, vector_bool_int, m32x4, xvcmpgtsp); |
| 213 | +impl_vec_cmpgt!(vector_double, vector_bool_long, m64x2, xvcmpgtdp); |
| 214 | + |
| 215 | +// Macro to implement VectorCmpGe trait for vector types. |
| 216 | +macro_rules! impl_vec_cmpge { |
| 217 | + ($vec_ty:ident, $result_ty:ident, $mask_ty:ident, $instr:ident) => { |
| 218 | + #[cfg(target_feature = "vsx")] |
| 219 | + #[unstable(feature = "stdarch_powerpc", issue = "111145")] |
| 220 | + impl crate::core_arch::powerpc::altivec::sealed::VectorCmpGe<$vec_ty> for $vec_ty { |
| 221 | + type Result = $result_ty; |
| 222 | + #[inline] |
| 223 | + #[target_feature(enable = "vsx")] |
| 224 | + #[cfg_attr(test, assert_instr($instr))] |
| 225 | + unsafe fn vec_cmpge(self, b: $vec_ty) -> Self::Result { |
| 226 | + let result: $mask_ty = simd_ge(self, b); |
| 227 | + transmute(result) |
| 228 | + } |
| 229 | + } |
| 230 | + }; |
| 231 | +} |
| 232 | +impl_vec_cmpge!(vector_float, vector_bool_int, m32x4, xvcmpgesp); |
| 233 | +impl_vec_cmpge!(vector_double, vector_bool_long, m64x2, xvcmpgedp); |
| 234 | + |
176 | 235 | /// Vector permute. |
177 | 236 | #[inline] |
178 | 237 | #[target_feature(enable = "vsx")] |
@@ -255,4 +314,98 @@ mod tests { |
255 | 314 | test_vec_xxpermdi! {test_vec_xxpermdi_i64x2, i64x2, vector_signed_long, [0], [-1], [2], [-3]} |
256 | 315 | test_vec_xxpermdi! {test_vec_xxpermdi_m64x2, m64x2, vector_bool_long, [false], [true], [false], [true]} |
257 | 316 | test_vec_xxpermdi! {test_vec_xxpermdi_f64x2, f64x2, vector_double, [0.0], [1.0], [2.0], [3.0]} |
| 317 | + |
| 318 | + #[simd_test(enable = "vsx")] |
| 319 | + fn test_vec_cmpeq_f32x4() { |
| 320 | + let a = vector_float::from(f32x4::from_array([1.0, 2.0, 3.0, 4.0])); |
| 321 | + let b = vector_float::from(f32x4::from_array([1.0, 3.0, 3.0, 5.0])); |
| 322 | + |
| 323 | + unsafe { |
| 324 | + let result: vector_bool_int = vec_cmpeq(a, b); |
| 325 | + // Elements 0 and 2 are equal, elements 1 and 3 are not equal. |
| 326 | + // Equal elements should have all bits set (-1), non-equal should be 0. |
| 327 | + let result_i32: i32x4 = transmute(result); |
| 328 | + assert_eq!(result_i32.as_array()[0], -1i32); |
| 329 | + assert_eq!(result_i32.as_array()[1], 0i32); |
| 330 | + assert_eq!(result_i32.as_array()[2], -1i32); |
| 331 | + assert_eq!(result_i32.as_array()[3], 0i32); |
| 332 | + } |
| 333 | + } |
| 334 | + |
| 335 | + #[simd_test(enable = "vsx")] |
| 336 | + fn test_vec_cmpeq_f64x2() { |
| 337 | + let a = vector_double::from(f64x2::from_array([1.0, 2.0])); |
| 338 | + let b = vector_double::from(f64x2::from_array([1.0, 3.0])); |
| 339 | + |
| 340 | + unsafe { |
| 341 | + let result: vector_bool_long = vec_cmpeq(a, b); |
| 342 | + // First element equal (1.0 == 1.0), second not equal (2.0 != 3.0). |
| 343 | + // Equal elements should have all bits set (-1), non-equal should be 0. |
| 344 | + let result_i64: i64x2 = transmute(result); |
| 345 | + assert_eq!(result_i64.as_array()[0], -1i64); |
| 346 | + assert_eq!(result_i64.as_array()[1], 0i64); |
| 347 | + } |
| 348 | + } |
| 349 | + |
| 350 | + #[simd_test(enable = "vsx")] |
| 351 | + fn test_vec_cmpgt_f32x4() { |
| 352 | + let a = vector_float::from(f32x4::from_array([1.0, 2.0, 3.0, 4.0])); |
| 353 | + let b = vector_float::from(f32x4::from_array([0.0, 3.0, 3.0, 5.0])); |
| 354 | + |
| 355 | + unsafe { |
| 356 | + let result: vector_bool_int = vec_cmpgt(a, b); |
| 357 | + // Element 0: 1.0 > 0.0 (true), Element 1: 2.0 > 3.0 (false) |
| 358 | + // Element 2: 3.0 > 3.0 (false), Element 3: 4.0 > 5.0 (false) |
| 359 | + let result_i32: i32x4 = transmute(result); |
| 360 | + assert_eq!(result_i32.as_array()[0], -1i32); |
| 361 | + assert_eq!(result_i32.as_array()[1], 0i32); |
| 362 | + assert_eq!(result_i32.as_array()[2], 0i32); |
| 363 | + assert_eq!(result_i32.as_array()[3], 0i32); |
| 364 | + } |
| 365 | + } |
| 366 | + |
| 367 | + #[simd_test(enable = "vsx")] |
| 368 | + fn test_vec_cmpgt_f64x2() { |
| 369 | + let a = vector_double::from(f64x2::from_array([2.0, 1.0])); |
| 370 | + let b = vector_double::from(f64x2::from_array([1.0, 3.0])); |
| 371 | + |
| 372 | + unsafe { |
| 373 | + let result: vector_bool_long = vec_cmpgt(a, b); |
| 374 | + // First element: 2.0 > 1.0 (true), second: 1.0 > 3.0 (false) |
| 375 | + let result_i64: i64x2 = transmute(result); |
| 376 | + assert_eq!(result_i64.as_array()[0], -1i64); |
| 377 | + assert_eq!(result_i64.as_array()[1], 0i64); |
| 378 | + } |
| 379 | + } |
| 380 | + |
| 381 | + #[simd_test(enable = "vsx")] |
| 382 | + fn test_vec_cmpge_f32x4() { |
| 383 | + let a = vector_float::from(f32x4::from_array([1.0, 2.0, 3.0, 4.0])); |
| 384 | + let b = vector_float::from(f32x4::from_array([0.0, 3.0, 3.0, 5.0])); |
| 385 | + |
| 386 | + unsafe { |
| 387 | + let result: vector_bool_int = vec_cmpge(a, b); |
| 388 | + // Element 0: 1.0 >= 0.0 (true), Element 1: 2.0 >= 3.0 (false) |
| 389 | + // Element 2: 3.0 >= 3.0 (true), Element 3: 4.0 >= 5.0 (false) |
| 390 | + let result_i32: i32x4 = transmute(result); |
| 391 | + assert_eq!(result_i32.as_array()[0], -1i32); |
| 392 | + assert_eq!(result_i32.as_array()[1], 0i32); |
| 393 | + assert_eq!(result_i32.as_array()[2], -1i32); |
| 394 | + assert_eq!(result_i32.as_array()[3], 0i32); |
| 395 | + } |
| 396 | + } |
| 397 | + |
| 398 | + #[simd_test(enable = "vsx")] |
| 399 | + fn test_vec_cmpge_f64x2() { |
| 400 | + let a = vector_double::from(f64x2::from_array([2.0, 3.0])); |
| 401 | + let b = vector_double::from(f64x2::from_array([1.0, 3.0])); |
| 402 | + |
| 403 | + unsafe { |
| 404 | + let result: vector_bool_long = vec_cmpge(a, b); |
| 405 | + // First element: 2.0 >= 1.0 (true), second: 3.0 >= 3.0 (true) |
| 406 | + let result_i64: i64x2 = transmute(result); |
| 407 | + assert_eq!(result_i64.as_array()[0], -1i64); |
| 408 | + assert_eq!(result_i64.as_array()[1], -1i64); |
| 409 | + } |
| 410 | + } |
258 | 411 | } |
0 commit comments