|
4 | 4 | //!
|
5 | 5 | //! Intrinsics that could live here
|
6 | 6 | //!
|
7 |
| -//! - __ssat16 |
8 |
| -//! - __usat16 |
9 |
| -//! - __sxtab16 |
10 |
| -//! - __sxtb16 |
11 |
| -//! - __uxtab16 |
12 |
| -//! - __uxtb16 |
13 |
| -//! - __qsub8 |
14 |
| -//! - __sadd8 |
15 |
| -//! - __shadd8 |
16 |
| -//! - __shsub8 |
17 |
| -//! - __ssub8 |
18 |
| -//! - __uadd8 |
19 |
| -//! - __uhadd8 |
20 |
| -//! - __uhsub8 |
21 |
| -//! - __uqadd8 |
22 |
| -//! - __uqsub8 |
23 |
| -//! - __usub8 |
24 |
| -//! - __usad8 |
25 |
| -//! - __usada8 |
26 |
| -//! - __qadd16 |
27 |
| -//! - __qasx |
28 |
| -//! - __qsub16 |
29 |
| -//! - __sadd16 |
30 |
| -//! - __sasx |
31 |
| -//! - __shadd16 |
32 |
| -//! - __shasx |
33 |
| -//! - __shsax |
34 |
| -//! - __shsub16 |
35 |
| -//! - __ssax |
36 |
| -//! - __ssub16 |
37 |
| -//! - __uadd16 |
38 |
| -//! - __uasx |
39 |
| -//! - __uhadd16 |
40 |
| -//! - __uhasx |
41 |
| -//! - __uhsax |
42 |
| -//! - __uhsub16 |
43 |
| -//! - __uqadd16 |
44 |
| -//! - __uqasx |
45 |
| -//! - __uqsax |
46 |
| -//! - __uqsub16 |
47 |
| -//! - __usax |
48 |
| -//! - __usub16 |
49 |
| -//! - __smlad |
50 |
| -//! - __smladx |
51 |
| -//! - __smlald |
52 |
| -//! - __smlaldx |
53 |
| -//! - __smlsd |
54 |
| -//! - __smlsdx |
55 |
| -//! - __smlsld |
56 |
| -//! - __smlsldx |
57 |
| -//! - __smuad |
58 |
| -//! - __smuadx |
59 |
| -//! - __smusd |
60 |
| -//! - __smusdx |
| 7 | +//! - [x] __sel |
| 8 | +//! - [ ] __ssat16 |
| 9 | +//! - [ ] __usat16 |
| 10 | +//! - [ ] __sxtab16 |
| 11 | +//! - [ ] __sxtb16 |
| 12 | +//! - [ ] __uxtab16 |
| 13 | +//! - [ ] __uxtb16 |
| 14 | +//! - [x] __qadd8 |
| 15 | +//! - [x] __qsub8 |
| 16 | +//! - [x] __sadd8 |
| 17 | +//! - [x] __shadd8 |
| 18 | +//! - [x] __shsub8 |
| 19 | +//! - [ ] __ssub8 |
| 20 | +//! - [ ] __uadd8 |
| 21 | +//! - [ ] __uhadd8 |
| 22 | +//! - [ ] __uhsub8 |
| 23 | +//! - [ ] __uqadd8 |
| 24 | +//! - [ ] __uqsub8 |
| 25 | +//! - [ ] __usub8 |
| 26 | +//! - [x] __usad8 |
| 27 | +//! - [x] __usada8 |
| 28 | +//! - [x] __qadd16 |
| 29 | +//! - [x] __qasx |
| 30 | +//! - [x] __qsax |
| 31 | +//! - [x] __qsub16 |
| 32 | +//! - [x] __sadd16 |
| 33 | +//! - [x] __sasx |
| 34 | +//! - [x] __shadd16 |
| 35 | +//! - [ ] __shasx |
| 36 | +//! - [ ] __shsax |
| 37 | +//! - [x] __shsub16 |
| 38 | +//! - [ ] __ssax |
| 39 | +//! - [ ] __ssub16 |
| 40 | +//! - [ ] __uadd16 |
| 41 | +//! - [ ] __uasx |
| 42 | +//! - [ ] __uhadd16 |
| 43 | +//! - [ ] __uhasx |
| 44 | +//! - [ ] __uhsax |
| 45 | +//! - [ ] __uhsub16 |
| 46 | +//! - [ ] __uqadd16 |
| 47 | +//! - [ ] __uqasx |
| 48 | +//! - [x] __uqsax |
| 49 | +//! - [ ] __uqsub16 |
| 50 | +//! - [ ] __usax |
| 51 | +//! - [ ] __usub16 |
| 52 | +//! - [x] __smlad |
| 53 | +//! - [ ] __smladx |
| 54 | +//! - [ ] __smlald |
| 55 | +//! - [ ] __smlaldx |
| 56 | +//! - [x] __smlsd |
| 57 | +//! - [ ] __smlsdx |
| 58 | +//! - [ ] __smlsld |
| 59 | +//! - [ ] __smlsldx |
| 60 | +//! - [x] __smuad |
| 61 | +//! - [x] __smuadx |
| 62 | +//! - [x] __smusd |
| 63 | +//! - [x] __smusdx |
| 64 | +
|
| 65 | +types! { |
| 66 | + /// ARM-specific 32-bit wide vector of four packed `i8`. |
| 67 | + pub struct int8x4_t(i8, i8, i8, i8); |
| 68 | + /// ARM-specific 32-bit wide vector of four packed `u8`. |
| 69 | + pub struct uint8x4_t(u8, u8, u8, u8); |
| 70 | + /// ARM-specific 32-bit wide vector of two packed `i16`. |
| 71 | + pub struct int16x2_t(i16, i16); |
| 72 | + /// ARM-specific 32-bit wide vector of two packed `u16`. |
| 73 | + pub struct uint16x2_t(u16, u16); |
| 74 | +} |
| 75 | + |
| 76 | +macro_rules! dsp_call { |
| 77 | + ($name:expr, $a:expr, $b:expr) => { |
| 78 | + ::mem::transmute($name(::mem::transmute($a), ::mem::transmute($b))) |
| 79 | + }; |
| 80 | +} |
| 81 | + |
| 82 | +extern "C" { |
| 83 | + #[link_name = "llvm.arm.qadd8"] |
| 84 | + fn arm_qadd8(a: i32, b: i32) -> i32; |
| 85 | + |
| 86 | + #[link_name = "llvm.arm.qsub8"] |
| 87 | + fn arm_qsub8(a: i32, b: i32) -> i32; |
| 88 | + |
| 89 | + #[link_name = "llvm.arm.qsub16"] |
| 90 | + fn arm_qsub16(a: i32, b: i32) -> i32; |
| 91 | + |
| 92 | + #[link_name = "llvm.arm.qadd16"] |
| 93 | + fn arm_qadd16(a: i32, b: i32) -> i32; |
| 94 | + |
| 95 | + #[link_name = "llvm.arm.qasx"] |
| 96 | + fn arm_qasx(a: i32, b: i32) -> i32; |
| 97 | + |
| 98 | + #[link_name = "llvm.arm.qsax"] |
| 99 | + fn arm_qsax(a: i32, b: i32) -> i32; |
| 100 | + |
| 101 | + #[link_name = "llvm.arm.sadd16"] |
| 102 | + fn arm_sadd16(a: i32, b: i32) -> i32; |
| 103 | + |
| 104 | + #[link_name = "llvm.arm.sadd8"] |
| 105 | + fn arm_sadd8(a: i32, b: i32) -> i32; |
| 106 | + |
| 107 | + #[link_name = "llvm.arm.smlad"] |
| 108 | + fn arm_smlad(a: i32, b: i32, c: i32) -> i32; |
| 109 | + |
| 110 | + #[link_name = "llvm.arm.smlsd"] |
| 111 | + fn arm_smlsd(a: i32, b: i32, c: i32) -> i32; |
| 112 | + |
| 113 | + #[link_name = "llvm.arm.sasx"] |
| 114 | + fn arm_sasx(a: i32, b: i32) -> i32; |
| 115 | + |
| 116 | + #[link_name = "llvm.arm.sel"] |
| 117 | + fn arm_sel(a: i32, b: i32) -> i32; |
| 118 | + |
| 119 | + #[link_name = "llvm.arm.shadd8"] |
| 120 | + fn arm_shadd8(a: i32, b: i32) -> i32; |
| 121 | + |
| 122 | + #[link_name = "llvm.arm.shadd16"] |
| 123 | + fn arm_shadd16(a: i32, b: i32) -> i32; |
| 124 | + |
| 125 | + #[link_name = "llvm.arm.shsub8"] |
| 126 | + fn arm_shsub8(a: i32, b: i32) -> i32; |
| 127 | + |
| 128 | + #[link_name = "llvm.arm.shsub16"] |
| 129 | + fn arm_shsub16(a: i32, b: i32) -> i32; |
| 130 | + |
| 131 | + #[link_name = "llvm.arm.smuad"] |
| 132 | + fn arm_smuad(a: i32, b: i32) -> i32; |
| 133 | + |
| 134 | + #[link_name = "llvm.arm.smuadx"] |
| 135 | + fn arm_smuadx(a: i32, b: i32) -> i32; |
| 136 | + |
| 137 | + #[link_name = "llvm.arm.smusd"] |
| 138 | + fn arm_smusd(a: i32, b: i32) -> i32; |
| 139 | + |
| 140 | + #[link_name = "llvm.arm.smusdx"] |
| 141 | + fn arm_smusdx(a: i32, b: i32) -> i32; |
| 142 | + |
| 143 | + #[link_name = "llvm.arm.usad8"] |
| 144 | + fn arm_usad8(a: i32, b: i32) -> u32; |
| 145 | +} |
| 146 | + |
| 147 | +/// Saturating four 8-bit integer additions |
| 148 | +/// |
| 149 | +/// Returns the 8-bit signed equivalent of |
| 150 | +/// |
| 151 | +/// res\[0\] = a\[0\] + b\[0\] |
| 152 | +/// res\[1\] = a\[1\] + b\[1\] |
| 153 | +/// res\[2\] = a\[2\] + b\[2\] |
| 154 | +/// res\[3\] = a\[3\] + b\[3\] |
| 155 | +#[inline] |
| 156 | +#[cfg_attr(test, assert_instr(qadd8))] |
| 157 | +pub unsafe fn qadd8(a: int8x4_t, b: int8x4_t) -> int8x4_t { |
| 158 | + dsp_call!(arm_qadd8, a, b) |
| 159 | +} |
| 160 | + |
| 161 | +/// Saturating two 8-bit integer subtraction |
| 162 | +/// |
| 163 | +/// Returns the 8-bit signed equivalent of |
| 164 | +/// |
| 165 | +/// res\[0\] = a\[0\] - b\[0\] |
| 166 | +/// res\[1\] = a\[1\] - b\[1\] |
| 167 | +/// res\[2\] = a\[2\] - b\[2\] |
| 168 | +/// res\[3\] = a\[3\] - b\[3\] |
| 169 | +#[inline] |
| 170 | +#[cfg_attr(test, assert_instr(qsub8))] |
| 171 | +pub unsafe fn qsub8(a: int8x4_t, b: int8x4_t) -> int8x4_t { |
| 172 | + dsp_call!(arm_qsub8, a, b) |
| 173 | +} |
| 174 | + |
| 175 | +/// Saturating two 16-bit integer subtraction |
| 176 | +/// |
| 177 | +/// Returns the 16-bit signed equivalent of |
| 178 | +/// |
| 179 | +/// res\[0\] = a\[0\] - b\[0\] |
| 180 | +/// res\[1\] = a\[1\] - b\[1\] |
| 181 | +#[inline] |
| 182 | +#[cfg_attr(test, assert_instr(qsub16))] |
| 183 | +pub unsafe fn qsub16(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 184 | + dsp_call!(arm_qsub16, a, b) |
| 185 | +} |
| 186 | + |
| 187 | +/// Saturating two 16-bit integer additions |
| 188 | +/// |
| 189 | +/// Returns the 16-bit signed equivalent of |
| 190 | +/// |
| 191 | +/// res\[0\] = a\[0\] + b\[0\] |
| 192 | +/// res\[1\] = a\[1\] + b\[1\] |
| 193 | +#[inline] |
| 194 | +#[cfg_attr(test, assert_instr(qadd16))] |
| 195 | +pub unsafe fn qadd16(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 196 | + dsp_call!(arm_qadd16, a, b) |
| 197 | +} |
| 198 | + |
| 199 | +/// Returns the 16-bit signed saturated equivalent of |
| 200 | +/// |
| 201 | +/// res\[0\] = a\[0\] - b\[1\] |
| 202 | +/// res\[1\] = a\[1\] + b\[0\] |
| 203 | +#[inline] |
| 204 | +#[cfg_attr(test, assert_instr(qasx))] |
| 205 | +pub unsafe fn qasx(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 206 | + dsp_call!(arm_qasx, a, b) |
| 207 | +} |
| 208 | + |
| 209 | +/// Returns the 16-bit signed saturated equivalent of |
| 210 | +/// |
| 211 | +/// res\[0\] = a\[0\] + b\[1\] |
| 212 | +/// res\[1\] = a\[1\] - b\[0\] |
| 213 | +#[inline] |
| 214 | +#[cfg_attr(test, assert_instr(qsax))] |
| 215 | +pub unsafe fn qsax(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 216 | + dsp_call!(arm_qsax, a, b) |
| 217 | +} |
| 218 | + |
| 219 | +/// Returns the 16-bit signed saturated equivalent of |
| 220 | +/// |
| 221 | +/// res\[0\] = a\[0\] + b\[1\] |
| 222 | +/// res\[1\] = a\[1\] + b\[0\] |
| 223 | +/// |
| 224 | +/// and the GE bits of the APSR are set. |
| 225 | +#[inline] |
| 226 | +#[cfg_attr(test, assert_instr(sadd16))] |
| 227 | +pub unsafe fn sadd16(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 228 | + dsp_call!(arm_sadd16, a, b) |
| 229 | +} |
| 230 | + |
| 231 | +/// Returns the 8-bit signed saturated equivalent of |
| 232 | +/// |
| 233 | +/// res\[0\] = a\[0\] + b\[1\] |
| 234 | +/// res\[1\] = a\[1\] + b\[0\] |
| 235 | +/// res\[2\] = a\[2\] + b\[2\] |
| 236 | +/// res\[3\] = a\[3\] + b\[3\] |
| 237 | +/// |
| 238 | +/// and the GE bits of the APSR are set. |
| 239 | +#[inline] |
| 240 | +#[cfg_attr(test, assert_instr(sadd8))] |
| 241 | +pub unsafe fn sadd8(a: int8x4_t, b: int8x4_t) -> int8x4_t { |
| 242 | + dsp_call!(arm_sadd8, a, b) |
| 243 | +} |
| 244 | + |
| 245 | +/// Dual 16-bit Signed Multiply with Addition of products |
| 246 | +/// and 32-bit accumulation. |
| 247 | +/// |
| 248 | +/// Returns the 16-bit signed equivalent of |
| 249 | +/// res = a\[0\] * b\[0\] + a\[1\] * b\[1\] + c |
| 250 | +#[inline] |
| 251 | +#[cfg_attr(test, assert_instr(smlad))] |
| 252 | +pub unsafe fn smlad(a: int16x2_t, b: int16x2_t, c: i32) -> i32 { |
| 253 | + arm_smlad(::mem::transmute(a), ::mem::transmute(b), c) |
| 254 | +} |
| 255 | + |
| 256 | +/// Dual 16-bit Signed Multiply with Subtraction of products |
| 257 | +/// and 32-bit accumulation and overflow detection. |
| 258 | +/// |
| 259 | +/// Returns the 16-bit signed equivalent of |
| 260 | +/// res = a\[0\] * b\[0\] - a\[1\] * b\[1\] + c |
| 261 | +#[inline] |
| 262 | +#[cfg_attr(test, assert_instr(smlsd))] |
| 263 | +pub unsafe fn smlsd(a: int16x2_t, b: int16x2_t, c: i32) -> i32 { |
| 264 | + arm_smlsd(::mem::transmute(a), ::mem::transmute(b), c) |
| 265 | +} |
| 266 | + |
| 267 | +/// Returns the 16-bit signed equivalent of |
| 268 | +/// |
| 269 | +/// res\[0\] = a\[0\] - b\[1\] |
| 270 | +/// res\[1\] = a\[1\] + b\[0\] |
| 271 | +/// |
| 272 | +/// and the GE bits of the APSR are set. |
| 273 | +#[inline] |
| 274 | +#[cfg_attr(test, assert_instr(sasx))] |
| 275 | +pub unsafe fn sasx(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 276 | + dsp_call!(arm_sasx, a, b) |
| 277 | +} |
| 278 | + |
| 279 | +/// Select bytes from each operand according to APSR GE flags |
| 280 | +/// |
| 281 | +/// Returns the equivalent of |
| 282 | +/// |
| 283 | +/// res\[0\] = GE\[0\] ? a\[0\] : b\[0\] |
| 284 | +/// res\[1\] = GE\[1\] ? a\[1\] : b\[1\] |
| 285 | +/// res\[2\] = GE\[2\] ? a\[2\] : b\[2\] |
| 286 | +/// res\[3\] = GE\[3\] ? a\[3\] : b\[3\] |
| 287 | +/// |
| 288 | +/// where GE are bits of APSR |
| 289 | +#[inline] |
| 290 | +#[cfg_attr(test, assert_instr(sel))] |
| 291 | +pub unsafe fn sel(a: int8x4_t, b: int8x4_t) -> int8x4_t { |
| 292 | + dsp_call!(arm_sel, a, b) |
| 293 | +} |
| 294 | + |
| 295 | +/// Signed halving parallel byte-wise addition. |
| 296 | +/// |
| 297 | +/// Returns the 8-bit signed equivalent of |
| 298 | +/// |
| 299 | +/// res\[0\] = (a\[0\] + b\[0\]) / 2 |
| 300 | +/// res\[1\] = (a\[1\] + b\[1\]) / 2 |
| 301 | +/// res\[2\] = (a\[2\] + b\[2\]) / 2 |
| 302 | +/// res\[3\] = (a\[3\] + b\[3\]) / 2 |
| 303 | +#[inline] |
| 304 | +#[cfg_attr(test, assert_instr(shadd8))] |
| 305 | +pub unsafe fn shadd8(a: int8x4_t, b: int8x4_t) -> int8x4_t { |
| 306 | + dsp_call!(arm_shadd8, a, b) |
| 307 | +} |
| 308 | + |
| 309 | +/// Signed halving parallel halfword-wise addition. |
| 310 | +/// |
| 311 | +/// Returns the 16-bit signed equivalent of |
| 312 | +/// |
| 313 | +/// res\[0\] = (a\[0\] + b\[0\]) / 2 |
| 314 | +/// res\[1\] = (a\[1\] + b\[1\]) / 2 |
| 315 | +#[inline] |
| 316 | +#[cfg_attr(test, assert_instr(shadd16))] |
| 317 | +pub unsafe fn shadd16(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 318 | + dsp_call!(arm_shadd16, a, b) |
| 319 | +} |
| 320 | + |
| 321 | +/// Signed halving parallel byte-wise subtraction. |
| 322 | +/// |
| 323 | +/// Returns the 8-bit signed equivalent of |
| 324 | +/// |
| 325 | +/// res\[0\] = (a\[0\] - b\[0\]) / 2 |
| 326 | +/// res\[1\] = (a\[1\] - b\[1\]) / 2 |
| 327 | +/// res\[2\] = (a\[2\] - b\[2\]) / 2 |
| 328 | +/// res\[3\] = (a\[3\] - b\[3\]) / 2 |
| 329 | +#[inline] |
| 330 | +#[cfg_attr(test, assert_instr(shsub8))] |
| 331 | +pub unsafe fn shsub8(a: int8x4_t, b: int8x4_t) -> int8x4_t { |
| 332 | + dsp_call!(arm_shsub8, a, b) |
| 333 | +} |
| 334 | + |
| 335 | +/// Signed halving parallel halfword-wise subtraction. |
| 336 | +/// |
| 337 | +/// Returns the 16-bit signed equivalent of |
| 338 | +/// |
| 339 | +/// res\[0\] = (a\[0\] - b\[0\]) / 2 |
| 340 | +/// res\[1\] = (a\[1\] - b\[1\]) / 2 |
| 341 | +#[inline] |
| 342 | +#[cfg_attr(test, assert_instr(shsub16))] |
| 343 | +pub unsafe fn shsub16(a: int16x2_t, b: int16x2_t) -> int16x2_t { |
| 344 | + dsp_call!(arm_shsub16, a, b) |
| 345 | +} |
| 346 | + |
| 347 | +/// Signed Dual Multiply Add. |
| 348 | +/// |
| 349 | +/// Returns the equivalent of |
| 350 | +/// |
| 351 | +/// res = a\[0\] * b\[0\] + a\[1\] * b\[1\] |
| 352 | +/// |
| 353 | +/// and sets the Q flag if overflow occurs on the addition. |
| 354 | +#[inline] |
| 355 | +#[cfg_attr(test, assert_instr(smuad))] |
| 356 | +pub unsafe fn smuad(a: int16x2_t, b: int16x2_t) -> i32 { |
| 357 | + arm_smuad(::mem::transmute(a), ::mem::transmute(b)) |
| 358 | +} |
| 359 | + |
| 360 | +/// Signed Dual Multiply Add Reversed. |
| 361 | +/// |
| 362 | +/// Returns the equivalent of |
| 363 | +/// |
| 364 | +/// res = a\[0\] * b\[1\] + a\[1\] * b\[0\] |
| 365 | +/// |
| 366 | +/// and sets the Q flag if overflow occurs on the addition. |
| 367 | +#[inline] |
| 368 | +#[cfg_attr(test, assert_instr(smuadx))] |
| 369 | +pub unsafe fn smuadx(a: int16x2_t, b: int16x2_t) -> i32 { |
| 370 | + arm_smuadx(::mem::transmute(a), ::mem::transmute(b)) |
| 371 | +} |
| 372 | + |
| 373 | +/// Signed Dual Multiply Subtract. |
| 374 | +/// |
| 375 | +/// Returns the equivalent of |
| 376 | +/// |
| 377 | +/// res = a\[0\] * b\[0\] - a\[1\] * b\[1\] |
| 378 | +/// |
| 379 | +/// and sets the Q flag if overflow occurs on the addition. |
| 380 | +#[inline] |
| 381 | +#[cfg_attr(test, assert_instr(smusd))] |
| 382 | +pub unsafe fn smusd(a: int16x2_t, b: int16x2_t) -> i32 { |
| 383 | + arm_smusd(::mem::transmute(a), ::mem::transmute(b)) |
| 384 | +} |
| 385 | + |
| 386 | +/// Signed Dual Multiply Subtract Reversed. |
| 387 | +/// |
| 388 | +/// Returns the equivalent of |
| 389 | +/// |
| 390 | +/// res = a\[0\] * b\[1\] - a\[1\] * b\[0\] |
| 391 | +/// |
| 392 | +/// and sets the Q flag if overflow occurs on the addition. |
| 393 | +#[inline] |
| 394 | +#[cfg_attr(test, assert_instr(smusdx))] |
| 395 | +pub unsafe fn smusdx(a: int16x2_t, b: int16x2_t) -> i32 { |
| 396 | + arm_smusdx(::mem::transmute(a), ::mem::transmute(b)) |
| 397 | +} |
| 398 | + |
| 399 | +/// Sum of 8-bit absolute differences. |
| 400 | +/// |
| 401 | +/// Returns the 8-bit unsigned equivalent of |
| 402 | +/// |
| 403 | +/// res = abs(a\[0\] - b\[0\]) + abs(a\[1\] - b\[1\]) +\ |
| 404 | +/// (a\[2\] - b\[2\]) + (a\[3\] - b\[3\]) |
| 405 | +#[inline] |
| 406 | +#[cfg_attr(test, assert_instr(usad8))] |
| 407 | +pub unsafe fn usad8(a: int8x4_t, b: int8x4_t) -> u32 { |
| 408 | + arm_usad8(::mem::transmute(a), ::mem::transmute(b)) |
| 409 | +} |
| 410 | + |
| 411 | +/// Sum of 8-bit absolute differences and constant. |
| 412 | +/// |
| 413 | +/// Returns the 8-bit unsigned equivalent of |
| 414 | +/// |
| 415 | +/// res = abs(a\[0\] - b\[0\]) + abs(a\[1\] - b\[1\]) +\ |
| 416 | +/// (a\[2\] - b\[2\]) + (a\[3\] - b\[3\]) + c |
| 417 | +#[inline] |
| 418 | +#[cfg_attr(test, assert_instr(usad8))] |
| 419 | +pub unsafe fn usada8(a: int8x4_t, b: int8x4_t, c: u32) -> u32 { |
| 420 | + usad8(a, b) + c |
| 421 | +} |
| 422 | + |
| 423 | +#[cfg(test)] |
| 424 | +mod tests { |
| 425 | + use core_arch::arm::*; |
| 426 | + use core_arch::simd::*; |
| 427 | + use std::mem; |
| 428 | + use stdsimd_test::simd_test; |
| 429 | + |
| 430 | + #[test] |
| 431 | + fn qadd() { |
| 432 | + unsafe { |
| 433 | + assert_eq!(dsp::qadd(-10, 60), 50); |
| 434 | + assert_eq!(dsp::qadd(::std::i32::MAX, 10), ::std::i32::MAX); |
| 435 | + assert_eq!(dsp::qadd(::std::i32::MIN, -10), ::std::i32::MIN); |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + #[test] |
| 440 | + fn qsub() { |
| 441 | + unsafe { |
| 442 | + assert_eq!(dsp::qsub(10, 60), -50); |
| 443 | + assert_eq!(dsp::qsub(::std::i32::MAX, -10), ::std::i32::MAX); |
| 444 | + assert_eq!(dsp::qsub(::std::i32::MIN, 10), ::std::i32::MIN); |
| 445 | + } |
| 446 | + } |
| 447 | + |
| 448 | + #[test] |
| 449 | + fn qadd8() { |
| 450 | + unsafe { |
| 451 | + let a = i8x4::new(1, 2, 3, ::std::i8::MAX); |
| 452 | + let b = i8x4::new(2, -1, 0, 1); |
| 453 | + let c = i8x4::new(3, 1, 3, ::std::i8::MAX); |
| 454 | + let r: i8x4 = dsp_call!(dsp::qadd8, a, b); |
| 455 | + assert_eq!(r, c); |
| 456 | + } |
| 457 | + } |
| 458 | + |
| 459 | + #[test] |
| 460 | + fn qsub8() { |
| 461 | + unsafe { |
| 462 | + let a = i8x4::new(1, 2, 3, ::std::i8::MIN); |
| 463 | + let b = i8x4::new(2, -1, 0, 1); |
| 464 | + let c = i8x4::new(-1, 3, 3, ::std::i8::MIN); |
| 465 | + let r: i8x4 = dsp_call!(dsp::qsub8, a, b); |
| 466 | + assert_eq!(r, c); |
| 467 | + } |
| 468 | + } |
| 469 | + |
| 470 | + #[test] |
| 471 | + fn qadd16() { |
| 472 | + unsafe { |
| 473 | + let a = i16x2::new(1, 2); |
| 474 | + let b = i16x2::new(2, -1); |
| 475 | + let c = i16x2::new(3, 1); |
| 476 | + let r: i16x2 = dsp_call!(dsp::qadd16, a, b); |
| 477 | + assert_eq!(r, c); |
| 478 | + } |
| 479 | + } |
| 480 | + |
| 481 | + #[test] |
| 482 | + fn qsub16() { |
| 483 | + unsafe { |
| 484 | + let a = i16x2::new(10, 20); |
| 485 | + let b = i16x2::new(20, -10); |
| 486 | + let c = i16x2::new(-10, 30); |
| 487 | + let r: i16x2 = dsp_call!(dsp::qsub16, a, b); |
| 488 | + assert_eq!(r, c); |
| 489 | + } |
| 490 | + } |
| 491 | + |
| 492 | + #[test] |
| 493 | + fn qasx() { |
| 494 | + unsafe { |
| 495 | + let a = i16x2::new(1, ::std::i16::MAX); |
| 496 | + let b = i16x2::new(2, 2); |
| 497 | + let c = i16x2::new(-1, ::std::i16::MAX); |
| 498 | + let r: i16x2 = dsp_call!(dsp::qasx, a, b); |
| 499 | + assert_eq!(r, c); |
| 500 | + } |
| 501 | + } |
| 502 | + |
| 503 | + #[test] |
| 504 | + fn qsax() { |
| 505 | + unsafe { |
| 506 | + let a = i16x2::new(1, ::std::i16::MAX); |
| 507 | + let b = i16x2::new(2, 2); |
| 508 | + let c = i16x2::new(3, ::std::i16::MAX - 2); |
| 509 | + let r: i16x2 = dsp_call!(dsp::qsax, a, b); |
| 510 | + assert_eq!(r, c); |
| 511 | + } |
| 512 | + } |
| 513 | + |
| 514 | + #[test] |
| 515 | + fn sadd16() { |
| 516 | + unsafe { |
| 517 | + let a = i16x2::new(1, ::std::i16::MAX); |
| 518 | + let b = i16x2::new(2, 2); |
| 519 | + let c = i16x2::new(3, -::std::i16::MAX); |
| 520 | + let r: i16x2 = dsp_call!(dsp::sadd16, a, b); |
| 521 | + assert_eq!(r, c); |
| 522 | + } |
| 523 | + } |
| 524 | + |
| 525 | + #[test] |
| 526 | + fn sadd8() { |
| 527 | + unsafe { |
| 528 | + let a = i8x4::new(1, 2, 3, ::std::i8::MAX); |
| 529 | + let b = i8x4::new(4, 3, 2, 2); |
| 530 | + let c = i8x4::new(5, 5, 5, -::std::i8::MAX); |
| 531 | + let r: i8x4 = dsp_call!(dsp::sadd8, a, b); |
| 532 | + assert_eq!(r, c); |
| 533 | + } |
| 534 | + } |
| 535 | + |
| 536 | + #[test] |
| 537 | + fn sasx() { |
| 538 | + unsafe { |
| 539 | + let a = i16x2::new(1, 2); |
| 540 | + let b = i16x2::new(2, 1); |
| 541 | + let c = i16x2::new(0, 4); |
| 542 | + let r: i16x2 = dsp_call!(dsp::sasx, a, b); |
| 543 | + assert_eq!(r, c); |
| 544 | + } |
| 545 | + } |
| 546 | + |
| 547 | + #[test] |
| 548 | + fn smlad() { |
| 549 | + unsafe { |
| 550 | + let a = i16x2::new(1, 2); |
| 551 | + let b = i16x2::new(3, 4); |
| 552 | + let r = dsp::smlad(::mem::transmute(a), ::mem::transmute(b), 10); |
| 553 | + assert_eq!(r, (1 * 3) + (2 * 4) + 10); |
| 554 | + } |
| 555 | + } |
| 556 | + |
| 557 | + #[test] |
| 558 | + fn smlsd() { |
| 559 | + unsafe { |
| 560 | + let a = i16x2::new(1, 2); |
| 561 | + let b = i16x2::new(3, 4); |
| 562 | + let r = dsp::smlsd(::mem::transmute(a), ::mem::transmute(b), 10); |
| 563 | + assert_eq!(r, ((1 * 3) - (2 * 4)) + 10); |
| 564 | + } |
| 565 | + } |
| 566 | + |
| 567 | + #[test] |
| 568 | + fn sel() { |
| 569 | + unsafe { |
| 570 | + let a = i8x4::new(1, 2, 3, ::std::i8::MAX); |
| 571 | + let b = i8x4::new(4, 3, 2, 2); |
| 572 | + // call sadd8() to set GE bits |
| 573 | + dsp::sadd8(::mem::transmute(a), ::mem::transmute(b)); |
| 574 | + let c = i8x4::new(1, 2, 3, ::std::i8::MAX); |
| 575 | + let r: i8x4 = dsp_call!(dsp::sel, a, b); |
| 576 | + assert_eq!(r, c); |
| 577 | + } |
| 578 | + } |
| 579 | + |
| 580 | + #[test] |
| 581 | + fn shadd8() { |
| 582 | + unsafe { |
| 583 | + let a = i8x4::new(1, 2, 3, 4); |
| 584 | + let b = i8x4::new(5, 4, 3, 2); |
| 585 | + let c = i8x4::new(3, 3, 3, 3); |
| 586 | + let r: i8x4 = dsp_call!(dsp::shadd8, a, b); |
| 587 | + assert_eq!(r, c); |
| 588 | + } |
| 589 | + } |
| 590 | + |
| 591 | + #[test] |
| 592 | + fn shadd16() { |
| 593 | + unsafe { |
| 594 | + let a = i16x2::new(1, 2); |
| 595 | + let b = i16x2::new(5, 4); |
| 596 | + let c = i16x2::new(3, 3); |
| 597 | + let r: i16x2 = dsp_call!(dsp::shadd16, a, b); |
| 598 | + assert_eq!(r, c); |
| 599 | + } |
| 600 | + } |
| 601 | + |
| 602 | + #[test] |
| 603 | + fn shsub8() { |
| 604 | + unsafe { |
| 605 | + let a = i8x4::new(1, 2, 3, 4); |
| 606 | + let b = i8x4::new(5, 4, 3, 2); |
| 607 | + let c = i8x4::new(-2, -1, 0, 1); |
| 608 | + let r: i8x4 = dsp_call!(dsp::shsub8, a, b); |
| 609 | + assert_eq!(r, c); |
| 610 | + } |
| 611 | + } |
| 612 | + |
| 613 | + #[test] |
| 614 | + fn shsub16() { |
| 615 | + unsafe { |
| 616 | + let a = i16x2::new(1, 2); |
| 617 | + let b = i16x2::new(5, 4); |
| 618 | + let c = i16x2::new(-2, -1); |
| 619 | + let r: i16x2 = dsp_call!(dsp::shsub16, a, b); |
| 620 | + assert_eq!(r, c); |
| 621 | + } |
| 622 | + } |
| 623 | + |
| 624 | + #[test] |
| 625 | + fn smuad() { |
| 626 | + unsafe { |
| 627 | + let a = i16x2::new(1, 2); |
| 628 | + let b = i16x2::new(5, 4); |
| 629 | + let r = dsp::smuad(::mem::transmute(a), ::mem::transmute(b)); |
| 630 | + assert_eq!(r, 13); |
| 631 | + } |
| 632 | + } |
| 633 | + |
| 634 | + #[test] |
| 635 | + fn smuadx() { |
| 636 | + unsafe { |
| 637 | + let a = i16x2::new(1, 2); |
| 638 | + let b = i16x2::new(5, 4); |
| 639 | + let r = dsp::smuadx(::mem::transmute(a), ::mem::transmute(b)); |
| 640 | + assert_eq!(r, 14); |
| 641 | + } |
| 642 | + } |
| 643 | + |
| 644 | + #[test] |
| 645 | + fn smusd() { |
| 646 | + unsafe { |
| 647 | + let a = i16x2::new(1, 2); |
| 648 | + let b = i16x2::new(5, 4); |
| 649 | + let r = dsp::smusd(::mem::transmute(a), ::mem::transmute(b)); |
| 650 | + assert_eq!(r, -3); |
| 651 | + } |
| 652 | + } |
| 653 | + |
| 654 | + #[test] |
| 655 | + fn smusdx() { |
| 656 | + unsafe { |
| 657 | + let a = i16x2::new(1, 2); |
| 658 | + let b = i16x2::new(5, 4); |
| 659 | + let r = dsp::smusdx(::mem::transmute(a), ::mem::transmute(b)); |
| 660 | + assert_eq!(r, -6); |
| 661 | + } |
| 662 | + } |
| 663 | + |
| 664 | + #[test] |
| 665 | + fn usad8() { |
| 666 | + unsafe { |
| 667 | + let a = i8x4::new(1, 2, 3, 4); |
| 668 | + let b = i8x4::new(4, 3, 2, 1); |
| 669 | + let r = dsp::usad8(::mem::transmute(a), ::mem::transmute(b)); |
| 670 | + assert_eq!(r, 8); |
| 671 | + } |
| 672 | + } |
| 673 | + |
| 674 | + #[test] |
| 675 | + fn usad8a() { |
| 676 | + unsafe { |
| 677 | + let a = i8x4::new(1, 2, 3, 4); |
| 678 | + let b = i8x4::new(4, 3, 2, 1); |
| 679 | + let c = 10; |
| 680 | + let r = dsp::usad8a(::mem::transmute(a), ::mem::transmute(b), c); |
| 681 | + assert_eq!(r, 8 + c); |
| 682 | + } |
| 683 | + } |
| 684 | +} |
0 commit comments