summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2021-11-18 09:19:58 (GMT)
committerGitHub <noreply@github.com>2021-11-18 09:19:58 (GMT)
commit345ba3f080c140dee3102f472bc166c2db191bcc (patch)
tree302e16c6c660da6dcb5b5400447c24e90e4f4f2b /Python/ceval.c
parent0920b61a0cb30128287ebafab1df8cad3a3dffdb (diff)
downloadcpython-345ba3f080c140dee3102f472bc166c2db191bcc.zip
cpython-345ba3f080c140dee3102f472bc166c2db191bcc.tar.gz
cpython-345ba3f080c140dee3102f472bc166c2db191bcc.tar.bz2
bpo-45510: Specialize BINARY_SUBTRACT (GH-29523)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index c02e351..e579ede 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2009,6 +2009,41 @@ check_eval_breaker:
DISPATCH();
}
+ TARGET(BINARY_OP_SUBTRACT_INT) {
+ PyObject *left = SECOND();
+ PyObject *right = TOP();
+ DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
+ DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
+ STAT_INC(BINARY_OP, hit);
+ PyObject *sub = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
+ SET_SECOND(sub);
+ Py_DECREF(right);
+ Py_DECREF(left);
+ STACK_SHRINK(1);
+ if (sub == NULL) {
+ goto error;
+ }
+ DISPATCH();
+ }
+
+ TARGET(BINARY_OP_SUBTRACT_FLOAT) {
+ PyObject *left = SECOND();
+ PyObject *right = TOP();
+ DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
+ DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
+ STAT_INC(BINARY_OP, hit);
+ double dsub = ((PyFloatObject *)left)->ob_fval - ((PyFloatObject *)right)->ob_fval;
+ PyObject *sub = PyFloat_FromDouble(dsub);
+ SET_SECOND(sub);
+ Py_DECREF(right);
+ Py_DECREF(left);
+ STACK_SHRINK(1);
+ if (sub == NULL) {
+ goto error;
+ }
+ DISPATCH();
+ }
+
TARGET(BINARY_OP_ADD_UNICODE) {
PyObject *left = SECOND();
PyObject *right = TOP();