File tree 3 files changed +44
-0
lines changed
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,25 @@ complete listing.
111
111
112
112
.. versionadded :: 3.3
113
113
114
+ .. c :macro :: Py_ALWAYS_INLINE
115
+
116
+ Ask the compiler to always inline a static inline function. The compiler can
117
+ ignore it and decides to not inline the function.
118
+
119
+ It can be used to inline performance critical static inline functions when
120
+ building Python in debug mode with function inlining disabled. For example,
121
+ MSC disables function inlining when building in debug mode.
122
+
123
+ Marking blindly a static inline function with Py_ALWAYS_INLINE can result in
124
+ worse performances (due to increased code size for example). The compiler is
125
+ usually smarter than the developer for the cost/benefit analysis.
126
+
127
+ It must be specified before the function return type. Usage::
128
+
129
+ static inline Py_ALWAYS_INLINE int random(void) { return 4; }
130
+
131
+ .. versionadded :: 3.11
132
+
114
133
.. c :macro :: Py_CHARMASK(c)
115
134
116
135
Argument must be a character or an integer in the range [-128, 127] or [0,
Original file line number Diff line number Diff line change @@ -557,6 +557,28 @@ extern "C" {
557
557
#define _Py_HOT_FUNCTION
558
558
#endif
559
559
560
+ // Ask the compiler to always inline a static inline function. The compiler can
561
+ // ignore it and decides to not inline the function.
562
+ //
563
+ // It can be used to inline performance critical static inline functions when
564
+ // building Python in debug mode with function inlining disabled. For example,
565
+ // MSC disables function inlining when building in debug mode.
566
+ //
567
+ // Marking blindly a static inline function with Py_ALWAYS_INLINE can result in
568
+ // worse performances (due to increased code size for example). The compiler is
569
+ // usually smarter than the developer for the cost/benefit analysis.
570
+ //
571
+ // It must be specified before the function return type. Usage:
572
+ //
573
+ // static inline Py_ALWAYS_INLINE int random(void) { return 4; }
574
+ #if defined(__GNUC__ ) || defined(__clang__ ) || defined(__INTEL_COMPILER )
575
+ # define Py_ALWAYS_INLINE __attribute__((always_inline))
576
+ #elif defined(_MSC_VER )
577
+ # define Py_ALWAYS_INLINE __forceinline
578
+ #else
579
+ # define Py_ALWAYS_INLINE
580
+ #endif
581
+
560
582
// Py_NO_INLINE
561
583
// Disable inlining on a function. For example, it reduces the C stack
562
584
// consumption: useful on LTO+PGO builds which heavily inline code (see
Original file line number Diff line number Diff line change
1
+ Add the :c:macro: `Py_ALWAYS_INLINE ` macro to ask the compiler to always
2
+ inline a static inline function. The compiler can ignore it and decides to
3
+ not inline the function. Patch by Victor Stinner.
You can’t perform that action at this time.
0 commit comments