@@ -2556,13 +2556,32 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
25562556 {NB_MULTIPLY , compactlong_float_guard , compactlong_float_multiply },
25572557};
25582558
2559+ int
2560+ _Py_Specialize_AddBinaryOpExtention (_PyBinaryOpSpecializationDescr * descr )
2561+ {
2562+ PyThreadState * tstate = PyThreadState_Get ();
2563+ _Py_c_array_t * extensions = & tstate -> interp -> binop_specializer_extentions ;
2564+ Py_ssize_t idx = tstate -> interp -> num_binop_specializer_extentions ;
2565+ if (idx == 0 ) {
2566+ _Py_CArray_Init (extensions , sizeof (_PyBinaryOpSpecializationDescr ), 10 );
2567+ }
2568+ if (_Py_CArray_EnsureCapacity (extensions , idx ) < 0 ) {
2569+ return -1 ;
2570+ }
2571+ _PyBinaryOpSpecializationDescr * descrs = (_PyBinaryOpSpecializationDescr * )extensions -> array ;
2572+ descrs [idx ] = * descr ;
2573+ tstate -> interp -> num_binop_specializer_extentions ++ ;
2574+ return 0 ;
2575+ }
2576+
25592577static int
2560- binary_op_extended_specialization (PyObject * lhs , PyObject * rhs , int oparg ,
2561- _PyBinaryOpSpecializationDescr * * descr )
2578+ binary_op_extended_specialization_from_list (
2579+ _PyBinaryOpSpecializationDescr * descrs , size_t size ,
2580+ PyObject * lhs , PyObject * rhs , int oparg ,
2581+ _PyBinaryOpSpecializationDescr * * descr )
25622582{
2563- size_t n = sizeof (binaryop_extend_descrs )/sizeof (_PyBinaryOpSpecializationDescr );
2564- for (size_t i = 0 ; i < n ; i ++ ) {
2565- _PyBinaryOpSpecializationDescr * d = & binaryop_extend_descrs [i ];
2583+ for (size_t i = 0 ; i < size ; i ++ ) {
2584+ _PyBinaryOpSpecializationDescr * d = & descrs [i ];
25662585 if (d -> oparg == oparg && d -> guard (lhs , rhs )) {
25672586 * descr = d ;
25682587 return 1 ;
@@ -2571,6 +2590,30 @@ binary_op_extended_specialization(PyObject *lhs, PyObject *rhs, int oparg,
25712590 return 0 ;
25722591}
25732592
2593+ static int
2594+ binary_op_extended_specialization (PyObject * lhs , PyObject * rhs , int oparg ,
2595+ _PyBinaryOpSpecializationDescr * * descr )
2596+ {
2597+ if (binary_op_extended_specialization_from_list (
2598+ binaryop_extend_descrs ,
2599+ sizeof (binaryop_extend_descrs )/sizeof (_PyBinaryOpSpecializationDescr ),
2600+ lhs , rhs , oparg , descr ))
2601+ {
2602+ return 1 ;
2603+ }
2604+
2605+ PyThreadState * tstate = PyThreadState_Get ();
2606+ _Py_c_array_t * extensions = & tstate -> interp -> binop_specializer_extentions ;
2607+ if (binary_op_extended_specialization_from_list (
2608+ (_PyBinaryOpSpecializationDescr * )extensions -> array ,
2609+ tstate -> interp -> num_binop_specializer_extentions ,
2610+ lhs , rhs , oparg , descr ))
2611+ {
2612+ return 1 ;
2613+ }
2614+ return 0 ;
2615+ }
2616+
25742617Py_NO_INLINE void
25752618_Py_Specialize_BinaryOp (_PyStackRef lhs_st , _PyStackRef rhs_st , _Py_CODEUNIT * instr ,
25762619 int oparg , _PyStackRef * locals )
0 commit comments