6

Added abs_diff for integer types. by orlp · Pull Request #88780 · rust-lang/rust...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/88780
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

the8472 commented on Sep 9

Does either of these compile to a psadbw (or equivalent SSE/AVX instructions for wider arrays) on x86?

fn sad_iter(a: &[u8; 8], b: &[u8; 8]) -> u32 {
  a.iter().zip(b).map(|&a, &b| a.abs_diff(b) as u32).sum()
}

fn sad_loop(a: &[u8; 8], b: &[u8; 8]) -> u32 {
  let mut sum = 0;
  for i in 0..a.len() {
      sum += a[i].abs_diff(b[i]) as u32;
  }
  sum
}

llvm does have some pattern detection to generate psadbw, so we should make sure we fall into that.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK