@@ -178,6 +178,20 @@ extern "C" {
178
178
179
179
#[ link_name = "llvm.ppc.altivec.vaddcuw" ]
180
180
fn vaddcuw ( a : vector_unsigned_int , b : vector_unsigned_int ) -> vector_unsigned_int ;
181
+
182
+ #[ link_name = "llvm.ppc.altivec.vaddsbs" ]
183
+ fn vaddsbs ( a : vector_signed_char , b : vector_signed_char ) -> vector_signed_char ;
184
+ #[ link_name = "llvm.ppc.altivec.vaddshs" ]
185
+ fn vaddshs ( a : vector_signed_short , b : vector_signed_short ) -> vector_signed_short ;
186
+ #[ link_name = "llvm.ppc.altivec.vaddsws" ]
187
+ fn vaddsws ( a : vector_signed_int , b : vector_signed_int ) -> vector_signed_int ;
188
+
189
+ #[ link_name = "llvm.ppc.altivec.vaddubs" ]
190
+ fn vaddubs ( a : vector_unsigned_char , b : vector_unsigned_char ) -> vector_unsigned_char ;
191
+ #[ link_name = "llvm.ppc.altivec.vadduhs" ]
192
+ fn vadduhs ( a : vector_unsigned_short , b : vector_unsigned_short ) -> vector_unsigned_short ;
193
+ #[ link_name = "llvm.ppc.altivec.vadduws" ]
194
+ fn vadduws ( a : vector_unsigned_int , b : vector_unsigned_int ) -> vector_unsigned_int ;
181
195
}
182
196
183
197
macro_rules! s_t_l {
@@ -320,6 +334,20 @@ mod sealed {
320
334
}
321
335
}
322
336
337
+ test_impl ! { vec_vaddsbs( a: vector_signed_char, b: vector_signed_char) -> vector_signed_char [ vaddsbs, vaddsbs ] }
338
+ test_impl ! { vec_vaddshs( a: vector_signed_short, b: vector_signed_short) -> vector_signed_short [ vaddshs, vaddshs ] }
339
+ test_impl ! { vec_vaddsws( a: vector_signed_int, b: vector_signed_int) -> vector_signed_int [ vaddsws, vaddsws ] }
340
+ test_impl ! { vec_vaddubs( a: vector_unsigned_char, b: vector_unsigned_char) -> vector_unsigned_char [ vaddubs, vaddubs ] }
341
+ test_impl ! { vec_vadduhs( a: vector_unsigned_short, b: vector_unsigned_short) -> vector_unsigned_short [ vadduhs, vadduhs ] }
342
+ test_impl ! { vec_vadduws( a: vector_unsigned_int, b: vector_unsigned_int) -> vector_unsigned_int [ vadduws, vadduws ] }
343
+
344
+ pub trait VectorAdds < Other > {
345
+ type Result ;
346
+ unsafe fn vec_adds ( self , b : Other ) -> Self :: Result ;
347
+ }
348
+
349
+ impl_vec_trait ! { [ VectorAdds vec_adds] ~( vaddubs, vaddsbs, vadduhs, vaddshs, vadduws, vaddsws) }
350
+
323
351
test_impl ! { vec_vaddcuw( a: vector_unsigned_int, b: vector_unsigned_int) -> vector_unsigned_int [ vaddcuw, vaddcuw] }
324
352
325
353
test_impl ! { vec_vsubsbs( a: vector_signed_char, b: vector_signed_char) -> vector_signed_char [ vsubsbs, vsubsbs ] }
@@ -1162,6 +1190,16 @@ mod sealed {
1162
1190
vector_mladd ! { vector_signed_short, vector_signed_short, vector_signed_short }
1163
1191
}
1164
1192
1193
+ /// Vector adds.
1194
+ #[ inline]
1195
+ #[ target_feature( enable = "altivec" ) ]
1196
+ pub unsafe fn vec_adds < T , U > ( a : T , b : U ) -> <T as sealed:: VectorAdds < U > >:: Result
1197
+ where
1198
+ T : sealed:: VectorAdds < U > ,
1199
+ {
1200
+ a. vec_adds ( b)
1201
+ }
1202
+
1165
1203
/// Vector addc.
1166
1204
#[ inline]
1167
1205
#[ target_feature( enable = "altivec" ) ]
@@ -1456,6 +1494,42 @@ mod tests {
1456
1494
}
1457
1495
}
1458
1496
1497
+ macro_rules! test_vec_adds {
1498
+ { $name: ident, $ty: ident, [ $( $a: expr) ,+] , [ $( $b: expr) ,+] , [ $( $d: expr) ,+] } => {
1499
+ test_vec_2! { $name, vec_adds, $ty, [ $( $a) ,+] , [ $( $b) ,+] , [ $( $d) ,+] }
1500
+ }
1501
+ }
1502
+
1503
+ test_vec_adds ! { test_vec_adds_i32x4, i32x4,
1504
+ [ i32 :: min_value( ) , i32 :: max_value( ) , 1 , -1 ] ,
1505
+ [ -1 , 1 , 1 , -1 ] ,
1506
+ [ i32 :: min_value( ) , i32 :: max_value( ) , 2 , -2 ] }
1507
+
1508
+ test_vec_adds ! { test_vec_adds_u32x4, u32x4,
1509
+ [ u32 :: max_value( ) , 0 , 1 , 2 ] ,
1510
+ [ 2 , 1 , 0 , 0 ] ,
1511
+ [ u32 :: max_value( ) , 1 , 1 , 2 ] }
1512
+
1513
+ test_vec_adds ! { test_vec_adds_i16x8, i16x8,
1514
+ [ i16 :: min_value( ) , i16 :: max_value( ) , 1 , -1 , 0 , 0 , 0 , 0 ] ,
1515
+ [ -1 , 1 , 1 , -1 , 0 , 0 , 0 , 0 ] ,
1516
+ [ i16 :: min_value( ) , i16 :: max_value( ) , 2 , -2 , 0 , 0 , 0 , 0 ] }
1517
+
1518
+ test_vec_adds ! { test_vec_adds_u16x8, u16x8,
1519
+ [ u16 :: max_value( ) , 0 , 1 , 2 , 0 , 0 , 0 , 0 ] ,
1520
+ [ 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1521
+ [ u16 :: max_value( ) , 1 , 1 , 2 , 0 , 0 , 0 , 0 ] }
1522
+
1523
+ test_vec_adds ! { test_vec_adds_i8x16, i8x16,
1524
+ [ i8 :: min_value( ) , i8 :: max_value( ) , 1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1525
+ [ -1 , 1 , 1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1526
+ [ i8 :: min_value( ) , i8 :: max_value( ) , 2 , -2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] }
1527
+
1528
+ test_vec_adds ! { test_vec_adds_u8x16, u8x16,
1529
+ [ u8 :: max_value( ) , 0 , 1 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1530
+ [ 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1531
+ [ u8 :: max_value( ) , 1 , 1 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] }
1532
+
1459
1533
test_vec_2 ! { test_vec_addc, vec_addc, u32x4, [ u32 :: max_value( ) , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 1 ] , [ 1 , 0 , 0 , 0 ] }
1460
1534
1461
1535
macro_rules! test_vec_abs {
0 commit comments