Skip to content

Commit

Permalink
Silence warnings on Windows
Browse files Browse the repository at this point in the history
Instead of `int oparg` we now have `uint64_t operand`.
In the Tier 2 interpreter, we add `int oparg` and set it
to a truncated version of `operand` so instructions can
reference it.
  • Loading branch information
gvanrossum committed Jun 26, 2023
1 parent 2254f83 commit 2f6603e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Include/internal/pycore_uops.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {

typedef struct {
int opcode;
uintptr_t oparg;
uint64_t operand; // Sometimes oparg, sometimes a cache entry
} _PyUOpInstruction;

typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2808,10 +2808,12 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
_Py_CODEUNIT *ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive - 1;
int pc = 0;
int opcode;
uint64_t operand;
int oparg;
for (;;) {
opcode = self->trace[pc].opcode;
oparg = self->trace[pc].oparg;
operand = self->trace[pc].operand;
oparg = (int)operand;
#ifdef LLTRACE
if (lltrace >= 3) {
const char *opname = opcode < 256 ? _PyOpcode_OpName[opcode] : "";
Expand Down
28 changes: 14 additions & 14 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,35 +323,35 @@ translate_bytecode_to_trace(
code->co_firstlineno,
(long)(instr - (_Py_CODEUNIT *)code->co_code_adaptive));
}
#define ADD_TO_TRACE(OPCODE, OPARG) \
#define ADD_TO_TRACE(OPCODE, OPERAND) \
if (lltrace >= 2) { \
const char *opname = (OPCODE) < 256 ? _PyOpcode_OpName[(OPCODE)] : ""; \
fprintf(stderr, " ADD_TO_TRACE(%s %d, %d)\n", opname, (OPCODE), (OPARG)); \
fprintf(stderr, " ADD_TO_TRACE(%s %d, %llu)\n", opname, (OPCODE), (uint64_t)(OPERAND)); \
} \
trace[trace_length].opcode = (OPCODE); \
trace[trace_length].oparg = (OPARG); \
trace[trace_length].operand = (OPERAND); \
trace_length++;
#else
#define ADD_TO_TRACE(OPCODE, OPARG) \
#define ADD_TO_TRACE(OPCODE, OPERAND) \
trace[trace_length].opcode = (OPCODE); \
trace[trace_length].oparg = (OPARG); \
trace[trace_length].operand = (OPERAND); \
trace_length++;
#endif

int trace_length = 0;
// Always reserve space for one uop, plus SET_UP, plus EXIT_TRACE
while (trace_length + 3 <= max_length) {
int opcode = instr->op.code;
int oparg = instr->op.arg;
uint64_t operand = instr->op.arg;
switch (opcode) {
case LOAD_FAST_LOAD_FAST:
{
// Reserve space for two uops (+ SETUP + EXIT_TRACE)
if (trace_length + 4 > max_length) {
goto done;
}
int oparg1 = oparg >> 4;
int oparg2 = oparg & 15;
uint64_t oparg1 = operand >> 4;
uint64_t oparg2 = operand & 15;
ADD_TO_TRACE(LOAD_FAST, oparg1);
ADD_TO_TRACE(LOAD_FAST, oparg2);
break;
Expand All @@ -371,23 +371,23 @@ translate_bytecode_to_trace(
case 0:
break;
case 1:
oparg = read_u16(&instr[offset].cache);
operand = read_u16(&instr[offset].cache);
break;
case 2:
oparg = read_u32(&instr[offset].cache);
operand = read_u32(&instr[offset].cache);
break;
case 4:
oparg = read_u64(&instr[offset].cache);
operand = read_u64(&instr[offset].cache);
break;
default:
fprintf(stderr,
"opcode=%d, oparg=%d; nuops=%d, i=%d; size=%d, offset=%d\n",
opcode, oparg, nuops, i,
"opcode=%d, operand=%llu; nuops=%d, i=%d; size=%d, offset=%d\n",
opcode, operand, nuops, i,
expansion->uops[i].size,
expansion->uops[i].offset);
Py_FatalError("garbled expansion");
}
ADD_TO_TRACE(expansion->uops[i].uop, oparg);
ADD_TO_TRACE(expansion->uops[i].uop, operand);
assert(expansion->uops[0].size == 0); // TODO
}
break;
Expand Down
2 changes: 1 addition & 1 deletion Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def write_body(
f"{typ}{ceffect.name} = {func}(&next_instr[{cache_offset}].cache);"
)
else:
out.emit(f"{typ}{ceffect.name} = oparg;")
out.emit(f"{typ}{ceffect.name} = operand;")
cache_offset += ceffect.size
assert cache_offset == self.cache_offset + cache_adjust

Expand Down

0 comments on commit 2f6603e

Please sign in to comment.