You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Python/tier2_engine.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,3 +148,13 @@ TO DO.
148
148
The implementation will change soon, so there is no point in
149
149
documenting it until then.
150
150
151
+
152
+
# Tier 2 IR format
153
+
154
+
The tier 2 IR (Internal Representation) format is also the basis for the Tier 2 interpreter (though the two formats may eventually differ). This format is also used as the input to the machine code generator (the JIT compiler).
155
+
156
+
Tier 2 IR entries are all the same size; there is no equivalent to `EXTENDED_ARG` or trailing inline cache entries. Each instruction is a struct with the following fields (all integers of varying sizes):
157
+
158
+
-**opcode**: Sometimes the same as a Tier 1 opcode, sometimes a separate micro opcode. Tier 2 opcodes are 9 bits (as opposed to Tier 1 opcodes, which fit in 8 bits). By convention, Tier 2 opcode names start with `_`.
159
+
-**oparg**: The argument. Usually the same as the Tier 1 oparg after expansion of `EXTENDED_ARG` prefixes. Up to 32 bits.
160
+
-**operand**: An additional argument, Typically the value of *one* cache item from the Tier 1 inline cache, up to 64 bits.
Copy file name to clipboardExpand all lines: Python/vm-state.md
+2-20Lines changed: 2 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,11 @@
3
3
## Definition of Tiers
4
4
5
5
-**Tier 1** is the classic Python bytecode interpreter.
6
-
This includes the specializing [adaptive interpreter](adaptive.md).
7
-
-**Tier 2**, also known as the micro-instruction ("uop") interpreter, is a new interpreter with a different instruction format.
6
+
This includes the specializing [adaptive interpreter](../InternalDocs/adaptive.md).
7
+
-**Tier 2**, also known as the micro-instruction ("uop") interpreter, is a new execution engine.
8
8
It was introduced in Python 3.13, and also forms the basis for a JIT using copy-and-patch technology. See [Tier 2](tier2_engine.md) for more information.
9
9
10
10
11
-
# Frame state
12
-
13
-
Almost all interpreter state is nominally stored in the frame structure.
14
-
A pointer to the current frame is held in `frame`, for more information about what `frame` contains see [Frames](frames.md):
15
11
16
12
# Thread state and interpreter state
17
13
@@ -23,20 +19,6 @@ The thread state is also used to access the **interpreter state** (`tstate->inte
23
19
The interpreter state also holds the optimizer state (`optimizer` and some counters).
24
20
Note that the eval breaker may be moved to the thread state soon as part of the multicore (PEP 703) work.
25
21
26
-
## Fast locals and evaluation stack
27
-
28
-
The frame contains a single array of object pointers, `localsplus`, which contains both the fast locals and the stack.
29
-
The top of the stack, including the locals, is indicated by `stacktop`.
30
-
For example, in a function with three locals, if the stack contains one value, `frame->stacktop == 4`.
31
-
32
-
The interpreters share an implementation which uses the same memory but caches the depth (as a pointer) in a C local, `stack_pointer`.
33
-
We aren't sure yet exactly how the JIT will implement the stack; likely some of the values near the top of the stack will be held in registers.
34
-
35
-
## Instruction pointer
36
-
37
-
The canonical, in-memory, representation of the instruction pointer is `frame->instr_ptr`.
38
-
It always points to an instruction in the bytecode array of the frame's code object.
39
-
Dispatching on `frame->instr_ptr` would be very inefficient, so in Tier 1 we cache the upcoming value of `frame->instr_ptr` in the C local `next_instr`.
0 commit comments