@@ -212,6 +212,13 @@ extern "C" {
212
212
213
213
#[ link_name = "llvm.ppc.altivec.vcmpbfp" ]
214
214
fn vcmpbfp ( a : vector_float , b : vector_float ) -> vector_signed_int ;
215
+
216
+ #[ link_name = "llvm.ppc.altivec.vcmpequb" ]
217
+ fn vcmpequb ( a : vector_unsigned_char , b : vector_unsigned_char ) -> vector_bool_char ;
218
+ #[ link_name = "llvm.ppc.altivec.vcmpequh" ]
219
+ fn vcmpequh ( a : vector_unsigned_short , b : vector_unsigned_short ) -> vector_bool_short ;
220
+ #[ link_name = "llvm.ppc.altivec.vcmpequw" ]
221
+ fn vcmpequw ( a : vector_unsigned_int , b : vector_unsigned_int ) -> vector_bool_int ;
215
222
}
216
223
217
224
macro_rules! s_t_l {
@@ -368,6 +375,28 @@ mod sealed {
368
375
}
369
376
}
370
377
378
+ test_impl ! { vec_vcmpequb( a: vector_unsigned_char, b: vector_unsigned_char) -> vector_bool_char [ vcmpequb, vcmpequb ] }
379
+ test_impl ! { vec_vcmpequh( a: vector_unsigned_short, b: vector_unsigned_short) -> vector_bool_short [ vcmpequh, vcmpequh ] }
380
+ test_impl ! { vec_vcmpequw( a: vector_unsigned_int, b: vector_unsigned_int) -> vector_bool_int [ vcmpequw, vcmpequw ] }
381
+
382
+ pub trait VectorCmpEq < Other > {
383
+ type Result ;
384
+ unsafe fn vec_cmpeq ( self , b : Other ) -> Self :: Result ;
385
+ }
386
+
387
+ macro_rules! impl_vec_cmp {
388
+ ( [ $Trait: ident $m: ident] ( $b: ident, $h: ident, $w: ident) ) => {
389
+ impl_vec_trait!{ [ $Trait $m] $b ( vector_unsigned_char, vector_unsigned_char) -> vector_bool_char }
390
+ impl_vec_trait!{ [ $Trait $m] $b ( vector_signed_char, vector_signed_char) -> vector_bool_char }
391
+ impl_vec_trait!{ [ $Trait $m] $h ( vector_unsigned_short, vector_unsigned_short) -> vector_bool_short }
392
+ impl_vec_trait!{ [ $Trait $m] $h ( vector_signed_short, vector_signed_short) -> vector_bool_short }
393
+ impl_vec_trait!{ [ $Trait $m] $w ( vector_unsigned_int, vector_unsigned_int) -> vector_bool_int }
394
+ impl_vec_trait!{ [ $Trait $m] $w ( vector_signed_int, vector_signed_int) -> vector_bool_int }
395
+ }
396
+ }
397
+
398
+ impl_vec_cmp ! { [ VectorCmpEq vec_cmpeq] ( vec_vcmpequb, vec_vcmpequh, vec_vcmpequw) }
399
+
371
400
test_impl ! { vec_vcmpbfp( a: vector_float, b: vector_float) -> vector_signed_int [ vcmpbfp, vcmpbfp] }
372
401
373
402
test_impl ! { vec_vceil( a: vector_float) -> vector_float [ vceil, vrfip / xvrspip ] }
@@ -1289,6 +1318,16 @@ mod sealed {
1289
1318
vector_mladd ! { vector_signed_short, vector_signed_short, vector_signed_short }
1290
1319
}
1291
1320
1321
+ /// Vector cmpeq.
1322
+ #[ inline]
1323
+ #[ target_feature( enable = "altivec" ) ]
1324
+ pub unsafe fn vec_cmpeq < T , U > ( a : T , b : U ) -> <T as sealed:: VectorCmpEq < U > >:: Result
1325
+ where
1326
+ T : sealed:: VectorCmpEq < U > ,
1327
+ {
1328
+ a. vec_cmpeq ( b)
1329
+ }
1330
+
1292
1331
/// Vector cmpb.
1293
1332
#[ inline]
1294
1333
#[ target_feature( enable = "altivec" ) ]
@@ -1625,18 +1664,57 @@ mod tests {
1625
1664
1626
1665
macro_rules! test_vec_2 {
1627
1666
{ $name: ident, $fn: ident, $ty: ident, [ $( $a: expr) ,+] , [ $( $b: expr) ,+] , [ $( $d: expr) ,+] } => {
1667
+ test_vec_2! { $name, $fn, $ty -> $ty, [ $( $a) ,+] , [ $( $b) ,+] , [ $( $d) ,+] }
1668
+ } ;
1669
+ { $name: ident, $fn: ident, $ty: ident -> $ty_out: ident, [ $( $a: expr) ,+] , [ $( $b: expr) ,+] , [ $( $d: expr) ,+] } => {
1628
1670
#[ simd_test( enable = "altivec" ) ]
1629
1671
unsafe fn $name( ) {
1630
1672
let a: s_t_l!( $ty) = transmute( $ty:: new( $( $a) ,+) ) ;
1631
1673
let b: s_t_l!( $ty) = transmute( $ty:: new( $( $b) ,+) ) ;
1632
1674
1633
- let d = $ty :: new( $( $d) ,+) ;
1634
- let r : $ty = transmute( $fn( a, b) ) ;
1675
+ let d = $ty_out :: new( $( $d) ,+) ;
1676
+ let r : $ty_out = transmute( $fn( a, b) ) ;
1635
1677
assert_eq!( d, r) ;
1636
1678
}
1637
1679
}
1638
1680
}
1639
1681
1682
+ test_vec_2 ! { test_vec_cmpeq_i8, vec_cmpeq, i8x16 -> m8x16,
1683
+ [ 1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1684
+ [ 0 , 0 , -1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1685
+ [ false , false , false , false , true , true , true , true , true , true , true , true , true , true , true , true ]
1686
+ }
1687
+
1688
+ test_vec_2 ! { test_vec_cmpeq_u8, vec_cmpeq, u8x16 -> m8x16,
1689
+ [ 1 , 255 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1690
+ [ 0 , 0 , 255 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1691
+ [ false , false , false , false , true , true , true , true , true , true , true , true , true , true , true , true ]
1692
+ }
1693
+
1694
+ test_vec_2 ! { test_vec_cmpeq_i16, vec_cmpeq, i16x8 -> m16x8,
1695
+ [ 1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1696
+ [ 0 , 0 , -1 , 1 , 0 , 0 , 0 , 0 ] ,
1697
+ [ false , false , false , false , true , true , true , true ]
1698
+ }
1699
+
1700
+ test_vec_2 ! { test_vec_cmpeq_u16, vec_cmpeq, u16x8 -> m16x8,
1701
+ [ 1 , 255 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1702
+ [ 0 , 0 , 255 , 1 , 0 , 0 , 0 , 0 ] ,
1703
+ [ false , false , false , false , true , true , true , true ]
1704
+ }
1705
+
1706
+ test_vec_2 ! { test_vec_cmpeq_i32, vec_cmpeq, i32x4 -> m32x4,
1707
+ [ 1 , -1 , 0 , 0 ] ,
1708
+ [ 0 , -1 , 0 , 1 ] ,
1709
+ [ false , true , true , false ]
1710
+ }
1711
+
1712
+ test_vec_2 ! { test_vec_cmpeq_u32, vec_cmpeq, u32x4 -> m32x4,
1713
+ [ 1 , 255 , 0 , 0 ] ,
1714
+ [ 0 , 255 , 0 , 1 ] ,
1715
+ [ false , true , true , false ]
1716
+ }
1717
+
1640
1718
#[ simd_test( enable = "altivec" ) ]
1641
1719
unsafe fn test_vec_cmpb ( ) {
1642
1720
let a: vector_float = transmute ( f32x4:: new ( 0.1 , 0.5 , 0.6 , 0.9 ) ) ;
0 commit comments