lkml.org 
[lkml]   [2000]   [Sep]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] abuse of macros in swab.h
From
Date
>>>>> " " == Alexander Viro <viro@math.psu.edu> writes:

> Nice spotting, but bad fix, IMO. swab...() stuff is a perfect
> example of the dangerous use of macros. BTW, 2.4 has the same
> problem.

> +static inline __u16 ___swab16(__u16 x) +{

Don't forget that htonl(), ntohl(), and friends are aliased to these
functions. Inlining everything therefore breaks good optimizations
such as __constant_htonl(). The latter is especially useful for 'case'
statements.

Isn't it simpler just to remove the gcc constant folding in swab.h and
swabb.h?

Cheers,
Trond

--- linux/include/linux/byteorder/swab.h.orig Tue Sep 1 19:50:11 1998
+++ linux/include/linux/byteorder/swab.h Wed Sep 20 14:52:02 2000
@@ -73,27 +73,9 @@
#endif


-/*
- * Allow constant folding
- */
-#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)
-# define __swab16(x) \
-(__builtin_constant_p((__u16)(x)) ? \
- ___swab16((x)) : \
- __fswab16((x)))
-# define __swab32(x) \
-(__builtin_constant_p((__u32)(x)) ? \
- ___swab32((x)) : \
- __fswab32((x)))
-# define __swab64(x) \
-(__builtin_constant_p((__u64)(x)) ? \
- ___swab64((x)) : \
- __fswab64((x)))
-#else
# define __swab16(x) __fswab16(x)
# define __swab32(x) __fswab32(x)
# define __swab64(x) __fswab64(x)
-#endif /* OPTIMIZE */


extern __inline__ __const__ __u16 __fswab16(__u16 x)
--- linux/include/linux/byteorder/swabb.h.orig Tue Sep 1 19:50:11 1998
+++ linux/include/linux/byteorder/swabb.h Wed Sep 20 14:52:19 2000
@@ -60,22 +60,8 @@
#endif


-/*
- * Allow constant folding
- */
-#if defined(__GNUC__) && (__GNUC__ >= 2) && defined(__OPTIMIZE__)
-# define __swahw32(x) \
-(__builtin_constant_p((__u32)(x)) ? \
- ___swahw32((x)) : \
- __fswahw32((x)))
-# define __swahb32(x) \
-(__builtin_constant_p((__u32)(x)) ? \
- ___swahb32((x)) : \
- __fswahb32((x)))
-#else
# define __swahw32(x) __fswahw32(x)
# define __swahb32(x) __fswahb32(x)
-#endif /* OPTIMIZE */


extern __inline__ __const__ __u32 __fswahw32(__u32 x)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 12:38    [W:0.295 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site