Skip to content
Closed
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
Use SET macros instead
  • Loading branch information
zooba committed Feb 14, 2023
commit 5005130274d1132c6644a087ace40f0c9a8be8bc
10 changes: 9 additions & 1 deletion Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ _py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
word->_op.opcode = opcode;
}

#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode)
#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), opcode)

static inline void
_py_set_oparg(_Py_CODEUNIT *word, uint8_t oparg)
{
word->_op.oparg = oparg;
}

#define _Py_SET_OPARG(word, opcode) _py_set_oparg(&(word), opcode)

typedef struct {
PyObject *_co_code;
Expand Down
10 changes: 5 additions & 5 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,10 +1507,10 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
_Py_CODEUNIT instruction = instructions[i];
int opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
int caches = _PyOpcode_Caches[opcode];
_Py_OPCODE(instructions[i]) = opcode;
_Py_SET_OPCODE(instructions[i], opcode);
while (caches--) {
_Py_OPCODE(instructions[++i]) = CACHE;
_Py_OPARG(instructions[i]) = 0;
_Py_SET_OPCODE(instructions[++i], CACHE);
_Py_SET_OPARG(instructions[i], 0);
}
}
}
Expand Down Expand Up @@ -1763,8 +1763,8 @@ code_richcompare(PyObject *self, PyObject *other, int op)
for (int i = 0; i < Py_SIZE(co); i++) {
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
_Py_OPCODE(co_instr) = _PyOpcode_Deopt[_Py_OPCODE(co_instr)];
_Py_OPCODE(cp_instr) =_PyOpcode_Deopt[_Py_OPCODE(cp_instr)];
_Py_SET_OPCODE(co_instr, _PyOpcode_Deopt[_Py_OPCODE(co_instr)]);
_Py_SET_OPCODE(cp_instr, _PyOpcode_Deopt[_Py_OPCODE(cp_instr)]);
eq = co_instr.cache == cp_instr.cache;
if (!eq) {
goto unequal;
Expand Down
20 changes: 10 additions & 10 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,31 +274,31 @@ write_instr(_Py_CODEUNIT *codestr, struct instr *instruction, int ilen)
int caches = _PyOpcode_Caches[opcode];
switch (ilen - caches) {
case 4:
_Py_OPCODE(*codestr) = EXTENDED_ARG;
_Py_OPARG(*codestr) = (oparg >> 24) & 0xFF;
_Py_SET_OPCODE(*codestr, EXTENDED_ARG);
_Py_SET_OPARG(*codestr, (oparg >> 24) & 0xFF);
codestr++;
/* fall through */
case 3:
_Py_OPCODE(*codestr) = EXTENDED_ARG;
_Py_OPARG(*codestr) = (oparg >> 16) & 0xFF;
_Py_SET_OPCODE(*codestr, EXTENDED_ARG);
_Py_SET_OPARG(*codestr, (oparg >> 16) & 0xFF);
codestr++;
/* fall through */
case 2:
_Py_OPCODE(*codestr) = EXTENDED_ARG;
_Py_OPARG(*codestr) = (oparg >> 8) & 0xFF;
_Py_SET_OPCODE(*codestr, EXTENDED_ARG);
_Py_SET_OPARG(*codestr, (oparg >> 8) & 0xFF);
codestr++;
/* fall through */
case 1:
_Py_OPCODE(*codestr) = opcode;
_Py_OPARG(*codestr) = oparg & 0xFF;
_Py_SET_OPCODE(*codestr, opcode);
_Py_SET_OPARG(*codestr, oparg & 0xFF);
codestr++;
break;
default:
Py_UNREACHABLE();
}
while (caches--) {
_Py_OPCODE(*codestr) = CACHE;
_Py_OPARG(*codestr) = 0;
_Py_SET_OPCODE(*codestr, CACHE);
_Py_SET_OPARG(*codestr, 0);
codestr++;
}
}
Expand Down
14 changes: 7 additions & 7 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,19 @@ _PyCode_Quicken(PyCodeObject *code)
}
switch (previous_opcode << 8 | opcode) {
case LOAD_CONST << 8 | LOAD_FAST:
_Py_OPCODE(instructions[i - 1]) = LOAD_CONST__LOAD_FAST;
_Py_SET_OPCODE(instructions[i - 1], LOAD_CONST__LOAD_FAST);
break;
case LOAD_FAST << 8 | LOAD_CONST:
_Py_OPCODE(instructions[i - 1]) = LOAD_FAST__LOAD_CONST;
_Py_SET_OPCODE(instructions[i - 1], LOAD_FAST__LOAD_CONST);
break;
case LOAD_FAST << 8 | LOAD_FAST:
_Py_OPCODE(instructions[i - 1]) = LOAD_FAST__LOAD_FAST;
_Py_SET_OPCODE(instructions[i - 1], LOAD_FAST__LOAD_FAST);
break;
case STORE_FAST << 8 | LOAD_FAST:
_Py_OPCODE(instructions[i - 1]) = STORE_FAST__LOAD_FAST;
_Py_SET_OPCODE(instructions[i - 1], STORE_FAST__LOAD_FAST);
break;
case STORE_FAST << 8 | STORE_FAST:
_Py_OPCODE(instructions[i - 1]) = STORE_FAST__STORE_FAST;
_Py_SET_OPCODE(instructions[i - 1], STORE_FAST__STORE_FAST);
break;
case COMPARE_OP << 8 | POP_JUMP_IF_TRUE:
case COMPARE_OP << 8 | POP_JUMP_IF_FALSE:
Expand All @@ -314,8 +314,8 @@ _PyCode_Quicken(PyCodeObject *code)
if (opcode == POP_JUMP_IF_FALSE) {
mask = mask ^ 0xf;
}
_Py_OPCODE(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP]) = COMPARE_AND_BRANCH;
_Py_OPARG(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP]) = (oparg & 0xf0) | mask;
_Py_SET_OPCODE(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP], COMPARE_AND_BRANCH);
_Py_SET_OPARG(instructions[i - 1 - INLINE_CACHE_ENTRIES_COMPARE_OP], (oparg & 0xf0) | mask);
break;
}
}
Expand Down