-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
abs_diff
function to SimdInt
and SimdUint
traits
Implement `abs_diff` for signed and unsigned integer vectors Add tests for testing all `i8`s and `u8`s against the scalar `abs_diff`
- Loading branch information
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![feature(portable_simd)] | ||
|
||
use core_simd::simd::Simd; | ||
|
||
const LANES: usize = 16; | ||
|
||
#[test] | ||
fn abs_diff_i8() { | ||
use core_simd::simd::num::SimdInt; | ||
|
||
for x in i8::MIN..=i8::MAX { | ||
for y in i8::MIN..=i8::MAX { | ||
let left: Simd<u8, LANES> = Simd::splat(x.abs_diff(y)); | ||
let right = Simd::splat(x).abs_diff(Simd::splat(y)); | ||
|
||
assert_eq!(left, right); | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn abs_diff_u8() { | ||
use core_simd::simd::num::SimdUint; | ||
|
||
for x in u8::MIN..=u8::MAX { | ||
for y in u8::MIN..=u8::MAX { | ||
let left: Simd<u8, LANES> = Simd::splat(x.abs_diff(y)); | ||
let right = Simd::splat(x).abs_diff(Simd::splat(y)); | ||
|
||
assert_eq!(left, right); | ||
} | ||
} | ||
} |