]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
up the trace length
authorKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 25 Oct 2025 22:49:49 +0000 (23:49 +0100)
committerKen Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Sat, 25 Oct 2025 22:49:49 +0000 (23:49 +0100)
Include/internal/pycore_uop.h
Python/optimizer.c

index bccc0b00a4d210ff301425719e02da2b252d2d6c..4e1b15af42caa3d9df2d21cedc45a4bad8b23011 100644 (file)
@@ -36,7 +36,7 @@ typedef struct _PyUOpInstruction{
 } _PyUOpInstruction;
 
 // This is the length of the trace we translate initially.
-#define UOP_MAX_TRACE_LENGTH 1500
+#define UOP_MAX_TRACE_LENGTH 3000
 #define UOP_BUFFER_SIZE (UOP_MAX_TRACE_LENGTH * sizeof(_PyUOpInstruction))
 
 /* Bloom filter with m = 256
index 38fccafeda491139e21a38058ff85a36087c1878..d39156a41afdc2d502130c03b5ad46ba3b5a7d1c 100644 (file)
@@ -544,9 +544,6 @@ add_to_trace(
         goto full; \
     }
 
-// Reserve space for N uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE
-#define RESERVE(needed) RESERVE_RAW((needed) + 3, _PyUOpName(opcode))
-
 
 /* Returns 1 on success (added to trace), 0 on trace end.
  */
@@ -688,19 +685,13 @@ _PyJit_translate_single_bytecode_to_trace(
     }
 
     // One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT
-    max_length -= 2;
+    max_length -= 1;
 
     const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
 
-    ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
-
     assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
     assert(!_PyErr_Occurred(tstate));
 
-    if (!OPCODE_HAS_NO_SAVE_IP(opcode)) {
-        ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)target_instr, target);
-    }
-
     /* Special case the first instruction,
      * so that we can guarantee forward progress */
     if (progress_needed && tstate->interp->jit_state.code_curr_size <= 2) {
@@ -720,7 +711,13 @@ _PyJit_translate_single_bytecode_to_trace(
         max_length--;
     }
 
-    RESERVE_RAW(expansion->nuops + needs_guard_ip + 4, "uop and various checks");
+    RESERVE_RAW(expansion->nuops + needs_guard_ip + 3 + (!OPCODE_HAS_NO_SAVE_IP(opcode)), "uop and various checks");
+
+    ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
+
+    if (!OPCODE_HAS_NO_SAVE_IP(opcode)) {
+        ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)target_instr, target);
+    }
 
 
     switch (opcode) {
@@ -780,7 +777,6 @@ _PyJit_translate_single_bytecode_to_trace(
                 goto unsupported;
             }
             assert(nuops > 0);
-            RESERVE(nuops + 1); /* One extra for exit */
             uint32_t orig_oparg = oparg;  // For OPARG_TOP/BOTTOM
             uint32_t orig_target = target;
             for (int i = 0; i < nuops; i++) {