]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[OPTIM] force inlining of large functions with gcc >= 3
authorWilly Tarreau <w@1wt.eu>
Fri, 29 Aug 2008 13:48:49 +0000 (15:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Sep 2008 09:04:51 +0000 (11:04 +0200)
GCC 3 and above do not inline large functions, which is a problem
with ebtree where most core functions are inlined.

This simple patch has both reduced code size and increased speed.
It should be back-ported to ebtree.
(cherry picked from commit 707d3da01f8475d5c172d347a73bd9e947076df6)

include/common/config.h
include/common/eb32tree.h
include/common/eb64tree.h
include/common/ebpttree.h
include/common/ebtree.h

index 74bee477eb22abd0a460593a85cfd9597c9d4864..5efa7cbb5af6f0637e426d9a93c29ba67011adbf 100644 (file)
 #define REGPRM3
 #endif
 
+/* By default, gcc does not inline large chunks of code, but we want it to
+ * respect our choices.
+ */
+#if !defined(forceinline)
+#if __GNUC__ < 3
+#define forceinline inline
+#else
+#define forceinline inline __attribute__((always_inline))
+#endif
+#endif
+
 #endif /* _COMMON_CONFIG_H */
index f0c79303574306bbec8534d6c92d80bf2507dddb..a326d184abfe6c3245ea7ea81471e5b2248b2e15 100644 (file)
@@ -108,7 +108,7 @@ REGPRM2 struct eb32_node *eb32i_insert(struct eb_root *root, struct eb32_node *n
  */
 
 /* Delete node from the tree if it was linked in. Mark the node unused. */
-static inline void __eb32_delete(struct eb32_node *eb32)
+static forceinline void __eb32_delete(struct eb32_node *eb32)
 {
        __eb_delete(&eb32->node);
 }
@@ -117,7 +117,7 @@ static inline void __eb32_delete(struct eb32_node *eb32)
  * Find the first occurence of a key in the tree <root>. If none can be
  * found, return NULL.
  */
-static inline struct eb32_node *__eb32_lookup(struct eb_root *root, u32 x)
+static forceinline struct eb32_node *__eb32_lookup(struct eb_root *root, u32 x)
 {
        struct eb32_node *node;
        eb_troot_t *troot;
@@ -161,7 +161,7 @@ static inline struct eb32_node *__eb32_lookup(struct eb_root *root, u32 x)
  * Find the first occurence of a signed key in the tree <root>. If none can
  * be found, return NULL.
  */
-static inline struct eb32_node *__eb32i_lookup(struct eb_root *root, s32 x)
+static forceinline struct eb32_node *__eb32i_lookup(struct eb_root *root, s32 x)
 {
        struct eb32_node *node;
        eb_troot_t *troot;
@@ -205,7 +205,7 @@ static inline struct eb32_node *__eb32i_lookup(struct eb_root *root, s32 x)
 /* Insert eb32_node <new> into subtree starting at node root <root>.
  * Only new->key needs be set with the key. The eb32_node is returned.
  */
-static inline struct eb32_node *
+static forceinline struct eb32_node *
 __eb32_insert(struct eb_root *root, struct eb32_node *new) {
        struct eb32_node *old;
        unsigned int side;
@@ -361,7 +361,7 @@ __eb32_insert(struct eb_root *root, struct eb32_node *new) {
  * signed keys. Only new->key needs be set with the key. The eb32_node
  * is returned
  */
-static inline struct eb32_node *
+static forceinline struct eb32_node *
 __eb32i_insert(struct eb_root *root, struct eb32_node *new) {
        struct eb32_node *old;
        unsigned int side;
index 9a069ca53f54bddac34de3fa6d5b57c72ea7c36d..1249c5a76e4e01f369ac70ed70fdcdb8ce559ba5 100644 (file)
@@ -108,7 +108,7 @@ REGPRM2 struct eb64_node *eb64i_insert(struct eb_root *root, struct eb64_node *n
  */
 
 /* Delete node from the tree if it was linked in. Mark the node unused. */
-static inline void __eb64_delete(struct eb64_node *eb64)
+static forceinline void __eb64_delete(struct eb64_node *eb64)
 {
        __eb_delete(&eb64->node);
 }
@@ -117,7 +117,7 @@ static inline void __eb64_delete(struct eb64_node *eb64)
  * Find the first occurence of a key in the tree <root>. If none can be
  * found, return NULL.
  */
-static inline struct eb64_node *__eb64_lookup(struct eb_root *root, u64 x)
+static forceinline struct eb64_node *__eb64_lookup(struct eb_root *root, u64 x)
 {
        struct eb64_node *node;
        eb_troot_t *troot;
@@ -161,7 +161,7 @@ static inline struct eb64_node *__eb64_lookup(struct eb_root *root, u64 x)
  * Find the first occurence of a signed key in the tree <root>. If none can
  * be found, return NULL.
  */
-static inline struct eb64_node *__eb64i_lookup(struct eb_root *root, s64 x)
+static forceinline struct eb64_node *__eb64i_lookup(struct eb_root *root, s64 x)
 {
        struct eb64_node *node;
        eb_troot_t *troot;
@@ -205,7 +205,7 @@ static inline struct eb64_node *__eb64i_lookup(struct eb_root *root, s64 x)
 /* Insert eb64_node <new> into subtree starting at node root <root>.
  * Only new->key needs be set with the key. The eb64_node is returned.
  */
-static inline struct eb64_node *
+static forceinline struct eb64_node *
 __eb64_insert(struct eb_root *root, struct eb64_node *new) {
        struct eb64_node *old;
        unsigned int side;
@@ -371,7 +371,7 @@ __eb64_insert(struct eb_root *root, struct eb64_node *new) {
  * signed keys. Only new->key needs be set with the key. The eb64_node
  * is returned.
  */
-static inline struct eb64_node *
+static forceinline struct eb64_node *
 __eb64i_insert(struct eb_root *root, struct eb64_node *new) {
        struct eb64_node *old;
        unsigned int side;
index be164ad4c8eec1fc22de650552e1d7383ad84929..2ea8539c15c28d15093335e96a6077d5072ab764 100644 (file)
@@ -109,7 +109,7 @@ REGPRM2 struct ebpt_node *ebpt_insert(struct eb_root *root, struct ebpt_node *ne
  */
 
 /* Delete node from the tree if it was linked in. Mark the node unused. */
-static inline void __ebpt_delete(struct ebpt_node *ebpt)
+static forceinline void __ebpt_delete(struct ebpt_node *ebpt)
 {
        __eb_delete(&ebpt->node);
 }
@@ -118,7 +118,7 @@ static inline void __ebpt_delete(struct ebpt_node *ebpt)
  * Find the first occurence of a key in the tree <root>. If none can be
  * found, return NULL.
  */
-static inline struct ebpt_node *__ebpt_lookup(struct eb_root *root, void *x)
+static forceinline struct ebpt_node *__ebpt_lookup(struct eb_root *root, void *x)
 {
        struct ebpt_node *node;
        eb_troot_t *troot;
@@ -161,7 +161,7 @@ static inline struct ebpt_node *__ebpt_lookup(struct eb_root *root, void *x)
 /* Insert ebpt_node <new> into subtree starting at node root <root>.
  * Only new->key needs be set with the key. The ebpt_node is returned.
  */
-static inline struct ebpt_node *
+static forceinline struct ebpt_node *
 __ebpt_insert(struct eb_root *root, struct ebpt_node *new) {
        struct ebpt_node *old;
        unsigned int side;
index 38cd0b533a0734e9923dfcfc0c5c792c00595571..c21f539d2d7382da0bdfb037f3579a5234dec317 100644 (file)
@@ -326,6 +326,17 @@ static inline int fls64(unsigned long long x)
 #endif
 #endif
 
+/* By default, gcc does not inline large chunks of code, but we want it to
+ * respect our choices.
+ */
+#if !defined(forceinline)
+#if __GNUC__ < 3
+#define forceinline inline
+#else
+#define forceinline inline __attribute__((always_inline))
+#endif
+#endif
+
 /* Support passing function parameters in registers. For this, the
  * CONFIG_EBTREE_REGPARM macro has to be set to the maximal number of registers
  * allowed. Some functions have intentionally received a regparm lower than
@@ -473,7 +484,7 @@ static inline struct eb_node *eb_walk_down(eb_troot_t *start, unsigned int side)
  * a subtree of at least 2 entries. It will probably never be needed inlined,
  * and it is not for end-user.
  */
-static inline struct eb_node *
+static forceinline struct eb_node *
 __eb_insert_dup(struct eb_node *sub, struct eb_node *new)
 {
        struct eb_node *head = sub;
@@ -635,7 +646,7 @@ static inline struct eb_node *eb_next_unique(struct eb_node *node)
 /* Removes a leaf node from the tree if it was still in it. Marks the node
  * as unlinked.
  */
-static inline void __eb_delete(struct eb_node *node)
+static forceinline void __eb_delete(struct eb_node *node)
 {
        __label__ delete_unlink;
        unsigned int pside, gpside, sibtype;