[Python-checkins] r46291 - in python/trunk: Include/pyport.h Python/ceval.c

fredrik.lundh python-checkins at python.org
Fri May 26 13:29:39 CEST 2006


Author: fredrik.lundh
Date: Fri May 26 13:29:39 2006
New Revision: 46291

Modified:
   python/trunk/Include/pyport.h
   python/trunk/Python/ceval.c
Log:
needforspeed: added Py_LOCAL macro, based on the LOCAL macro used
for SRE and others.  applied Py_LOCAL to relevant portion of ceval,
which gives a 1-2% speedup on my machine.  ymmv.



Modified: python/trunk/Include/pyport.h
==============================================================================
--- python/trunk/Include/pyport.h	(original)
+++ python/trunk/Include/pyport.h	Fri May 26 13:29:39 2006
@@ -137,6 +137,23 @@
 #   endif
 #endif
 
+/* PY_LOCAL can be used instead of static to get the fastest possible calling
+ * convention for functions that are local to a given module.  It also enables
+ * inlining, where suitable. */
+
+#undef USE_INLINE /* XXX - set via configure? */
+
+#if defined(_MSC_VER)
+ /* ignore warnings if the compiler decides not to inline a function */ 
+#pragma warning(disable: 4710)
+/* fastest possible local call under MSVC */
+#define Py_LOCAL(type) static __inline type __fastcall
+#elif defined(USE_INLINE)
+#define Py_LOCAL(type) static inline type
+#else
+#define Py_LOCAL(type) static type
+#endif
+
 #include <stdlib.h>
 
 #include <math.h> /* Moved here from the math section, before extern "C" */

Modified: python/trunk/Python/ceval.c
==============================================================================
--- python/trunk/Python/ceval.c	(original)
+++ python/trunk/Python/ceval.c	Fri May 26 13:29:39 2006
@@ -30,7 +30,7 @@
 
 #define READ_TIMESTAMP(var) ppc_getcounter(&var)
 
-static void
+Py_LOCAL(void)
 ppc_getcounter(uint64 *v)
 {
 	register unsigned long tbu, tb, tbu2;
@@ -83,44 +83,44 @@
 
 /* Forward declarations */
 #ifdef WITH_TSC
-static PyObject *call_function(PyObject ***, int, uint64*, uint64*);
+Py_LOCAL(PyObject *)call_function(PyObject ***, int, uint64*, uint64*);
 #else
-static PyObject *call_function(PyObject ***, int);
+Py_LOCAL(PyObject *)call_function(PyObject ***, int);
 #endif
-static PyObject *fast_function(PyObject *, PyObject ***, int, int, int);
-static PyObject *do_call(PyObject *, PyObject ***, int, int);
-static PyObject *ext_do_call(PyObject *, PyObject ***, int, int, int);
-static PyObject *update_keyword_args(PyObject *, int, PyObject ***,PyObject *);
-static PyObject *update_star_args(int, int, PyObject *, PyObject ***);
-static PyObject *load_args(PyObject ***, int);
+Py_LOCAL(PyObject *)fast_function(PyObject *, PyObject ***, int, int, int);
+Py_LOCAL(PyObject *)do_call(PyObject *, PyObject ***, int, int);
+Py_LOCAL(PyObject *)ext_do_call(PyObject *, PyObject ***, int, int, int);
+Py_LOCAL(PyObject *)update_keyword_args(PyObject *, int, PyObject ***,PyObject *);
+Py_LOCAL(PyObject *)update_star_args(int, int, PyObject *, PyObject ***);
+Py_LOCAL(PyObject *)load_args(PyObject ***, int);
 #define CALL_FLAG_VAR 1
 #define CALL_FLAG_KW 2
 
 #ifdef LLTRACE
-static int lltrace;
-static int prtrace(PyObject *, char *);
+Py_LOCAL(int) lltrace;
+Py_LOCAL(int) prtrace(PyObject *, char *);
 #endif
-static int call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
+Py_LOCAL(int) call_trace(Py_tracefunc, PyObject *, PyFrameObject *,
 		      int, PyObject *);
-static void call_trace_protected(Py_tracefunc, PyObject *,
+Py_LOCAL(void) call_trace_protected(Py_tracefunc, PyObject *,
 				 PyFrameObject *, int, PyObject *);
-static void call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
-static int maybe_call_line_trace(Py_tracefunc, PyObject *,
+Py_LOCAL(void) call_exc_trace(Py_tracefunc, PyObject *, PyFrameObject *);
+Py_LOCAL(int) maybe_call_line_trace(Py_tracefunc, PyObject *,
 				  PyFrameObject *, int *, int *, int *);
 
-static PyObject *apply_slice(PyObject *, PyObject *, PyObject *);
-static int assign_slice(PyObject *, PyObject *,
+Py_LOCAL(PyObject *)apply_slice(PyObject *, PyObject *, PyObject *);
+Py_LOCAL(int) assign_slice(PyObject *, PyObject *,
 			PyObject *, PyObject *);
-static PyObject *cmp_outcome(int, PyObject *, PyObject *);
-static PyObject *import_from(PyObject *, PyObject *);
-static int import_all_from(PyObject *, PyObject *);
-static PyObject *build_class(PyObject *, PyObject *, PyObject *);
-static int exec_statement(PyFrameObject *,
+Py_LOCAL(PyObject *)cmp_outcome(int, PyObject *, PyObject *);
+Py_LOCAL(PyObject *)import_from(PyObject *, PyObject *);
+Py_LOCAL(int) import_all_from(PyObject *, PyObject *);
+Py_LOCAL(PyObject *)build_class(PyObject *, PyObject *, PyObject *);
+Py_LOCAL(int) exec_statement(PyFrameObject *,
 			  PyObject *, PyObject *, PyObject *);
-static void set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
-static void reset_exc_info(PyThreadState *);
-static void format_exc_check_arg(PyObject *, char *, PyObject *);
-static PyObject *string_concatenate(PyObject *, PyObject *,
+Py_LOCAL(void) set_exc_info(PyThreadState *, PyObject *, PyObject *, PyObject *);
+Py_LOCAL(void) reset_exc_info(PyThreadState *);
+Py_LOCAL(void) format_exc_check_arg(PyObject *, char *, PyObject *);
+Py_LOCAL(PyObject *)string_concatenate(PyObject *, PyObject *,
 				    PyFrameObject *, unsigned char *);
 
 #define NAME_ERROR_MSG \
@@ -477,7 +477,7 @@
 };
 
 static enum why_code do_raise(PyObject *, PyObject *, PyObject *);
-static int unpack_iterable(PyObject *, int, PyObject **);
+Py_LOCAL(int) unpack_iterable(PyObject *, int, PyObject **);
 
 /* for manipulating the thread switch and periodic "stuff" - used to be
    per thread, now just a pair o' globals */
@@ -2888,7 +2888,7 @@
 
 */
 
-static void
+Py_LOCAL(void)
 set_exc_info(PyThreadState *tstate,
 	     PyObject *type, PyObject *value, PyObject *tb)
 {
@@ -2933,7 +2933,7 @@
 	PySys_SetObject("exc_traceback", tb);
 }
 
-static void
+Py_LOCAL(void)
 reset_exc_info(PyThreadState *tstate)
 {
 	PyFrameObject *frame;
@@ -3080,7 +3080,7 @@
 /* Iterate v argcnt times and store the results on the stack (via decreasing
    sp).  Return 1 for success, 0 if error. */
 
-static int
+Py_LOCAL(int)
 unpack_iterable(PyObject *v, int argcnt, PyObject **sp)
 {
 	int i = 0;
@@ -3127,7 +3127,7 @@
 
 
 #ifdef LLTRACE
-static int
+Py_LOCAL(int)
 prtrace(PyObject *v, char *str)
 {
 	printf("%s ", str);
@@ -3138,7 +3138,7 @@
 }
 #endif
 
-static void
+Py_LOCAL(void)
 call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
 {
 	PyObject *type, *value, *traceback, *arg;
@@ -3164,7 +3164,7 @@
 	}
 }
 
-static void
+Py_LOCAL(void)
 call_trace_protected(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
 		     int what, PyObject *arg)
 {
@@ -3181,7 +3181,7 @@
 	}
 }
 
-static int
+Py_LOCAL(int)
 call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
 	   int what, PyObject *arg)
 {
@@ -3216,7 +3216,7 @@
 	return result;
 }
 
-static int
+Py_LOCAL(int)
 maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
 		      PyFrameObject *frame, int *instr_lb, int *instr_ub,
 		      int *instr_prev)
@@ -3444,7 +3444,7 @@
 	}
 }
 
-static void
+Py_LOCAL(void)
 err_args(PyObject *func, int flags, int nargs)
 {
 	if (flags & METH_NOARGS)
@@ -3491,7 +3491,7 @@
 	x = call; \
 	}
 
-static PyObject *
+Py_LOCAL(PyObject *)
 call_function(PyObject ***pp_stack, int oparg
 #ifdef WITH_TSC
 		, uint64* pintr0, uint64* pintr1
@@ -3582,7 +3582,7 @@
    done before evaluating the frame.
 */
 
-static PyObject *
+Py_LOCAL(PyObject *)
 fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk)
 {
 	PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
@@ -3635,7 +3635,7 @@
 				 PyFunction_GET_CLOSURE(func));
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 update_keyword_args(PyObject *orig_kwdict, int nk, PyObject ***pp_stack,
                     PyObject *func)
 {
@@ -3675,7 +3675,7 @@
 	return kwdict;
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 update_star_args(int nstack, int nstar, PyObject *stararg,
 		 PyObject ***pp_stack)
 {
@@ -3700,7 +3700,7 @@
 	return callargs;
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 load_args(PyObject ***pp_stack, int na)
 {
 	PyObject *args = PyTuple_New(na);
@@ -3715,7 +3715,7 @@
 	return args;
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 do_call(PyObject *func, PyObject ***pp_stack, int na, int nk)
 {
 	PyObject *callargs = NULL;
@@ -3751,7 +3751,7 @@
 	return result;
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 ext_do_call(PyObject *func, PyObject ***pp_stack, int flags, int na, int nk)
 {
 	int nstar = 0;
@@ -3863,7 +3863,7 @@
                      PyType_HasFeature((x)->ob_type, Py_TPFLAGS_HAVE_INDEX) \
 		     && (x)->ob_type->tp_as_number->nb_index))
 
-static PyObject *
+Py_LOCAL(PyObject *)
 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
 {
 	PyTypeObject *tp = u->ob_type;
@@ -3889,7 +3889,7 @@
 	}
 }
 
-static int
+Py_LOCAL(int)
 assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
 	/* u[v:w] = x */
 {
@@ -3923,7 +3923,7 @@
 	}
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 cmp_outcome(int op, register PyObject *v, register PyObject *w)
 {
 	int res = 0;
@@ -3956,7 +3956,7 @@
 	return v;
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 import_from(PyObject *v, PyObject *name)
 {
 	PyObject *x;
@@ -3970,7 +3970,7 @@
 	return x;
 }
 
-static int
+Py_LOCAL(int)
 import_all_from(PyObject *locals, PyObject *v)
 {
 	PyObject *all = PyObject_GetAttrString(v, "__all__");
@@ -4027,7 +4027,7 @@
 	return err;
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 build_class(PyObject *methods, PyObject *bases, PyObject *name)
 {
 	PyObject *metaclass = NULL, *result, *base;
@@ -4079,7 +4079,7 @@
 	return result;
 }
 
-static int
+Py_LOCAL(int)
 exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
 	       PyObject *locals)
 {
@@ -4175,7 +4175,7 @@
 	return 0;
 }
 
-static void
+Py_LOCAL(void)
 format_exc_check_arg(PyObject *exc, char *format_str, PyObject *obj)
 {
 	char *obj_str;
@@ -4190,7 +4190,7 @@
 	PyErr_Format(exc, format_str, obj_str);
 }
 
-static PyObject *
+Py_LOCAL(PyObject *)
 string_concatenate(PyObject *v, PyObject *w,
 		   PyFrameObject *f, unsigned char *next_instr)
 {
@@ -4265,7 +4265,7 @@
 
 #ifdef DYNAMIC_EXECUTION_PROFILE
 
-static PyObject *
+Py_LOCAL(PyObject *)
 getarray(long a[256])
 {
 	int i;


More information about the Python-checkins mailing list