[New-bugs-announce] [issue46528] Simplify the VM's stack manipulations

Brandt Bucher report at bugs.python.org
Tue Jan 25 20:39:59 EST 2022

New submission from Brandt Bucher <brandtbucher at gmail.com>:

...as discussed in https://github.com/faster-cpython/ideas/discussions/228.

We can dramatically simplify our stack manipulations by getting rid of the `DUP_TOP*` and `ROT_*` families of instructions:

- Replace `DUP_TOP` with `COPY(1)`.
- Replace `DUP_TOP_TWO` with `COPY(2), COPY(2)`.
- Introduce a new `SWAP` instruction.
  - Replace `ROT_TWO` with `SWAP(2)`.
  - Replace `ROT_THREE` with `SWAP(3), SWAP(2)`.
  - Remove `ROT_FOUR`.
  - Replace `ROT_N(n)` with `SWAP(n), SWAP(n - 1), ..., SWAP(2)`.

It then becomes much simpler for the peephole optimizer to reason about code sequences involving these instructions (for example, it's pretty straightforward to truly *optimize* an arbitrary sequence of swaps).

assignee: brandtbucher
components: Interpreter Core
messages: 411697
nosy: Mark.Shannon, brandtbucher
priority: normal
severity: normal
status: open
title: Simplify the VM's stack manipulations
type: performance
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list