From e8786448c9a52dc24f9af80b32eb8345040bf4bd Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sat, 1 Feb 2025 17:49:28 +0100 Subject: [PATCH 1/5] remove redundant condition inside `codegen_addop_load_const` --- Python/codegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/codegen.c b/Python/codegen.c index 0bf9526cdc8435..c432c31bebdd79 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -284,7 +284,7 @@ codegen_addop_load_const(compiler *c, location loc, PyObject *o) if (PyLong_CheckExact(o)) { int overflow; long val = PyLong_AsLongAndOverflow(o, &overflow); - if (!overflow && val >= 0 && val < 256 && val < _PY_NSMALLPOSINTS) { + if (!overflow && val >= 0 && val < 256) { ADDOP_I(c, loc, LOAD_SMALL_INT, val); return SUCCESS; } From 9ec033c16f2e4bf8c056185a6abb95993a2a8333 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 3 Feb 2025 10:06:05 +0100 Subject: [PATCH 2/5] Revert "remove redundant condition inside `codegen_addop_load_const`" This reverts commit e8786448c9a52dc24f9af80b32eb8345040bf4bd. --- Python/codegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/codegen.c b/Python/codegen.c index c432c31bebdd79..0bf9526cdc8435 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -284,7 +284,7 @@ codegen_addop_load_const(compiler *c, location loc, PyObject *o) if (PyLong_CheckExact(o)) { int overflow; long val = PyLong_AsLongAndOverflow(o, &overflow); - if (!overflow && val >= 0 && val < 256) { + if (!overflow && val >= 0 && val < 256 && val < _PY_NSMALLPOSINTS) { ADDOP_I(c, loc, LOAD_SMALL_INT, val); return SUCCESS; } From d5288814fae7caf8c25d0aa8bc9c81030cccdf44 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 3 Feb 2025 10:20:55 +0100 Subject: [PATCH 3/5] make condition a macro --- Include/internal/pycore_long.h | 2 ++ Python/codegen.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h index c52eb77692dd6a..3a038c8c4a7da6 100644 --- a/Include/internal/pycore_long.h +++ b/Include/internal/pycore_long.h @@ -65,6 +65,8 @@ PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *self); # error "_PY_NSMALLPOSINTS must be greater than or equal to 257" #endif +#define _IS_LOAD_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < _PY_NSMALLPOSINTS) + // Return a reference to the immortal zero singleton. // The function cannot return NULL. static inline PyObject* _PyLong_GetZero(void) diff --git a/Python/codegen.c b/Python/codegen.c index 0bf9526cdc8435..ef597191447188 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -284,7 +284,7 @@ codegen_addop_load_const(compiler *c, location loc, PyObject *o) if (PyLong_CheckExact(o)) { int overflow; long val = PyLong_AsLongAndOverflow(o, &overflow); - if (!overflow && val >= 0 && val < 256 && val < _PY_NSMALLPOSINTS) { + if (!overflow && _IS_LOAD_SMALL_INT(val)) { ADDOP_I(c, loc, LOAD_SMALL_INT, val); return SUCCESS; } From 9d5b6baa9ff9833e23164356120bf2b76006803a Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 3 Feb 2025 10:31:14 +0100 Subject: [PATCH 4/5] Update Include/internal/pycore_long.h Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- Include/internal/pycore_long.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h index 3a038c8c4a7da6..ab4a031cb9f9cd 100644 --- a/Include/internal/pycore_long.h +++ b/Include/internal/pycore_long.h @@ -65,7 +65,7 @@ PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *self); # error "_PY_NSMALLPOSINTS must be greater than or equal to 257" #endif -#define _IS_LOAD_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < _PY_NSMALLPOSINTS) +#define _IS_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < _PY_NSMALLPOSINTS) // Return a reference to the immortal zero singleton. // The function cannot return NULL. From 31f1d4ebda3f69e96b82c2e2947e4b514e858d5e Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 3 Feb 2025 10:32:38 +0100 Subject: [PATCH 5/5] rename macro --- Include/internal/pycore_long.h | 2 +- Python/codegen.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h index ab4a031cb9f9cd..df0656a7cb8f0c 100644 --- a/Include/internal/pycore_long.h +++ b/Include/internal/pycore_long.h @@ -65,7 +65,7 @@ PyAPI_FUNC(void) _PyLong_ExactDealloc(PyObject *self); # error "_PY_NSMALLPOSINTS must be greater than or equal to 257" #endif -#define _IS_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < _PY_NSMALLPOSINTS) +#define _PY_IS_SMALL_INT(val) ((val) >= 0 && (val) < 256 && (val) < _PY_NSMALLPOSINTS) // Return a reference to the immortal zero singleton. // The function cannot return NULL. diff --git a/Python/codegen.c b/Python/codegen.c index ef597191447188..e9853d7302f67f 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -284,7 +284,7 @@ codegen_addop_load_const(compiler *c, location loc, PyObject *o) if (PyLong_CheckExact(o)) { int overflow; long val = PyLong_AsLongAndOverflow(o, &overflow); - if (!overflow && _IS_LOAD_SMALL_INT(val)) { + if (!overflow && _PY_IS_SMALL_INT(val)) { ADDOP_I(c, loc, LOAD_SMALL_INT, val); return SUCCESS; }