@@ -708,60 +708,102 @@ dummy_func(
708708 macro (BINARY_OP_SUBTRACT_INT ) =
709709 _GUARD_TOS_INT + _GUARD_NOS_INT + unused /5 + _BINARY_OP_SUBTRACT_INT + _POP_TOP_INT + _POP_TOP_INT ;
710710
711- // Inplace compact int ops: mutate the uniquely-referenced operand
712- // when the result is a non- small medium int. For small int results,
713- // return the cached singleton. Deopt on overflow . Tier 2 only.
711+ // Inplace compact int ops: try to mutate the uniquely-referenced
712+ // operand. If TARGET is immortal ( small int at runtime) or the
713+ // result doesn't fit, fall back to _PyCompactLong_* . Tier 2 only.
714714 tier2 op (_BINARY_OP_ADD_INT_INPLACE , (left , right -- res , l , r )) {
715715 INT_INPLACE_OP (left , right , left , + );
716- EXIT_IF (_int_inplace_status == 2 );
717- res = _int_inplace_status == 1 ? _int_inplace_smallref : left ;
718- l = _int_inplace_status == 0 ? PyStackRef_NULL : left ;
716+ if (_int_inplace_ok ) {
717+ res = left ;
718+ l = PyStackRef_NULL ;
719+ }
720+ else {
721+ res = _PyCompactLong_Add ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
722+ (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
723+ EXIT_IF (PyStackRef_IsNull (res ));
724+ l = left ;
725+ }
719726 r = right ;
720727 INPUTS_DEAD ();
721728 }
722729
723730 tier2 op (_BINARY_OP_SUBTRACT_INT_INPLACE , (left , right -- res , l , r )) {
724731 INT_INPLACE_OP (left , right , left , - );
725- EXIT_IF (_int_inplace_status == 2 );
726- res = _int_inplace_status == 1 ? _int_inplace_smallref : left ;
727- l = _int_inplace_status == 0 ? PyStackRef_NULL : left ;
732+ if (_int_inplace_ok ) {
733+ res = left ;
734+ l = PyStackRef_NULL ;
735+ }
736+ else {
737+ res = _PyCompactLong_Subtract ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
738+ (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
739+ EXIT_IF (PyStackRef_IsNull (res ));
740+ l = left ;
741+ }
728742 r = right ;
729743 INPUTS_DEAD ();
730744 }
731745
732746 tier2 op (_BINARY_OP_MULTIPLY_INT_INPLACE , (left , right -- res , l , r )) {
733747 INT_INPLACE_OP (left , right , left , * );
734- EXIT_IF (_int_inplace_status == 2 );
735- res = _int_inplace_status == 1 ? _int_inplace_smallref : left ;
736- l = _int_inplace_status == 0 ? PyStackRef_NULL : left ;
748+ if (_int_inplace_ok ) {
749+ res = left ;
750+ l = PyStackRef_NULL ;
751+ }
752+ else {
753+ res = _PyCompactLong_Multiply ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
754+ (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
755+ EXIT_IF (PyStackRef_IsNull (res ));
756+ l = left ;
757+ }
737758 r = right ;
738759 INPUTS_DEAD ();
739760 }
740761
741762 tier2 op (_BINARY_OP_ADD_INT_INPLACE_RIGHT , (left , right -- res , l , r )) {
742763 INT_INPLACE_OP (left , right , right , + );
743- EXIT_IF (_int_inplace_status == 2 );
744- res = _int_inplace_status == 1 ? _int_inplace_smallref : right ;
764+ if (_int_inplace_ok ) {
765+ res = right ;
766+ r = PyStackRef_NULL ;
767+ }
768+ else {
769+ res = _PyCompactLong_Add ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
770+ (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
771+ EXIT_IF (PyStackRef_IsNull (res ));
772+ r = right ;
773+ }
745774 l = left ;
746- r = _int_inplace_status == 0 ? PyStackRef_NULL : right ;
747775 INPUTS_DEAD ();
748776 }
749777
750778 tier2 op (_BINARY_OP_SUBTRACT_INT_INPLACE_RIGHT , (left , right -- res , l , r )) {
751779 INT_INPLACE_OP (left , right , right , - );
752- EXIT_IF (_int_inplace_status == 2 );
753- res = _int_inplace_status == 1 ? _int_inplace_smallref : right ;
780+ if (_int_inplace_ok ) {
781+ res = right ;
782+ r = PyStackRef_NULL ;
783+ }
784+ else {
785+ res = _PyCompactLong_Subtract ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
786+ (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
787+ EXIT_IF (PyStackRef_IsNull (res ));
788+ r = right ;
789+ }
754790 l = left ;
755- r = _int_inplace_status == 0 ? PyStackRef_NULL : right ;
756791 INPUTS_DEAD ();
757792 }
758793
759794 tier2 op (_BINARY_OP_MULTIPLY_INT_INPLACE_RIGHT , (left , right -- res , l , r )) {
760795 INT_INPLACE_OP (left , right , right , * );
761- EXIT_IF (_int_inplace_status == 2 );
762- res = _int_inplace_status == 1 ? _int_inplace_smallref : right ;
796+ if (_int_inplace_ok ) {
797+ res = right ;
798+ r = PyStackRef_NULL ;
799+ }
800+ else {
801+ res = _PyCompactLong_Multiply ((PyLongObject * )PyStackRef_AsPyObjectBorrow (left ),
802+ (PyLongObject * )PyStackRef_AsPyObjectBorrow (right ));
803+ EXIT_IF (PyStackRef_IsNull (res ));
804+ r = right ;
805+ }
763806 l = left ;
764- r = _int_inplace_status == 0 ? PyStackRef_NULL : right ;
765807 INPUTS_DEAD ();
766808 }
767809
0 commit comments