@@ -71,14 +71,15 @@ do { \
71
71
72
72
#define inst (name , ...) case name:
73
73
#define super (name ) static int SUPER_##name
74
- #define family (name ) static int family_##name
74
+ #define family (name , ... ) static int family_##name
75
75
76
76
#define NAME_ERROR_MSG \
77
77
"name '%.200s' is not defined"
78
78
79
79
// Dummy variables for stack effects.
80
80
static PyObject * value , * value1 , * value2 , * left , * right , * res , * sum , * prod , * sub ;
81
81
static PyObject * container , * start , * stop , * v , * lhs , * rhs ;
82
+ static PyObject * list , * tuple , * dict ;
82
83
83
84
static PyObject *
84
85
dummy_func (
@@ -322,7 +323,15 @@ dummy_func(
322
323
ERROR_IF (sum == NULL , error );
323
324
}
324
325
325
- inst (BINARY_SUBSCR , (container , sub -- res )) {
326
+ family (binary_subscr , INLINE_CACHE_ENTRIES_BINARY_SUBSCR ) = {
327
+ BINARY_SUBSCR ,
328
+ BINARY_SUBSCR_DICT ,
329
+ BINARY_SUBSCR_GETITEM ,
330
+ BINARY_SUBSCR_LIST_INT ,
331
+ BINARY_SUBSCR_TUPLE_INT ,
332
+ };
333
+
334
+ inst (BINARY_SUBSCR , (container , sub , unused /4 -- res )) {
326
335
_PyBinarySubscrCache * cache = (_PyBinarySubscrCache * )next_instr ;
327
336
if (ADAPTIVE_COUNTER_IS_ZERO (cache -> counter )) {
328
337
assert (cframe .use_tracing == 0 );
@@ -336,7 +345,6 @@ dummy_func(
336
345
Py_DECREF (container );
337
346
Py_DECREF (sub );
338
347
ERROR_IF (res == NULL , error );
339
- JUMPBY (INLINE_CACHE_ENTRIES_BINARY_SUBSCR );
340
348
}
341
349
342
350
inst (BINARY_SLICE , (container , start , stop -- res )) {
@@ -369,11 +377,8 @@ dummy_func(
369
377
ERROR_IF (err , error );
370
378
}
371
379
372
- // stack effect: (__0 -- )
373
- inst (BINARY_SUBSCR_LIST_INT ) {
380
+ inst (BINARY_SUBSCR_LIST_INT , (list , sub , unused /4 -- res )) {
374
381
assert (cframe .use_tracing == 0 );
375
- PyObject * sub = TOP ();
376
- PyObject * list = SECOND ();
377
382
DEOPT_IF (!PyLong_CheckExact (sub ), BINARY_SUBSCR );
378
383
DEOPT_IF (!PyList_CheckExact (list ), BINARY_SUBSCR );
379
384
@@ -384,21 +389,15 @@ dummy_func(
384
389
Py_ssize_t index = ((PyLongObject * )sub )-> ob_digit [0 ];
385
390
DEOPT_IF (index >= PyList_GET_SIZE (list ), BINARY_SUBSCR );
386
391
STAT_INC (BINARY_SUBSCR , hit );
387
- PyObject * res = PyList_GET_ITEM (list , index );
392
+ res = PyList_GET_ITEM (list , index );
388
393
assert (res != NULL );
389
394
Py_INCREF (res );
390
- STACK_SHRINK (1 );
391
395
_Py_DECREF_SPECIALIZED (sub , (destructor )PyObject_Free );
392
- SET_TOP (res );
393
396
Py_DECREF (list );
394
- JUMPBY (INLINE_CACHE_ENTRIES_BINARY_SUBSCR );
395
397
}
396
398
397
- // stack effect: (__0 -- )
398
- inst (BINARY_SUBSCR_TUPLE_INT ) {
399
+ inst (BINARY_SUBSCR_TUPLE_INT , (tuple , sub , unused /4 -- res )) {
399
400
assert (cframe .use_tracing == 0 );
400
- PyObject * sub = TOP ();
401
- PyObject * tuple = SECOND ();
402
401
DEOPT_IF (!PyLong_CheckExact (sub ), BINARY_SUBSCR );
403
402
DEOPT_IF (!PyTuple_CheckExact (tuple ), BINARY_SUBSCR );
404
403
@@ -409,51 +408,39 @@ dummy_func(
409
408
Py_ssize_t index = ((PyLongObject * )sub )-> ob_digit [0 ];
410
409
DEOPT_IF (index >= PyTuple_GET_SIZE (tuple ), BINARY_SUBSCR );
411
410
STAT_INC (BINARY_SUBSCR , hit );
412
- PyObject * res = PyTuple_GET_ITEM (tuple , index );
411
+ res = PyTuple_GET_ITEM (tuple , index );
413
412
assert (res != NULL );
414
413
Py_INCREF (res );
415
- STACK_SHRINK (1 );
416
414
_Py_DECREF_SPECIALIZED (sub , (destructor )PyObject_Free );
417
- SET_TOP (res );
418
415
Py_DECREF (tuple );
419
- JUMPBY (INLINE_CACHE_ENTRIES_BINARY_SUBSCR );
420
416
}
421
417
422
- // stack effect: (__0 -- )
423
- inst (BINARY_SUBSCR_DICT ) {
418
+ inst (BINARY_SUBSCR_DICT , (dict , sub , unused /4 -- res )) {
424
419
assert (cframe .use_tracing == 0 );
425
- PyObject * dict = SECOND ();
426
- DEOPT_IF (!PyDict_CheckExact (SECOND ()), BINARY_SUBSCR );
420
+ DEOPT_IF (!PyDict_CheckExact (dict ), BINARY_SUBSCR );
427
421
STAT_INC (BINARY_SUBSCR , hit );
428
- PyObject * sub = TOP ();
429
- PyObject * res = PyDict_GetItemWithError (dict , sub );
422
+ res = PyDict_GetItemWithError (dict , sub );
430
423
if (res == NULL ) {
431
424
if (!_PyErr_Occurred (tstate )) {
432
425
_PyErr_SetKeyError (sub );
433
426
}
434
- goto error ;
427
+ Py_DECREF (dict );
428
+ Py_DECREF (sub );
429
+ ERROR_IF (1 , error );
435
430
}
436
- Py_INCREF (res );
437
- STACK_SHRINK (1 );
438
- Py_DECREF (sub );
439
- SET_TOP (res );
431
+ Py_INCREF (res ); // Do this before DECREF'ing dict, sub
440
432
Py_DECREF (dict );
441
- JUMPBY ( INLINE_CACHE_ENTRIES_BINARY_SUBSCR );
433
+ Py_DECREF ( sub );
442
434
}
443
435
444
- // stack effect: (__0 -- )
445
- inst (BINARY_SUBSCR_GETITEM ) {
446
- PyObject * sub = TOP ();
447
- PyObject * container = SECOND ();
448
- _PyBinarySubscrCache * cache = (_PyBinarySubscrCache * )next_instr ;
449
- uint32_t type_version = read_u32 (cache -> type_version );
436
+ inst (BINARY_SUBSCR_GETITEM , (container , sub , unused /1 , type_version /2 , func_version /1 -- unused )) {
450
437
PyTypeObject * tp = Py_TYPE (container );
451
438
DEOPT_IF (tp -> tp_version_tag != type_version , BINARY_SUBSCR );
452
439
assert (tp -> tp_flags & Py_TPFLAGS_HEAPTYPE );
453
440
PyObject * cached = ((PyHeapTypeObject * )tp )-> _spec_cache .getitem ;
454
441
assert (PyFunction_Check (cached ));
455
442
PyFunctionObject * getitem = (PyFunctionObject * )cached ;
456
- DEOPT_IF (getitem -> func_version != cache -> func_version , BINARY_SUBSCR );
443
+ DEOPT_IF (getitem -> func_version != func_version , BINARY_SUBSCR );
457
444
PyCodeObject * code = (PyCodeObject * )getitem -> func_code ;
458
445
assert (code -> co_argcount == 2 );
459
446
DEOPT_IF (!_PyThreadState_HasStackSpace (tstate , code -> co_framesize ), BINARY_SUBSCR );
0 commit comments