@@ -125,8 +125,8 @@ PyTypeObject _PyDefaultOptimizer_Type = {
125
125
static _PyOptimizerObject _PyOptimizer_Default = {
126
126
PyObject_HEAD_INIT (& _PyDefaultOptimizer_Type )
127
127
.optimize = never_optimize ,
128
- .resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
129
128
.backedge_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
129
+ .resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
130
130
.side_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
131
131
};
132
132
@@ -183,10 +183,11 @@ _Py_SetOptimizer(PyInterpreterState *interp, _PyOptimizerObject *optimizer)
183
183
interp -> optimizer = optimizer ;
184
184
interp -> optimizer_backedge_threshold = shift_and_offset_threshold (optimizer -> backedge_threshold );
185
185
interp -> optimizer_resume_threshold = shift_and_offset_threshold (optimizer -> resume_threshold );
186
- interp -> optimizer_side_threshold = optimizer -> side_threshold ;
186
+ interp -> optimizer_side_threshold = shift_and_offset_threshold ( optimizer -> side_threshold ) ;
187
187
if (optimizer == & _PyOptimizer_Default ) {
188
188
assert (interp -> optimizer_backedge_threshold == OPTIMIZER_UNREACHABLE_THRESHOLD );
189
189
assert (interp -> optimizer_resume_threshold == OPTIMIZER_UNREACHABLE_THRESHOLD );
190
+ assert (interp -> optimizer_side_threshold == OPTIMIZER_UNREACHABLE_THRESHOLD );
190
191
}
191
192
return old ;
192
193
}
@@ -941,9 +942,11 @@ make_executor_from_uops(_PyUOpInstruction *buffer, const _PyBloomFilter *depende
941
942
OPT_HIST (length , optimized_trace_length_hist );
942
943
943
944
/* Initialize exits */
945
+ PyInterpreterState * interp = _PyInterpreterState_GET ();
944
946
for (int i = 0 ; i < exit_count ; i ++ ) {
945
947
executor -> exits [i ].executor = & COLD_EXITS [i ];
946
- executor -> exits [i ].temperature = 0 ;
948
+ executor -> exits [i ].temperature =
949
+ adaptive_counter_bits (interp -> optimizer_side_threshold , 4 ); // TODO: Constantify
947
950
}
948
951
int next_exit = exit_count - 1 ;
949
952
_PyUOpInstruction * dest = (_PyUOpInstruction * )& executor -> trace [length - 1 ];
@@ -1104,11 +1107,11 @@ PyUnstable_Optimizer_NewUOpOptimizer(void)
1104
1107
return NULL ;
1105
1108
}
1106
1109
opt -> optimize = uop_optimize ;
1107
- opt -> resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1108
1110
// Need a few iterations to settle specializations,
1109
1111
// and to ammortize the cost of optimization.
1110
- opt -> side_threshold = 16 ;
1111
1112
opt -> backedge_threshold = 16 ;
1113
+ opt -> resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1114
+ opt -> side_threshold = 16 ;
1112
1115
return (PyObject * )opt ;
1113
1116
}
1114
1117
@@ -1196,9 +1199,9 @@ PyUnstable_Optimizer_NewCounter(void)
1196
1199
return NULL ;
1197
1200
}
1198
1201
opt -> base .optimize = counter_optimize ;
1202
+ opt -> base .backedge_threshold = 0 ;
1199
1203
opt -> base .resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1200
1204
opt -> base .side_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1201
- opt -> base .backedge_threshold = 0 ;
1202
1205
opt -> count = 0 ;
1203
1206
return (PyObject * )opt ;
1204
1207
}
@@ -1365,7 +1368,7 @@ _Py_ExecutorClear(_PyExecutorObject *executor)
1365
1368
for (uint32_t i = 0 ; i < executor -> exit_count ; i ++ ) {
1366
1369
Py_DECREF (executor -> exits [i ].executor );
1367
1370
executor -> exits [i ].executor = & COLD_EXITS [i ];
1368
- executor -> exits [i ].temperature = INT16_MIN ;
1371
+ executor -> exits [i ].temperature = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1369
1372
}
1370
1373
_Py_CODEUNIT * instruction = & _PyCode_CODE (code )[executor -> vm_data .index ];
1371
1374
assert (instruction -> op .code == ENTER_EXECUTOR );
0 commit comments