Skip to content

ISPC is faster #3

Description

@cloudhan
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions