‹ BackHN Continuity

Thread

Reversing Factorio's RNG

255 points · 48 comments · jheitmann

  1. cmovq · · focus · HN ↗
    One of the reasons I dislike boost is in the first code sample. What’s the point of implementing what boils down to a 10 line function (as shown in the decompiled output) like this

        typedef xor_combine_engine<
      xor_combine_engine<
        linear_feedback_shift_engine<uint32_t, 32, 31, 13, 12>, 0,
        linear_feedback_shift_engine<uint32_t, 32, 29, 2, 4>, 0>, 0,
      linear_feedback_shift_engine<uint32_t, 32, 28, 3, 17>, 0> taus88;
    1. ainiriand · · focus · HN ↗
      C++ is uglier than punching one's dad.
      1. windenntw · · focus · HN ↗
        Correct, but also beside the point.

        To do it in almost-plain C, you'd need fairly complex macros that are more difficult to write correctly.

        To do it in plain C without macros, or plain C++ without templates... you'd need to work out the combination of the template expansion yourself and write down a piece of code that is more likely to have bugs and more difficult to understand.

        1. eru · · focus · HN ↗
          I'm not quite sure: you could probably use plain C functions, and a reasonably smart compiler could see through it all and inline and duplicate and merge the code as necessary.

          EDIT: I just had an AI agent run the experiment. At least for my version of clang, they produce the same assembly for x86_64 (modulo using slightly different registers).

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.