Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPC is faster #3

Open
cloudhan opened this issue Jul 29, 2020 · 0 comments
Open

ISPC is faster #3

cloudhan opened this issue Jul 29, 2020 · 0 comments

Comments

@cloudhan
Copy link

struct Pixel { unsigned int8 r, g, b; };

unsigned int8 rgb2gray_kernel(Pixel p) {
    return (p.r *76 + p.g *150 + p.b *30) >> 8;
}

export void rgb2gray(uniform unsigned int8* uniform src,
                     uniform unsigned int8* uniform dst,
                     uniform size_t width,
                     uniform size_t height,
                     uniform size_t stride) {
    for (uniform int h=0; h<height; ++h) {
        uniform unsigned int8* uniform scanline_start = src + h * stride;
        uniform Pixel* scanline = (uniform Pixel* uniform)scanline_start;

        uniform unsigned int8* uniform out_scanline = dst + h * width;

        foreach (w= 0...width) {
            unsigned int8 v = rgb2gray_kernel(scanline[w]);
            out_scanline[w] = v;
        }
    }
}

compiled with

ispc rgb2gray.ispc -h rgb2gray.h -o rgb2gray.o -O3 --pic --target=avx2-i32x16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant