From 44c61a8c3a87fbf9f798127cac45bf0b939a3a69 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 17 Mar 2024 16:33:08 +0800 Subject: [PATCH] add `PREDICT_INT_DIV_OP` --- src/ceval.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ceval.cpp b/src/ceval.cpp index eff56782..fac6c535 100644 --- a/src/ceval.cpp +++ b/src/ceval.cpp @@ -8,6 +8,13 @@ namespace pkpy{ DISPATCH() \ } +#define PREDICT_INT_DIV_OP(op) \ + if(is_small_int(_0) && is_small_int(_1)){ \ + if(_1 == VAR(0)) ZeroDivisionError(); \ + TOP() = VAR((i64)(PK_BITS(_0)>>2) op (i64)(PK_BITS(_1)>>2)); \ + DISPATCH() \ + } + #define BINARY_F_COMPARE(func, op, rfunc) \ PyObject* ret; \ @@ -419,6 +426,7 @@ __NEXT_STEP:; TARGET(BINARY_FLOORDIV){ PyObject* _1 = POPX(); PyObject* _0 = TOP(); + PREDICT_INT_DIV_OP(/) const PyTypeInfo* _ti; BINARY_OP_SPECIAL(__floordiv__); if(TOP() == NotImplemented) BinaryOptError("//", _0, _1); @@ -426,6 +434,7 @@ __NEXT_STEP:; TARGET(BINARY_MOD){ PyObject* _1 = POPX(); PyObject* _0 = TOP(); + PREDICT_INT_DIV_OP(%) const PyTypeInfo* _ti; BINARY_OP_SPECIAL(__mod__); if(TOP() == NotImplemented) BinaryOptError("%", _0, _1);