Comment by 10000truths

Comment by 10000truths 5 months ago

3 replies

I feel like using calling conventions to massage the compiler's register allocation strategy is a hack. If the problem is manual control over register allocation, then the ideal solution should be... well, exactly that and no more? An annotation for local variables indicating "always spill this" (for cold-path locals) or "never spill this or else trigger a build error" (for hot-path locals). Isn't that literally why the "register" keyword exists in C? Why don't today's C compilers actually use it?

haberman 5 months ago

If the tail calling pattern made the code ugly, I would be more inclined to agree with this. But putting each opcode in its own function isn't so bad: it seems just as readable, if not more so, than a mondo function that implements every opcode.

By contrast, a mondo function that also has a bunch of register allocation annotations seems less readable.

  • 10000truths 5 months ago

    I don't see how a hypothetical __attribute__((never_spill)) annotation on local variables would preclude splitting opcode logic into separate functions. It just means those functions would have to be inlined into the interpreter loop to avoid conflicts with calling convention constraints.

    • haberman 5 months ago

      Agreed -- I'm just saying that the tail call pattern doesn't seem so bad to me. The shape it imposes on your code doesn't detract from readability in my opinion.