Hacker Newsnew | past | comments | ask | show | jobs | submit | mtklein's commentslogin

Assuming we start with an overall even number of eyes, each instance of eye-for-eye justice reducing that overall count by 2 means that even parity is conserved.

Yeah but if we're the last two sighted people left, and I take out one of your eyes first (which you deserve because you blinded my friend!), then after one cycle of retaliation and counter-retaliation I am the proverbial one-eyed king. I'm sure you and your mates would love to take your revenge (again), but good luck catching me when none of you can see me.

sort of like this,

    #include <stdio.h>

    static int generator(int st, float *out) {
        switch (st++) {
            case 0: *out = 1.0f; return st;
            case 1: *out = 7.0f; return st;
            case 2: *out = 9.0f; return st;
        }
        return 0;
    }
   
    int main(void) {
        float f;
        for (int st = 0; (st = generator(st, &f));) {
            printf("generator yielded %g\n", (double)f);
        }
        return 0;
    }
but notice you also have the option to make the state static rather than a parameter, which gives you more encapsulation of your state machine at the cost of being way less flexible in terms of threading and reentrance.

That isn't Duff's device. Duff's device has NO return/break, it intentionally falls through to the next case statement. It is an interesting optimization that is only rarely useful (and probably even less useful in these days of optimization compilers) that everybody misunderstands.

Ah okay, thanks! Surprisingly more readable as there's no loop (in this example...)

If you really want readable, search for the protothreads library

This strikes me as one of those moments where the distinction between "will" and "shall" is important, and it's not clear whether the author intended to make it.

At that point,

    (* (+ a b c d) e)


I don't think it's too clever at all. Notably it works with both signed and unsigned i. Frankly if I see anyone doing anything other than this, they're wrong.


My first skim had me thinking he sent the package in the 90s; sadly it was just three weeks ago.


That's kind of exactly what floats are. You store the log2 of the number, a bit for its sign, and in what remaining bits you have left some fixed-point scaling between adjacent powers.


No, that is not what floats are. A logarithmic number system literally just stores the logarithm of a number (and a sign bit) and manipulates it as a logarithm. The significand is 1, always. So multiplication & division are simply addition & subtraction, respectively. But this simplification for multiplication, division, roots, and powers is counterbalanced by more complex addition and subtraction.[1]

[1] https://en.wikipedia.org/wiki/Logarithmic_number_system


Floats are actually rational numbers with denominators of power of 2.

https://en.wikipedia.org/wiki/Dyadic_rational#In_computing


I think they mean storing just an exponent instead of an exponent + mantissa. Makes multiplication much easier to implement.


As a former Skia contrib, this is cool as heck to read. It's exactly the sort of optimization work we had in mind when we wrote that SkRecord system, and I'm pleased that you were able to make use of nanobench. Back in those days we had just a few small optimizations that we could apply, mostly trying to eliminate unnecessary saveLayer() calls. Very cool to see it done in a modern way with Lean.


Thank you! The SkRecord system was _perfect_ for doing these optimizations. I don't think it would have been possible to do this project without it.


Let me also add that nanobench was a huge help, not just because it was a good benchmarking tool but also because it gave us some confidence that we're measuring the right thing. It's easy to make _something_ faster but hard to know if it's the right thing. Having that come pre-packaged from the project answers a lot of tricky questions that would otherwise be easy to get wrong.


That's how we felt answering performance questions of our own... we needed to know if our work was important, and the tools help keep that focus locked in. I'm no longer on the Skia team, but like, welcome to the Skia team; if you use nanobench, you're legit. :)

I'm the same user name @gmail.com if you ever have any questions. It's been a while but I'd be happy to try to page things back in for a good cause.


Hey, I am the first author of the paper, and thank you so much for the kind words. I am very grateful to you and all the other Skia contributors who've made the Skia codebase so easy to build and develop. I learnt so much about performance benchmarking by reading the nanobench source code too!


Decades ago they used to pull completely off the can (think Jimmy Buffet "stepped on a pop-top").


I should barely be listed as a co-author on what Claude does for me. Hiding Claude's contribution feels about as true as a combover to me.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: