🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove _SWAP_FAST for now, only specialize POP_TOP
  • Loading branch information
Fidget-Spinner committed Jun 23, 2025
commit 23197eb2e8cbe492174a8767e674e86b7414d211
6 changes: 3 additions & 3 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 28 additions & 28 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 8 additions & 29 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2349,11 +2349,10 @@ def testfunc(n):
assert ex is not None
"""))

def test_store_fast_pop_top_specialize_immortal(self):
def test_store_pop_top_specialize_none(self):
def testfunc(n):
for _ in range(n):
x = None # _POP_TOP, as x's type is not yet known by optimizer.
x = None # _POP_TOP_NOP, as x = None
global_identity(None)

testfunc(TIER2_THRESHOLD)

Expand All @@ -2363,12 +2362,10 @@ def testfunc(n):

self.assertIn("_POP_TOP_NOP", uops)

def test_store_fast_pop_top_specialize_int(self):
def test_store_pop_top_specialize_int(self):
def testfunc(n):
y = int(1e6) # Big number so no int caching
for _ in range(n):
x = y + y # _POP_TOP, as x's type is not yet known by optimizer.
x = None # _POP_TOP_INT, as x = int
global_identity(100000)

testfunc(TIER2_THRESHOLD)

Expand All @@ -2378,12 +2375,10 @@ def testfunc(n):

self.assertIn("_POP_TOP_INT", uops)

def test_store_fast_pop_top_specialize_float(self):
def test_store_pop_top_specialize_float(self):
def testfunc(n):
y = 1.0
for _ in range(n):
x = y + y # _POP_TOP, as x's type is not yet known by optimizer.
x = None # _POP_TOP_FLOAT, as x = int
global_identity(1e6)

testfunc(TIER2_THRESHOLD)

Expand All @@ -2393,12 +2388,10 @@ def testfunc(n):

self.assertIn("_POP_TOP_FLOAT", uops)

def test_store_fast_pop_top_specialize_unicode(self):
def test_store_pop_top_specialize_str(self):
def testfunc(n):
y = "hi"
for _ in range(n):
x = y + y # _POP_TOP, as x's type is not yet known by optimizer.
x = None # _POP_TOP_STR, as x = int
global_identity("2" + "1")

testfunc(TIER2_THRESHOLD)

Expand All @@ -2408,20 +2401,6 @@ def testfunc(n):

self.assertIn("_POP_TOP_UNICODE", uops)

def test_store_pop_top_specialize_none(self):
def testfunc(n):
for _ in range(n):
global_identity(None)

testfunc(TIER2_THRESHOLD)

ex = get_first_executor(testfunc)
self.assertIsNotNone(ex)
uops = get_opnames(ex)

self.assertIn("_POP_TOP_NOP", uops)



def global_identity(x):
return x
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Specialize :opcode:`POP_TOP` and thus :opcode:`STORE_FAST` in the JIT compiler by specializing for reference lifetime and type. This will also enable easier top of stack caching in the JIT compiler.
Specialize :opcode:`POP_TOP` in the JIT compiler by specializing for reference lifetime and type. This will also enable easier top of stack caching in the JIT compiler.
7 changes: 3 additions & 4 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,13 @@ dummy_func(
value = PyStackRef_FromPyObjectBorrow(obj);
}

replicate(8) op(_SWAP_FAST, (value -- trash)) {
trash = GETLOCAL(oparg);
replicate(8) inst(STORE_FAST, (value --)) {
_PyStackRef tmp = GETLOCAL(oparg);
GETLOCAL(oparg) = value;
DEAD(value);
PyStackRef_XCLOSE(tmp);
}

macro(STORE_FAST) = _SWAP_FAST + POP_TOP;

pseudo(STORE_FAST_MAYBE_NULL, (unused --)) = {
STORE_FAST,
};
Expand Down
Loading
Loading