Comment

Comment by LarsKrimi

Okay. Good point, that is quite a bit shorter than I first thought of

A rough benchmark of a version of that against the original shows it to be close to twice as fast for unpredictable input with GCC (4.5 ns vs 2.72 ns) on my old machine. With predictable input where x values often are the same the original version is quicker

    int sparse_8_jump(int x, int val) {
        unsigned int idx = (unsigned int)x >> 3;
        if (idx > 5)
            return 0;
        if (x & 7)
            return 0;
        
        switch (idx) {
            case 0:
                return f0(val);
            case 1:
                return f1(val);
            case 2:
                return f2(val);
            case 3:
                return f3(val);
            case 5:
                return f4(val);
            default:
                return 0;
        }
    }
parent LarsKrimi 15 hours ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton