Skip to content

Commit c14f4d2

Browse files
TSPMPalexcrichton
authored andcommitted
Implement addition aliases (rust-lang#281)
- `_m_paddb` for `_mm_add_pi8` - `_m_paddw` for `_mm_add_pi16` - `_m_paddd` for `_mm_add_pi32` - `_m_paddsb` for `_mm_adds_pi8` - `_m_paddsw` for `_mm_adds_pi16` - `_m_paddusb` for `_mm_adds_pu8` - `_m_paddusw` for `_mm_adds_pu16`
1 parent 9865a27 commit c14f4d2

File tree

1 file changed

+70
-14
lines changed

1 file changed

+70
-14
lines changed

coresimd/src/x86/i686/mmx.rs

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ pub unsafe fn _mm_add_pi8(a: __m64, b: __m64) -> __m64 {
3232
paddb(a, b)
3333
}
3434

35+
/// Add packed 8-bit integers in `a` and `b`.
36+
#[inline(always)]
37+
#[target_feature = "+mmx"]
38+
#[cfg_attr(test, assert_instr(paddb))]
39+
pub unsafe fn _m_paddb(a: __m64, b: __m64) -> __m64 {
40+
_mm_add_pi8(a, b)
41+
}
42+
3543
/// Add packed 16-bit integers in `a` and `b`.
3644
#[inline(always)]
3745
#[target_feature = "+mmx"]
@@ -40,6 +48,14 @@ pub unsafe fn _mm_add_pi16(a: __m64, b: __m64) -> __m64 {
4048
paddw(a, b)
4149
}
4250

51+
/// Add packed 16-bit integers in `a` and `b`.
52+
#[inline(always)]
53+
#[target_feature = "+mmx"]
54+
#[cfg_attr(test, assert_instr(paddw))]
55+
pub unsafe fn _m_paddw(a: __m64, b: __m64) -> __m64 {
56+
_mm_add_pi16(a, b)
57+
}
58+
4359
/// Add packed 32-bit integers in `a` and `b`.
4460
#[inline(always)]
4561
#[target_feature = "+mmx"]
@@ -48,6 +64,14 @@ pub unsafe fn _mm_add_pi32(a: __m64, b: __m64) -> __m64 {
4864
paddd(a, b)
4965
}
5066

67+
/// Add packed 32-bit integers in `a` and `b`.
68+
#[inline(always)]
69+
#[target_feature = "+mmx"]
70+
#[cfg_attr(test, assert_instr(paddd))]
71+
pub unsafe fn _m_paddd(a: __m64, b: __m64) -> __m64 {
72+
_mm_add_pi32(a, b)
73+
}
74+
5175
/// Add packed 8-bit integers in `a` and `b` using saturation.
5276
#[inline(always)]
5377
#[target_feature = "+mmx"]
@@ -56,6 +80,14 @@ pub unsafe fn _mm_adds_pi8(a: __m64, b: __m64) -> __m64 {
5680
paddsb(a, b)
5781
}
5882

83+
/// Add packed 8-bit integers in `a` and `b` using saturation.
84+
#[inline(always)]
85+
#[target_feature = "+mmx"]
86+
#[cfg_attr(test, assert_instr(paddsb))]
87+
pub unsafe fn _m_paddsb(a: __m64, b: __m64) -> __m64 {
88+
_mm_adds_pi8(a, b)
89+
}
90+
5991
/// Add packed 16-bit integers in `a` and `b` using saturation.
6092
#[inline(always)]
6193
#[target_feature = "+mmx"]
@@ -64,6 +96,14 @@ pub unsafe fn _mm_adds_pi16(a: __m64, b: __m64) -> __m64 {
6496
paddsw(a, b)
6597
}
6698

99+
/// Add packed 16-bit integers in `a` and `b` using saturation.
100+
#[inline(always)]
101+
#[target_feature = "+mmx"]
102+
#[cfg_attr(test, assert_instr(paddsw))]
103+
pub unsafe fn _m_paddsw(a: __m64, b: __m64) -> __m64 {
104+
_mm_adds_pi16(a, b)
105+
}
106+
67107
/// Add packed unsigned 8-bit integers in `a` and `b` using saturation.
68108
#[inline(always)]
69109
#[target_feature = "+mmx"]
@@ -72,6 +112,14 @@ pub unsafe fn _mm_adds_pu8(a: __m64, b: __m64) -> __m64 {
72112
paddusb(a, b)
73113
}
74114

115+
/// Add packed unsigned 8-bit integers in `a` and `b` using saturation.
116+
#[inline(always)]
117+
#[target_feature = "+mmx"]
118+
#[cfg_attr(test, assert_instr(paddusb))]
119+
pub unsafe fn _m_paddusb(a: __m64, b: __m64) -> __m64 {
120+
_mm_adds_pu8(a, b)
121+
}
122+
75123
/// Add packed unsigned 16-bit integers in `a` and `b` using saturation.
76124
#[inline(always)]
77125
#[target_feature = "+mmx"]
@@ -80,6 +128,14 @@ pub unsafe fn _mm_adds_pu16(a: __m64, b: __m64) -> __m64 {
80128
paddusw(a, b)
81129
}
82130

131+
/// Add packed unsigned 16-bit integers in `a` and `b` using saturation.
132+
#[inline(always)]
133+
#[target_feature = "+mmx"]
134+
#[cfg_attr(test, assert_instr(paddusw))]
135+
pub unsafe fn _m_paddusw(a: __m64, b: __m64) -> __m64 {
136+
_mm_adds_pu16(a, b)
137+
}
138+
83139
/// Subtract packed 8-bit integers in `b` from packed 8-bit integers in `a`.
84140
#[inline(always)]
85141
#[target_feature = "+mmx"]
@@ -444,9 +500,9 @@ mod tests {
444500
unsafe fn _mm_add_pi8() {
445501
let a = i8x8::new(-1, -1, 1, 1, -1, 0, 1, 0);
446502
let b = i8x8::new(-127, 101, 99, 126, 0, -1, 0, 1);
447-
let r = i8x8::from(mmx::_mm_add_pi8(a.into(), b.into()));
448503
let e = i8x8::new(-128, 100, 100, 127, -1, -1, 1, 1);
449-
assert_eq!(r, e);
504+
assert_eq!(e, i8x8::from(mmx::_mm_add_pi8(a.into(), b.into())));
505+
assert_eq!(e, i8x8::from(mmx::_m_paddb(a.into(), b.into())));
450506
}
451507

452508
#[simd_test = "mmx"]
@@ -458,55 +514,55 @@ mod tests {
458514
-30001,
459515
i16::max_value() - 1,
460516
);
461-
let r = i16x4::from(mmx::_mm_add_pi16(a.into(), b.into()));
462517
let e = i16x4::new(i16::min_value(), 30000, -30000, i16::max_value());
463-
assert_eq!(r, e);
518+
assert_eq!(e, i16x4::from(mmx::_mm_add_pi16(a.into(), b.into())));
519+
assert_eq!(e, i16x4::from(mmx::_m_paddw(a.into(), b.into())));
464520
}
465521

466522
#[simd_test = "mmx"]
467523
unsafe fn _mm_add_pi32() {
468524
let a = i32x2::new(1, -1);
469525
let b = i32x2::new(i32::max_value() - 1, i32::min_value() + 1);
470-
let r = i32x2::from(mmx::_mm_add_pi32(a.into(), b.into()));
471526
let e = i32x2::new(i32::max_value(), i32::min_value());
472-
assert_eq!(r, e);
527+
assert_eq!(e, i32x2::from(mmx::_mm_add_pi32(a.into(), b.into())));
528+
assert_eq!(e, i32x2::from(mmx::_m_paddd(a.into(), b.into())));
473529
}
474530

475531
#[simd_test = "mmx"]
476532
unsafe fn _mm_adds_pi8() {
477533
let a = i8x8::new(-100, -1, 1, 100, -1, 0, 1, 0);
478534
let b = i8x8::new(-100, 1, -1, 100, 0, -1, 0, 1);
479-
let r = i8x8::from(mmx::_mm_adds_pi8(a.into(), b.into()));
480535
let e =
481536
i8x8::new(i8::min_value(), 0, 0, i8::max_value(), -1, -1, 1, 1);
482-
assert_eq!(r, e);
537+
assert_eq!(e, i8x8::from(mmx::_mm_adds_pi8(a.into(), b.into())));
538+
assert_eq!(e, i8x8::from(mmx::_m_paddsb(a.into(), b.into())));
483539
}
484540

485541
#[simd_test = "mmx"]
486542
unsafe fn _mm_adds_pi16() {
487543
let a = i16x4::new(-32000, 32000, 4, 0);
488544
let b = i16x4::new(-32000, 32000, -5, 1);
489-
let r = i16x4::from(mmx::_mm_adds_pi16(a.into(), b.into()));
490545
let e = i16x4::new(i16::min_value(), i16::max_value(), -1, 1);
491-
assert_eq!(r, e);
546+
assert_eq!(e, i16x4::from(mmx::_mm_adds_pi16(a.into(), b.into())));
547+
assert_eq!(e, i16x4::from(mmx::_m_paddsw(a.into(), b.into())));
492548
}
493549

494550
#[simd_test = "mmx"]
495551
unsafe fn _mm_adds_pu8() {
496552
let a = u8x8::new(0, 1, 2, 3, 4, 5, 6, 200);
497553
let b = u8x8::new(0, 10, 20, 30, 40, 50, 60, 200);
498-
let r = u8x8::from(mmx::_mm_adds_pu8(a.into(), b.into()));
499554
let e = u8x8::new(0, 11, 22, 33, 44, 55, 66, u8::max_value());
500-
assert_eq!(r, e);
555+
assert_eq!(e, u8x8::from(mmx::_mm_adds_pu8(a.into(), b.into())));
556+
assert_eq!(e, u8x8::from(mmx::_m_paddusb(a.into(), b.into())));
501557
}
502558

503559
#[simd_test = "mmx"]
504560
unsafe fn _mm_adds_pu16() {
505561
let a = u16x4::new(0, 1, 2, 60000);
506562
let b = u16x4::new(0, 10, 20, 60000);
507-
let r = u16x4::from(mmx::_mm_adds_pu16(a.into(), b.into()));
508563
let e = u16x4::new(0, 11, 22, u16::max_value());
509-
assert_eq!(r, e);
564+
assert_eq!(e, u16x4::from(mmx::_mm_adds_pu16(a.into(), b.into())));
565+
assert_eq!(e, u16x4::from(mmx::_m_paddusw(a.into(), b.into())));
510566
}
511567

512568
#[simd_test = "mmx"]

0 commit comments

Comments
 (0)