logoalt Hacker News

zipy124today at 11:03 AM2 repliesview on HN

It does and the key here is that adding the if is akin to avoiding a branch, since getting data then doing something with it is a hidden branch if you already have the data. All this code does is formalise the hidden branch so that it can be avoided when possible.


Replies

nextaccountictoday at 2:08 PM

> since getting data then doing something with it is a hidden branch if you already have the data

You mean that the naive, simpler code, despite not having an if, has a "branch" on the microarchitectural state? (which is like.. if we have this already in cache, do something. if not, do something else)

    // Find the optimal encoding for each symbol.
    // Chunk boundaries are located where encodings change.
    uint8_t encoding[n_symbols];
    uint8_t j = 0; // always start with encoding 0 for simplicity
    for (int i = 0; i < n_symbols; i++) {
        j = next_j[i][j];
        encoding[i] = j;
    }
summarybottoday at 12:40 PM

That's pretty cool. Is there something obcluding the compiler from noticing this parallelization opportunity without the new `if` ?

My understanding is the assignment and the evaluation are somehow coupled in this case based on the essay, but I could use an explanation.

show 1 reply