faster-cpython / ideas

1.69k stars 49 forks source link

Expand the tier 2 instruction format to 2 operands #698

Open Fidget-Spinner opened 3 weeks ago

Fidget-Spinner commented 3 weeks ago

@markshannon and @brandtbucher

I propose we expand the tier 2 instruction format to hold 2 64-bit pointers worth of space.

My main reasoning follows:

  1. We likely won't interpret tier 2 instructions anymore, so space won't be an issue once we start discarding tier 2 instructions for JIT compilation.
  2. The tier 2 serves as an IR, it would be best to make the IR more flexible rather than artificially limit ourselves.
  3. I have ideas for strength reduction of guards that are only possible if we have an operand and a version number in a single instruction.

Thank you for your consideration.

brandtbucher commented 3 weeks ago

Yep, let’s do it. Some of the current tier-1-to-2 translations do weird, complicated things (like pushing operands to the stack just so the next instruction can use them, or repeating the same work twice in different instructions), and changing this will probably make things easier to understand and more efficient, at the cost of some bloat for the traces themselves.

Given that the C compiler will probably pad the struct to double its current size if we do this, we should probably just use this space and either bump the number of operands to 3, or just expand the union and bitfield into proper members.