Skip to content

Commit 04edf5c

Browse files
committed
Refactor LOAD_GLOBAL to use a common conditional uop
1 parent b591bb3 commit 04edf5c

File tree

7 files changed

+79
-66
lines changed

7 files changed

+79
-66
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: 28 additions & 27 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: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,10 +1665,13 @@ dummy_func(
16651665
}
16661666

16671667
// res[1] because we need a pointer to res to pass it to _PyEval_LoadGlobalStackRef
1668-
op(_LOAD_GLOBAL, ( -- res[1], null if (oparg & 1))) {
1668+
op(_LOAD_GLOBAL, ( -- res[1])) {
16691669
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
16701670
_PyEval_LoadGlobalStackRef(GLOBALS(), BUILTINS(), name, res);
16711671
ERROR_IF(PyStackRef_IsNull(*res), error);
1672+
}
1673+
1674+
op(_PUSH_NULL_OPARG_AND_1, ( -- null if (oparg & 1))) {
16721675
null = PyStackRef_NULL;
16731676
}
16741677

@@ -1677,7 +1680,8 @@ dummy_func(
16771680
counter/1 +
16781681
globals_version/1 +
16791682
builtins_version/1 +
1680-
_LOAD_GLOBAL;
1683+
_LOAD_GLOBAL +
1684+
_PUSH_NULL_OPARG_AND_1;
16811685

16821686
op(_GUARD_GLOBALS_VERSION, (version/1 --)) {
16831687
PyDictObject *dict = (PyDictObject *)GLOBALS();
@@ -1707,7 +1711,7 @@ dummy_func(
17071711
assert(DK_IS_UNICODE(builtins_keys));
17081712
}
17091713

1710-
op(_LOAD_GLOBAL_MODULE_FROM_KEYS, (index/1, globals_keys: PyDictKeysObject* -- res, null if (oparg & 1))) {
1714+
op(_LOAD_GLOBAL_MODULE_FROM_KEYS, (index/1, globals_keys: PyDictKeysObject* -- res)) {
17111715
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(globals_keys);
17121716
PyObject *res_o = FT_ATOMIC_LOAD_PTR_RELAXED(entries[index].me_value);
17131717
DEAD(globals_keys);
@@ -1721,10 +1725,9 @@ dummy_func(
17211725
res = PyStackRef_FromPyObjectSteal(res_o);
17221726
#endif
17231727
STAT_INC(LOAD_GLOBAL, hit);
1724-
null = PyStackRef_NULL;
17251728
}
17261729

1727-
op(_LOAD_GLOBAL_BUILTINS_FROM_KEYS, (index/1, builtins_keys: PyDictKeysObject* -- res, null if (oparg & 1))) {
1730+
op(_LOAD_GLOBAL_BUILTINS_FROM_KEYS, (index/1, builtins_keys: PyDictKeysObject* -- res)) {
17281731
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(builtins_keys);
17291732
PyObject *res_o = FT_ATOMIC_LOAD_PTR_RELAXED(entries[index].me_value);
17301733
DEAD(builtins_keys);
@@ -1738,20 +1741,21 @@ dummy_func(
17381741
res = PyStackRef_FromPyObjectSteal(res_o);
17391742
#endif
17401743
STAT_INC(LOAD_GLOBAL, hit);
1741-
null = PyStackRef_NULL;
17421744
}
17431745

17441746
macro(LOAD_GLOBAL_MODULE) =
17451747
unused/1 + // Skip over the counter
17461748
_GUARD_GLOBALS_VERSION_PUSH_KEYS +
17471749
unused/1 + // Skip over the builtins version
1748-
_LOAD_GLOBAL_MODULE_FROM_KEYS;
1750+
_LOAD_GLOBAL_MODULE_FROM_KEYS +
1751+
_PUSH_NULL_OPARG_AND_1;
17491752

17501753
macro(LOAD_GLOBAL_BUILTIN) =
17511754
unused/1 + // Skip over the counter
17521755
_GUARD_GLOBALS_VERSION +
17531756
_GUARD_BUILTINS_VERSION_PUSH_KEYS +
1754-
_LOAD_GLOBAL_BUILTINS_FROM_KEYS;
1757+
_LOAD_GLOBAL_BUILTINS_FROM_KEYS +
1758+
_PUSH_NULL_OPARG_AND_1;
17551759

17561760
inst(DELETE_FAST, (--)) {
17571761
_PyStackRef v = GETLOCAL(oparg);

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)