Multiplication optimization
Jean-Paul Calderone
exarkun at divmod.com
Sat Feb 18 22:43:32 EST 2006
On 18 Feb 2006 16:48:38 -0800, Paul McGuire <ptmcg at austin.rr.com> wrote:
>Does Python's run-time do any optimization of multiplication
>operations, like it does for boolean short-cutting?
Here's the beginning of int_mul from Objects/intobject.c:
static PyObject *
int_mul(PyObject *v, PyObject *w)
{
long a, b;
long longprod; /* a*b in native long arithmetic */
double doubled_longprod; /* (double)longprod */
double doubleprod; /* (double)a * (double)b */
CONVERT_TO_LONG(v, a);
CONVERT_TO_LONG(w, b);
longprod = a * b;
doubleprod = (double)a * (double)b;
doubled_longprod = (double)longprod;
I think the rest of the function is probably irrelevant, as far as your question goes.
Jean-Paul
More information about the Python-list
mailing list