Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6868767

Browse filesBrowse files
committed
Modernize LOAD_GLOBAL_BUILTIN
1 parent 995822a commit 6868767
Copy full SHA for 6868767

File tree

3 files changed

+21
-24
lines changed
Filter options

3 files changed

+21
-24
lines changed

‎Python/bytecodes.c

Copy file name to clipboardExpand all lines: Python/bytecodes.c
+5-12Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ dummy_func(
10711071
family(load_global, INLINE_CACHE_ENTRIES_LOAD_GLOBAL) = {
10721072
LOAD_GLOBAL,
10731073
LOAD_GLOBAL_MODULE,
1074-
// LOAD_GLOBAL_BUILTIN,
1074+
LOAD_GLOBAL_BUILTIN,
10751075
};
10761076

10771077
inst(LOAD_GLOBAL, (unused/1, unused/1, unused/2, unused/1 -- null if (oparg & 1), v)) {
@@ -1143,28 +1143,21 @@ dummy_func(
11431143
null = NULL;
11441144
}
11451145

1146-
// error: LOAD_GLOBAL has irregular stack effect
1147-
inst(LOAD_GLOBAL_BUILTIN) {
1146+
inst(LOAD_GLOBAL_BUILTIN, (unused/1, index/1, mod_version/2, bltn_version/1 -- null if (oparg & 1), res)) {
11481147
assert(cframe.use_tracing == 0);
11491148
DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL);
11501149
DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL);
11511150
PyDictObject *mdict = (PyDictObject *)GLOBALS();
11521151
PyDictObject *bdict = (PyDictObject *)BUILTINS();
1153-
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
1154-
uint32_t mod_version = read_u32(cache->module_keys_version);
1155-
uint16_t bltn_version = cache->builtin_keys_version;
11561152
DEOPT_IF(mdict->ma_keys->dk_version != mod_version, LOAD_GLOBAL);
11571153
DEOPT_IF(bdict->ma_keys->dk_version != bltn_version, LOAD_GLOBAL);
11581154
assert(DK_IS_UNICODE(bdict->ma_keys));
11591155
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(bdict->ma_keys);
1160-
PyObject *res = entries[cache->index].me_value;
1156+
res = entries[index].me_value;
11611157
DEOPT_IF(res == NULL, LOAD_GLOBAL);
1162-
int push_null = oparg & 1;
1163-
PEEK(0) = NULL;
1164-
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_GLOBAL);
1158+
Py_INCREF(res);
11651159
STAT_INC(LOAD_GLOBAL, hit);
1166-
STACK_GROW(push_null+1);
1167-
SET_TOP(Py_NewRef(res));
1160+
null = NULL;
11681161
}
11691162

11701163
inst(DELETE_FAST, (--)) {

‎Python/generated_cases.c.h

Copy file name to clipboardExpand all lines: Python/generated_cases.c.h
+13-9Lines changed: 13 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Python/opcode_metadata.h

Copy file name to clipboardExpand all lines: Python/opcode_metadata.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ _PyOpcode_num_popped(int opcode, int oparg) {
145145
case LOAD_GLOBAL_MODULE:
146146
return 0;
147147
case LOAD_GLOBAL_BUILTIN:
148-
return -1;
148+
return 0;
149149
case DELETE_FAST:
150150
return 0;
151151
case MAKE_CELL:
@@ -491,7 +491,7 @@ _PyOpcode_num_pushed(int opcode, int oparg) {
491491
case LOAD_GLOBAL_MODULE:
492492
return ((oparg & 1) ? 1 : 0) + 1;
493493
case LOAD_GLOBAL_BUILTIN:
494-
return -1;
494+
return ((oparg & 1) ? 1 : 0) + 1;
495495
case DELETE_FAST:
496496
return 0;
497497
case MAKE_CELL:
@@ -771,7 +771,7 @@ struct opcode_metadata {
771771
[LOAD_NAME] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
772772
[LOAD_GLOBAL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
773773
[LOAD_GLOBAL_MODULE] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
774-
[LOAD_GLOBAL_BUILTIN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
774+
[LOAD_GLOBAL_BUILTIN] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC0000 },
775775
[DELETE_FAST] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
776776
[MAKE_CELL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
777777
[DELETE_DEREF] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.