1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#![cfg(target_feature = "sse3")]

use super::*;

/// Add the high lane and subtract the low lane.
/// ```
/// # use safe_arch::*;
/// let a = m128d::from_array([10.0, 50.0]);
/// let b = m128d::from_array([100.0, 500.0]);
/// let c = addsub_m128d(a, b).to_array();
/// assert_eq!(c, [-90.0, 550.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn addsub_m128d(a: m128d, b: m128d) -> m128d {
  m128d(unsafe { _mm_addsub_pd(a.0, b.0) })
}

/// Alternately, from the top, add a lane and then subtract a lane.
/// ```
/// # use safe_arch::*;
/// let a = m128::from_array([10.0, 20.0, 30.0, 40.0]);
/// let b = m128::from_array([100.0, 200.0, 300.0, 400.0]);
/// let c = addsub_m128(a, b).to_array();
/// assert_eq!(c, [-90.0, 220.0, -270.0, 440.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn addsub_m128(a: m128, b: m128) -> m128 {
  m128(unsafe { _mm_addsub_ps(a.0, b.0) })
}

/// Add each lane horizontally, pack the outputs as `a` then `b`.
/// ```
/// # use safe_arch::*;
/// let a = m128d::from_array([10.0, 50.0]);
/// let b = m128d::from_array([100.0, 500.0]);
/// let c = add_horizontal_m128d(a, b).to_array();
/// assert_eq!(c, [60.0, 600.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn add_horizontal_m128d(a: m128d, b: m128d) -> m128d {
  m128d(unsafe { _mm_hadd_pd(a.0, b.0) })
}

/// Add each lane horizontally, pack the outputs as `a` then `b`.
/// ```
/// # use safe_arch::*;
/// let a = m128::from_array([10.0, 20.0, 30.0, 40.0]);
/// let b = m128::from_array([100.0, 200.0, 300.0, 400.0]);
/// let c = add_horizontal_m128(a, b).to_array();
/// assert_eq!(c, [30.0, 70.0, 300.0, 700.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn add_horizontal_m128(a: m128, b: m128) -> m128 {
  m128(unsafe { _mm_hadd_ps(a.0, b.0) })
}

/// Subtract each lane horizontally, pack the outputs as `a` then `b`.
/// ```
/// # use safe_arch::*;
/// let a = m128d::from_array([10.0, 50.0]);
/// let b = m128d::from_array([100.0, 500.0]);
/// let c = sub_horizontal_m128d(a, b).to_array();
/// assert_eq!(c, [-40.0, -400.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn sub_horizontal_m128d(a: m128d, b: m128d) -> m128d {
  m128d(unsafe { _mm_hsub_pd(a.0, b.0) })
}

/// Subtract each lane horizontally, pack the outputs as `a` then `b`.
/// ```
/// # use safe_arch::*;
/// let a = m128::from_array([10.0, 20.0, 30.0, 45.0]);
/// let b = m128::from_array([100.0, 200.0, 300.0, 450.0]);
/// let c = sub_horizontal_m128(a, b).to_array();
/// assert_eq!(c, [-10.0, -15.0, -100.0, -150.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn sub_horizontal_m128(a: m128, b: m128) -> m128 {
  m128(unsafe { _mm_hsub_ps(a.0, b.0) })
}

/// Copy the low lane of the input to both lanes of the output.
/// ```
/// # use safe_arch::*;
/// let a = m128d::from_array([1.0, 2.0]);
/// let b = duplicate_low_lane_m128d_s(a);
/// assert_eq!(b.to_array(), [1.0, 1.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn duplicate_low_lane_m128d_s(a: m128d) -> m128d {
  m128d(unsafe { _mm_movedup_pd(a.0) })
}

/// Duplicate the odd lanes to the even lanes.
/// ```
/// # use safe_arch::*;
/// let a = m128::from_array([0.0, 1.0, 2.0, 3.0]);
/// let b = duplicate_odd_lanes_m128(a);
/// assert_eq!(b.to_array(), [1.0, 1.0, 3.0, 3.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn duplicate_odd_lanes_m128(a: m128) -> m128 {
  m128(unsafe { _mm_movehdup_ps(a.0) })
}

/// Duplicate the odd lanes to the even lanes.
/// ```
/// # use safe_arch::*;
/// let a = m128::from_array([0.0, 1.0, 2.0, 3.0]);
/// let b = duplicate_even_lanes_m128(a);
/// assert_eq!(b.to_array(), [0.0, 0.0, 2.0, 2.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse3")))]
pub fn duplicate_even_lanes_m128(a: m128) -> m128 {
  m128(unsafe { _mm_moveldup_ps(a.0) })
}