@@ -125,8 +125,8 @@ PyTypeObject _PyDefaultOptimizer_Type = {
125125static _PyOptimizerObject _PyOptimizer_Default = {
126126 PyObject_HEAD_INIT (& _PyDefaultOptimizer_Type )
127127 .optimize = never_optimize ,
128- .resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
129128 .backedge_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
129+ .resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
130130 .side_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ,
131131};
132132
@@ -189,10 +189,11 @@ _Py_SetOptimizer(PyInterpreterState *interp, _PyOptimizerObject *optimizer)
189189 interp -> optimizer = optimizer ;
190190 interp -> optimizer_backedge_threshold = shift_and_offset_threshold (optimizer -> backedge_threshold );
191191 interp -> optimizer_resume_threshold = shift_and_offset_threshold (optimizer -> resume_threshold );
192- interp -> optimizer_side_threshold = optimizer -> side_threshold ;
192+ interp -> optimizer_side_threshold = shift_and_offset_threshold ( optimizer -> side_threshold ) ;
193193 if (optimizer == & _PyOptimizer_Default ) {
194194 assert (interp -> optimizer_backedge_threshold == OPTIMIZER_UNREACHABLE_THRESHOLD );
195195 assert (interp -> optimizer_resume_threshold == OPTIMIZER_UNREACHABLE_THRESHOLD );
196+ assert (interp -> optimizer_side_threshold == OPTIMIZER_UNREACHABLE_THRESHOLD );
196197 }
197198 return old ;
198199}
@@ -1103,10 +1104,12 @@ make_executor_from_uops(_PyUOpInstruction *buffer, int length, const _PyBloomFil
11031104 }
11041105
11051106 /* Initialize exits */
1107+ PyInterpreterState * interp = _PyInterpreterState_GET ();
11061108 assert (exit_count < COLD_EXIT_COUNT );
11071109 for (int i = 0 ; i < exit_count ; i ++ ) {
11081110 executor -> exits [i ].executor = & COLD_EXITS [i ];
1109- executor -> exits [i ].temperature = 0 ;
1111+ executor -> exits [i ].temperature =
1112+ adaptive_counter_bits (interp -> optimizer_side_threshold , 4 ); // TODO: Constantify
11101113 }
11111114 int next_exit = exit_count - 1 ;
11121115 _PyUOpInstruction * dest = (_PyUOpInstruction * )& executor -> trace [length ];
@@ -1288,11 +1291,11 @@ PyUnstable_Optimizer_NewUOpOptimizer(void)
12881291 return NULL ;
12891292 }
12901293 opt -> optimize = uop_optimize ;
1291- opt -> resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
12921294 // Need a few iterations to settle specializations,
12931295 // and to ammortize the cost of optimization.
1294- opt -> side_threshold = 16 ;
12951296 opt -> backedge_threshold = 16 ;
1297+ opt -> resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1298+ opt -> side_threshold = 16 ;
12961299 return (PyObject * )opt ;
12971300}
12981301
@@ -1382,9 +1385,9 @@ PyUnstable_Optimizer_NewCounter(void)
13821385 return NULL ;
13831386 }
13841387 opt -> base .optimize = counter_optimize ;
1388+ opt -> base .backedge_threshold = 0 ;
13851389 opt -> base .resume_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
13861390 opt -> base .side_threshold = OPTIMIZER_UNREACHABLE_THRESHOLD ;
1387- opt -> base .backedge_threshold = 0 ;
13881391 opt -> count = 0 ;
13891392 return (PyObject * )opt ;
13901393}
@@ -1551,7 +1554,7 @@ _Py_ExecutorClear(_PyExecutorObject *executor)
15511554 for (uint32_t i = 0 ; i < executor -> exit_count ; i ++ ) {
15521555 Py_DECREF (executor -> exits [i ].executor );
15531556 executor -> exits [i ].executor = & COLD_EXITS [i ];
1554- executor -> exits [i ].temperature = INT16_MIN ;
1557+ executor -> exits [i ].temperature = OPTIMIZER_UNREACHABLE_THRESHOLD ;
15551558 }
15561559 _Py_CODEUNIT * instruction = & _PyCode_CODE (code )[executor -> vm_data .index ];
15571560 assert (instruction -> op .code == ENTER_EXECUTOR );
0 commit comments