Skip to content

Commit 23197eb

Browse files
Remove _SWAP_FAST for now, only specialize POP_TOP
1 parent 134ad1f commit 23197eb

File tree

10 files changed

+134
-139
lines changed

10 files changed

+134
-139
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,11 +2349,10 @@ def testfunc(n):
23492349
assert ex is not None
23502350
"""))
23512351

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

23582357
testfunc(TIER2_THRESHOLD)
23592358

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

23642363
self.assertIn("_POP_TOP_NOP", uops)
23652364

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

23732370
testfunc(TIER2_THRESHOLD)
23742371

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

23792376
self.assertIn("_POP_TOP_INT", uops)
23802377

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

23882383
testfunc(TIER2_THRESHOLD)
23892384

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

23942389
self.assertIn("_POP_TOP_FLOAT", uops)
23952390

2396-
def test_store_fast_pop_top_specialize_unicode(self):
2391+
def test_store_pop_top_specialize_str(self):
23972392
def testfunc(n):
2398-
y = "hi"
23992393
for _ in range(n):
2400-
x = y + y # _POP_TOP, as x's type is not yet known by optimizer.
2401-
x = None # _POP_TOP_STR, as x = int
2394+
global_identity("2" + "1")
24022395

24032396
testfunc(TIER2_THRESHOLD)
24042397

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

24092402
self.assertIn("_POP_TOP_UNICODE", uops)
24102403

2411-
def test_store_pop_top_specialize_none(self):
2412-
def testfunc(n):
2413-
for _ in range(n):
2414-
global_identity(None)
2415-
2416-
testfunc(TIER2_THRESHOLD)
2417-
2418-
ex = get_first_executor(testfunc)
2419-
self.assertIsNotNone(ex)
2420-
uops = get_opnames(ex)
2421-
2422-
self.assertIn("_POP_TOP_NOP", uops)
2423-
2424-
24252404

24262405
def global_identity(x):
24272406
return x
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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.
1+
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.

Python/bytecodes.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,13 @@ dummy_func(
306306
value = PyStackRef_FromPyObjectBorrow(obj);
307307
}
308308

309-
replicate(8) op(_SWAP_FAST, (value -- trash)) {
310-
trash = GETLOCAL(oparg);
309+
replicate(8) inst(STORE_FAST, (value --)) {
310+
_PyStackRef tmp = GETLOCAL(oparg);
311311
GETLOCAL(oparg) = value;
312312
DEAD(value);
313+
PyStackRef_XCLOSE(tmp);
313314
}
314315

315-
macro(STORE_FAST) = _SWAP_FAST + POP_TOP;
316-
317316
pseudo(STORE_FAST_MAYBE_NULL, (unused --)) = {
318317
STORE_FAST,
319318
};

0 commit comments

Comments
 (0)