faster-cpython / ideas

1.67k stars 49 forks source link

non-register arg to a register instruction #527

Closed iritkatriel closed 1 year ago

iritkatriel commented 1 year ago

The cases generator currently generates arg = REG(opargi) statements for the inputs. We need a way to indicate in the DSL that an input is not a register index, but just a number (like a jump offset).

gvanrossum commented 1 year ago

Hm, for the stack machine this is not in the header at all, the body just uses oparg. Why can’t the register machine do this?

iritkatriel commented 1 year ago

It can, but the generator currently outputs the arg = REG(opargi), and we need it not to.

The easiest way for me to implement the jumps was to have the offset as oparg1 (it just reuses the current compiler code). Then the condition is in REG(oparg2). So it would be sufficient if I could write something in the header that says "ignore oparg1, set cond = REG(oparg2)".

iritkatriel commented 1 year ago

I just pushed my JUMPS implementation, so you can see what I did. (Some tests are failing due to peephole optimisations not working for these jumps yet).

iritkatriel commented 1 year ago

I'm not blocked on this, it seems to work (the offsets are small so it's not accessing crazy memory addresses?).

gvanrossum commented 1 year ago

Oh, seeing the code makes me realize that you can just name the first argument unused and then no code will be generated for it (or at least it shouldn't be -- this is how it is for the stack machine and for cache effects).

iritkatriel commented 1 year ago

Yes that works. Perfect.