image-rs / imageproc

Image processing operations
MIT License
735 stars 145 forks source link

SIMD optimization? #267

Open fschutt opened 6 years ago

fschutt commented 6 years ago

Since now the compiler has SIMD instructions on stable Rust, wouldn't it be a good idea to SIMD-optimize the operations internally? I.e.:

fn premultiply(data: &mut [u8]) {
    if is_sse2_detected!() {
        premultiply_sse2(data);
    } else {
        premultiply_fallback(data);
    }
}

This would use runtime feature detection, however, since an image is usually a lot of data, doing a one-time runtime check wouldn't add much overhead and with SIMD we could process 4, 8 or 16 bytes at a time, which would be much faster.

theotherphil commented 6 years ago

This would definitely be a good idea! I don't have any time at the moment to do this, but I'd gladly take pull requests. I'm not sure how to get this to play nicely with the image crate's ImageBuffer type that we use throughout - we'd probably have to manually convert back and forth between that type and its raw underlying buffer. Or just create our own image types or traits.

CsVeryLoveXieWenLi commented 1 year ago

now?

cospectrum commented 6 months ago

I would recommend relying on auto-vectorization