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

A.M. Kuchling amk at amk.ca
Sat May 27 14:14:50 CEST 2006


On Sat, May 27, 2006 at 12:39:49PM +0200, fredrik.lundh wrote:
> +/* Py_LOCAL can be used instead of static to get the fastest possible calling
> + * convention for functions that are local to a given module.

I've attached a patch that makes Py_LOCAL use a GCC attribute on x86
that supposedly passes some parameters in registers.  On my machine
the difference seems to be in the noise (sometimes faster, sometimes
slower), but perhaps Fredrik or Andrew would like to try it; they're
probably very good at benchmarking the string types by now.

--amk
-------------- next part --------------
Index: Include/pyport.h
===================================================================
--- Include/pyport.h	(revision 46443)
+++ Include/pyport.h	(working copy)
@@ -157,6 +157,7 @@
 #undef USE_INLINE /* XXX - set via configure? */
 
 #if defined(_MSC_VER)
+/* Platform-specific case: Visual Studio */
 #if defined(PY_LOCAL_AGGRESSIVE)
 /* enable more aggressive optimization for visual studio */
 #pragma optimize("agtw", on)
@@ -166,10 +167,24 @@
 /* fastest possible local call under MSVC */
 #define Py_LOCAL(type) static type __fastcall
 #define Py_LOCAL_INLINE(type) static __inline type __fastcall
+
+#elif defined(__i386__) && defined(__GNUC__)
+/* Platform-specific case: GCC on x86 */
+
+#if defined(USE_INLINE)
+#define Py_LOCAL(type) static type Py_GCC_ATTRIBUTE((regparm(3)))
+#define Py_LOCAL_INLINE(type) static inline type Py_GCC_ATTRIBUTE((regparm(3)))
+#else
+#define Py_LOCAL(type) static type Py_GCC_ATTRIBUTE((regparm(3)))
+#define Py_LOCAL_INLINE(type) static type Py_GCC_ATTRIBUTE((regparm(3)))
+#endif
+
 #elif defined(USE_INLINE)
+/* Generic case: inline is enabled */
 #define Py_LOCAL(type) static type
 #define Py_LOCAL_INLINE(type) static inline type
 #else
+/* Generic case */
 #define Py_LOCAL(type) static type
 #define Py_LOCAL_INLINE(type) static type
 #endif


More information about the Python-checkins mailing list