2003-05-31 13:57:38

by Nikita Danilov

[permalink] [raw]
Subject: const from include/asm-i386/byteorder.h

Hello,

include/asm-i386/byteorder.h contains strange __const__'s in function
definitions that have no effect:

static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
static __inline__ __const__ __u16 ___arch__swab16(__u16 x)

What is their meaning?

Nikita.


2003-05-31 18:35:30

by Gianni Tedesco

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

On Sat, 2003-05-31 at 15:10, Nikita Danilov wrote:
> Hello,
>
> include/asm-i386/byteorder.h contains strange __const__'s in function
> definitions that have no effect:
>
> static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
> static __inline__ __const__ __u16 ___arch__swab16(__u16 x)

shouldn't it be __attribute__((const)) to designate a pure function?

--
// Gianni Tedesco (gianni at scaramanga dot co dot uk)
lynx --source http://www.scaramanga.co.uk/gianni-at-ecsc.asc | gpg --import
8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2003-05-31 18:44:01

by William Lee Irwin III

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

On Sat, 2003-05-31 at 15:10, Nikita Danilov wrote:
>> Hello,
>> include/asm-i386/byteorder.h contains strange __const__'s in function
>> definitions that have no effect:
>> static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
>> static __inline__ __const__ __u16 ___arch__swab16(__u16 x)

On Sat, May 31, 2003 at 07:49:53PM +0100, Gianni Tedesco wrote:
> shouldn't it be __attribute__((const)) to designate a pure function?

There is an __attribute__((pure)) IIRC.


-- wli

2003-06-02 11:38:45

by Nikita Danilov

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

William Lee Irwin III writes:
> On Sat, 2003-05-31 at 15:10, Nikita Danilov wrote:
> >> Hello,
> >> include/asm-i386/byteorder.h contains strange __const__'s in function
> >> definitions that have no effect:
> >> static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
> >> static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
>
> On Sat, May 31, 2003 at 07:49:53PM +0100, Gianni Tedesco wrote:
> > shouldn't it be __attribute__((const)) to designate a pure function?
>
> There is an __attribute__((pure)) IIRC.

Gcc info page:

`const'
Many functions do not examine any values except their arguments,
and have no effects except the return value. Basically this is
just slightly more strict class than the `pure' attribute above,
since function is not allowed to read global memory.

So, it seems byte swapping functions should be __attribute__((const))

Here is a patch:

replace obsolete __const__ qualifiers on function return type with
__attribute__((const)).

It also adds missing __attribute__((const)) for
include/asm-i386/byteorder.h:___arch__swab64()

Linus, please apply.

Nikita.
===== include/asm-arm/current.h 1.3 vs edited =====
--- 1.3/include/asm-arm/current.h Sat Dec 28 19:26:45 2002
+++ edited/include/asm-arm/current.h Mon Jun 2 14:44:24 2003
@@ -3,7 +3,7 @@

#include <linux/thread_info.h>

-static inline struct task_struct *get_current(void) __attribute__ (( __const__ ));
+static inline struct task_struct *get_current(void) __attribute_const;

static inline struct task_struct *get_current(void)
{
===== include/asm-arm/thread_info.h 1.6 vs edited =====
--- 1.6/include/asm-arm/thread_info.h Sat Dec 28 19:26:45 2002
+++ edited/include/asm-arm/thread_info.h Mon Jun 2 14:44:24 2003
@@ -74,7 +74,7 @@
/*
* how to get the thread information struct from C
*/
-static inline struct thread_info *current_thread_info(void) __attribute__ (( __const__ ));
+static inline struct thread_info *current_thread_info(void) __attribute_const;

static inline struct thread_info *current_thread_info(void)
{
===== include/asm-cris/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-cris/byteorder.h Tue Feb 5 20:56:43 2002
+++ edited/include/asm-cris/byteorder.h Mon Jun 2 14:44:24 2003
@@ -12,14 +12,14 @@
* them together into ntohl etc.
*/

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 x)
{
__asm__ ("swapwb %0" : "=r" (x) : "0" (x));

return(x);
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 x)
{
__asm__ ("swapb %0" : "=r" (x) : "0" (x));

===== include/asm-i386/byteorder.h 1.2 vs edited =====
--- 1.2/include/asm-i386/byteorder.h Fri Oct 11 21:15:35 2002
+++ edited/include/asm-i386/byteorder.h Mon Jun 2 14:40:24 2003
@@ -8,9 +8,10 @@
/* For avoiding bswap on i386 */
#ifdef __KERNEL__
#include <linux/config.h>
+#include <linux/compiler.h>
#endif

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 x)
{
#ifdef CONFIG_X86_BSWAP
__asm__("bswap %0" : "=r" (x) : "0" (x));
@@ -26,7 +27,7 @@

/* gcc should generate this for open coded C now too. May be worth switching to
it because inline assembly cannot be scheduled. -AK */
-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 x)
{
__asm__("xchgb %b0,%h0" /* swap bytes */
: "=q" (x)
@@ -35,7 +36,7 @@
}


-static inline __u64 ___arch__swab64(__u64 val)
+static inline __attribute_const __u64 ___arch__swab64(__u64 val)
{
union {
struct { __u32 a,b; } s;
===== include/asm-ia64/byteorder.h 1.2 vs edited =====
--- 1.2/include/asm-ia64/byteorder.h Tue Feb 5 10:39:14 2002
+++ edited/include/asm-ia64/byteorder.h Mon Jun 2 14:44:24 2003
@@ -8,7 +8,7 @@

#include <asm/types.h>

-static __inline__ __const__ __u64
+static __inline__ __attribute_const __u64
__ia64_swab64 (__u64 x)
{
__u64 result;
@@ -17,13 +17,13 @@
return result;
}

-static __inline__ __const__ __u32
+static __inline__ __attribute_const __u32
__ia64_swab32 (__u32 x)
{
return __ia64_swab64(x) >> 32;
}

-static __inline__ __const__ __u16
+static __inline__ __attribute_const __u16
__ia64_swab16(__u16 x)
{
return __ia64_swab64(x) >> 48;
===== include/asm-m68k/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-m68k/byteorder.h Tue Feb 5 20:39:46 2002
+++ edited/include/asm-m68k/byteorder.h Mon Jun 2 14:44:24 2003
@@ -5,7 +5,7 @@

#ifdef __GNUC__

-static __inline__ __const__ __u32 ___arch__swab32(__u32 val)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 val)
{
__asm__("rolw #8,%0; swap %0; rolw #8,%0" : "=d" (val) : "0" (val));
return val;
===== include/asm-parisc/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-parisc/byteorder.h Tue Feb 5 20:39:57 2002
+++ edited/include/asm-parisc/byteorder.h Mon Jun 2 14:44:24 2003
@@ -5,7 +5,7 @@

#ifdef __GNUC__

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 x)
{
unsigned int temp;
__asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab */
@@ -28,7 +28,7 @@
** HSHR 67452301 -> *6*4*2*0 into %0
** OR %0 | %1 -> 76543210 into %0 (all done!)
*/
-static __inline__ __const__ __u64 ___arch__swab64(__u64 x) {
+static __inline__ __attribute_const __u64 ___arch__swab64(__u64 x) {
__u64 temp;
__asm__("permh 3210, %0, %0\n\t"
"hshl %0, 8, %1\n\t"
@@ -40,7 +40,7 @@
}
#define __arch__swab64(x) ___arch__swab64(x)
#else
-static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
+static __inline__ __attribute_const __u64 ___arch__swab64(__u64 x)
{
__u32 t1 = (__u32) x;
__u32 t2 = (__u32) ((x) >> 32);
@@ -51,7 +51,7 @@
#endif


-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 x)
{
__asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */
"shd %r0, %0, 8, %0" /* shift 000000ab -> 00ba */
===== include/asm-ppc/byteorder.h 1.5 vs edited =====
--- 1.5/include/asm-ppc/byteorder.h Mon Sep 16 08:52:03 2002
+++ edited/include/asm-ppc/byteorder.h Mon Jun 2 14:44:24 2003
@@ -32,7 +32,7 @@
__asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 value)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 value)
{
__u16 result;

@@ -40,7 +40,7 @@
return result;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 value)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 value)
{
__u32 result;

===== include/asm-ppc64/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-ppc64/byteorder.h Thu Feb 14 15:14:36 2002
+++ edited/include/asm-ppc64/byteorder.h Mon Jun 2 14:44:24 2003
@@ -40,7 +40,7 @@
}

#if 0
-static __inline__ __const__ __u16 ___arch__swab16(__u16 value)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 value)
{
__u16 result;

@@ -50,7 +50,7 @@
return result;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 value)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 value)
{
__u32 result;

@@ -62,7 +62,7 @@
return result;
}

-static __inline__ __const__ __u64 ___arch__swab64(__u64 value)
+static __inline__ __attribute_const __u64 ___arch__swab64(__u64 value)
{
__u64 result;
#error implement me
===== include/asm-s390/byteorder.h 1.4 vs edited =====
--- 1.4/include/asm-s390/byteorder.h Mon Apr 14 23:11:58 2003
+++ edited/include/asm-s390/byteorder.h Mon Jun 2 14:44:24 2003
@@ -14,7 +14,7 @@
#ifdef __GNUC__

#ifdef __s390x__
-static __inline__ __const__ __u64 ___arch__swab64p(__u64 *x)
+static __inline__ __attribute_const __u64 ___arch__swab64p(__u64 *x)
{
__u64 result;

@@ -24,7 +24,7 @@
return result;
}

-static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
+static __inline__ __attribute_const __u64 ___arch__swab64(__u64 x)
{
__u64 result;

@@ -40,7 +40,7 @@
}
#endif /* __s390x__ */

-static __inline__ __const__ __u32 ___arch__swab32p(__u32 *x)
+static __inline__ __attribute_const __u32 ___arch__swab32p(__u32 *x)
{
__u32 result;

@@ -58,7 +58,7 @@
return result;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 x)
{
#ifndef __s390x__
return ___arch__swab32p(&x);
@@ -77,7 +77,7 @@
*x = ___arch__swab32p(x);
}

-static __inline__ __const__ __u16 ___arch__swab16p(__u16 *x)
+static __inline__ __attribute_const __u16 ___arch__swab16p(__u16 *x)
{
__u16 result;

@@ -93,7 +93,7 @@
return result;
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 x)
{
return ___arch__swab16p(&x);
}
===== include/asm-sh/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-sh/byteorder.h Tue Feb 5 20:39:53 2002
+++ edited/include/asm-sh/byteorder.h Mon Jun 2 14:44:24 2003
@@ -7,7 +7,7 @@

#include <asm/types.h>

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 x)
{
__asm__("swap.b %0, %0\n\t"
"swap.w %0, %0\n\t"
@@ -17,7 +17,7 @@
return x;
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __attribute_const __u16 ___arch__swab16(__u16 x)
{
__asm__("swap.b %0, %0"
: "=r" (x)
===== include/asm-v850/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-v850/byteorder.h Fri Nov 1 19:38:12 2002
+++ edited/include/asm-v850/byteorder.h Mon Jun 2 14:44:24 2003
@@ -18,14 +18,14 @@

#ifdef __GNUC__

-static __inline__ __const__ __u32 ___arch__swab32 (__u32 word)
+static __inline__ __attribute_const __u32 ___arch__swab32 (__u32 word)
{
__u32 res;
__asm__ ("bsw %1, %0" : "=r" (res) : "r" (word));
return res;
}

-static __inline__ __const__ __u16 ___arch__swab16 (__u16 half_word)
+static __inline__ __attribute_const __u16 ___arch__swab16 (__u16 half_word)
{
__u16 res;
__asm__ ("bsh %1, %0" : "=r" (res) : "r" (half_word));
===== include/asm-x86_64/byteorder.h 1.2 vs edited =====
--- 1.2/include/asm-x86_64/byteorder.h Fri Apr 4 02:51:08 2003
+++ edited/include/asm-x86_64/byteorder.h Mon Jun 2 14:44:24 2003
@@ -5,13 +5,13 @@

#ifdef __GNUC__

-static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
+static __inline__ __attribute_const __u64 ___arch__swab64(__u64 x)
{
__asm__("bswapq %0" : "=r" (x) : "0" (x));
return x;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __attribute_const __u32 ___arch__swab32(__u32 x)
{
__asm__("bswapl %0" : "=r" (x) : "0" (x));
return x;
===== include/linux/compiler.h 1.15 vs edited =====
--- 1.15/include/linux/compiler.h Wed Apr 9 22:15:46 2003
+++ edited/include/linux/compiler.h Mon Jun 2 14:44:18 2003
@@ -56,6 +56,22 @@
#define __attribute_used__ __attribute__((__unused__))
#endif

+/* The attribute `pure' is not implemented in GCC versions earlier than 2.96. */
+#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+#define __attribute_pure __attribute__ ((__pure__))
+#else
+#define __attribute_pure
+#endif
+
+/* The attribute `const' is not implemented in GCC versions earlier than 2.5. */
+/* Basically this is just slightly more strict class than the `pure'
+ attribute */
+#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)
+#define __attribute_const __attribute__ ((__const__))
+#else
+#define __attribute_const
+#endif
+
/* This macro obfuscates arithmetic on a variable address so that gcc
shouldn't recognize the original var, and make assumptions about it */
#define RELOC_HIDE(ptr, off) \
===== include/linux/byteorder/swab.h 1.2 vs edited =====
--- 1.2/include/linux/byteorder/swab.h Tue Feb 5 10:43:00 2002
+++ edited/include/linux/byteorder/swab.h Fri May 30 17:34:25 2003
@@ -128,7 +128,7 @@
#endif /* OPTIMIZE */


-static __inline__ __const__ __u16 __fswab16(__u16 x)
+static __inline__ __attribute_const __u16 __fswab16(__u16 x)
{
return __arch__swab16(x);
}
@@ -141,7 +141,7 @@
__arch__swab16s(addr);
}

-static __inline__ __const__ __u32 __fswab32(__u32 x)
+static __inline__ __attribute_const __u32 __fswab32(__u32 x)
{
return __arch__swab32(x);
}
@@ -155,7 +155,7 @@
}

#ifdef __BYTEORDER_HAS_U64__
-static __inline__ __const__ __u64 __fswab64(__u64 x)
+static __inline__ __attribute_const __u64 __fswab64(__u64 x)
{
# ifdef __SWAB_64_THRU_32__
__u32 h = x >> 32;
===== include/linux/byteorder/swabb.h 1.2 vs edited =====
--- 1.2/include/linux/byteorder/swabb.h Tue Feb 5 10:43:00 2002
+++ edited/include/linux/byteorder/swabb.h Mon Jun 2 14:44:24 2003
@@ -92,7 +92,7 @@
#endif /* OPTIMIZE */


-static __inline__ __const__ __u32 __fswahw32(__u32 x)
+static __inline__ __attribute_const __u32 __fswahw32(__u32 x)
{
return __arch__swahw32(x);
}
@@ -106,7 +106,7 @@
}


-static __inline__ __const__ __u32 __fswahb32(__u32 x)
+static __inline__ __attribute_const __u32 __fswahb32(__u32 x)
{
return __arch__swahb32(x);
}

2003-06-02 12:02:14

by William Lee Irwin III

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

On Mon, Jun 02, 2003 at 03:51:39PM +0400, Nikita Danilov wrote:
> Gcc info page:
> `const'
> Many functions do not examine any values except their arguments,
> and have no effects except the return value. Basically this is
> just slightly more strict class than the `pure' attribute above,
> since function is not allowed to read global memory.
> So, it seems byte swapping functions should be __attribute__((const))
> Here is a patch:

I'm very skeptical, in particular, about these hunks:


On Mon, Jun 02, 2003 at 03:51:39PM +0400, Nikita Danilov wrote:
> #include <linux/thread_info.h>
> -static inline struct task_struct *get_current(void) __attribute__ (( __const__ ));
> +static inline struct task_struct *get_current(void) __attribute_const;
> static inline struct task_struct *get_current(void)
> {
> ===== include/asm-arm/thread_info.h 1.6 vs edited =====
> --- 1.6/include/asm-arm/thread_info.h Sat Dec 28 19:26:45 2002
> +++ edited/include/asm-arm/thread_info.h Mon Jun 2 14:44:24 2003
> @@ -74,7 +74,7 @@
> /*
> * how to get the thread information struct from C
> */
> -static inline struct thread_info *current_thread_info(void) __attribute__ (( __const__ ));
> +static inline struct thread_info *current_thread_info(void) __attribute_const;
>
> static inline struct thread_info *current_thread_info(void)
> {

Someone needs to doublecheck whether this actually works. Last I heard,
it did not, but that could have changed since. It vaguely appears some
assumption about it working was made recently since __const__ was there.


-- wli

2003-06-02 12:22:56

by Nikita Danilov

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

William Lee Irwin III writes:
> On Mon, Jun 02, 2003 at 03:51:39PM +0400, Nikita Danilov wrote:
> > Gcc info page:
> > `const'
> > Many functions do not examine any values except their arguments,
> > and have no effects except the return value. Basically this is
> > just slightly more strict class than the `pure' attribute above,
> > since function is not allowed to read global memory.
> > So, it seems byte swapping functions should be __attribute__((const))
> > Here is a patch:
>
> I'm very skeptical, in particular, about these hunks:
>
>
> On Mon, Jun 02, 2003 at 03:51:39PM +0400, Nikita Danilov wrote:
> > #include <linux/thread_info.h>
> > -static inline struct task_struct *get_current(void) __attribute__ (( __const__ ));
> > +static inline struct task_struct *get_current(void) __attribute_const;
> > static inline struct task_struct *get_current(void)
> > {
> > ===== include/asm-arm/thread_info.h 1.6 vs edited =====
> > --- 1.6/include/asm-arm/thread_info.h Sat Dec 28 19:26:45 2002
> > +++ edited/include/asm-arm/thread_info.h Mon Jun 2 14:44:24 2003
> > @@ -74,7 +74,7 @@
> > /*
> > * how to get the thread information struct from C
> > */
> > -static inline struct thread_info *current_thread_info(void) __attribute__ (( __const__ ));
> > +static inline struct thread_info *current_thread_info(void) __attribute_const;
> >
> > static inline struct thread_info *current_thread_info(void)
> > {
>
> Someone needs to doublecheck whether this actually works. Last I heard,

I don't quite understand. __attribute_const is defined as

#define __attribute_const __attribute__ ((__const__))

so, after preprocessing prototypes of get_current() and
current_thread_info() will be the same as before patch, modulo spacing.

> it did not, but that could have changed since. It vaguely appears some
> assumption about it working was made recently since __const__ was there.
>

I am currently running ./fsstress -p 111 on patched kernel on 2*XEON
2.20GHz with hyper threading.

>
> -- wli

Nikita.

2003-06-02 12:28:00

by William Lee Irwin III

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

William Lee Irwin III writes:
>> Someone needs to doublecheck whether this actually works. Last I heard,

On Mon, Jun 02, 2003 at 04:36:18PM +0400, Nikita Danilov wrote:
> I don't quite understand. __attribute_const is defined as
> #define __attribute_const __attribute__ ((__const__))
> so, after preprocessing prototypes of get_current() and
> current_thread_info() will be the same as before patch, modulo spacing.

William Lee Irwin III writes:
>> it did not, but that could have changed since. It vaguely appears some
>> assumption about it working was made recently since __const__ was there.

On Mon, Jun 02, 2003 at 04:36:18PM +0400, Nikita Danilov wrote:
> I am currently running ./fsstress -p 111 on patched kernel on 2*XEON
> 2.20GHz with hyper threading.

Sounds good. If you could doublecheck the assembly to make sure it's
doing the right thing, that would be good, too.

Thanks.

-- wli

2003-06-02 12:45:50

by Nikita Danilov

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

William Lee Irwin III writes:

[...]

>
> Sounds good. If you could doublecheck the assembly to make sure it's
> doing the right thing, that would be good, too.

I have neither ARM hardware nor knowledge of their assembly. Maybe
someone from ARM development team will help.

>
> Thanks.
>
> -- wli

2003-06-02 12:55:27

by William Lee Irwin III

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

William Lee Irwin III writes:
>> Sounds good. If you could doublecheck the assembly to make sure it's
>> doing the right thing, that would be good, too.

On Mon, Jun 02, 2003 at 04:59:13PM +0400, Nikita Danilov wrote:
> I have neither ARM hardware nor knowledge of their assembly. Maybe
> someone from ARM development team will help.

I'd say that i386 is the only one needing direct auditing, the others
can differ if they discover it's problematic. But I think your stress
testing should be enough; if there's a problem it should come up rather
quickly, as context switching is very fundamental and the only thing
that could violate the assumptions given to the compiler, and when
broken it's very obvious _something_ is broken.

As I had heard it, this broke rather blatantly. If it's passing tests
then the issues I had heard of are not happening.


-- wli

2003-06-02 13:06:52

by Gianni Tedesco

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

On Mon, 2003-06-02 at 12:51, Nikita Danilov wrote:
> ===== include/linux/compiler.h 1.15 vs edited =====
> --- 1.15/include/linux/compiler.h Wed Apr 9 22:15:46 2003
> +++ edited/include/linux/compiler.h Mon Jun 2 14:44:18 2003
> @@ -56,6 +56,22 @@
> #define __attribute_used__ __attribute__((__unused__))
> #endif
>
> +/* The attribute `pure' is not implemented in GCC versions earlier than 2.96. */
> +#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
> +#define __attribute_pure __attribute__ ((__pure__))
> +#else
> +#define __attribute_pure
> +#endif
> +
> +/* The attribute `const' is not implemented in GCC versions earlier than 2.5. */
> +/* Basically this is just slightly more strict class than the `pure'
> + attribute */
> +#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)
> +#define __attribute_const __attribute__ ((__const__))
> +#else
> +#define __attribute_const
> +#endif
> +

I think __const_fn and __pure_fn would be a bit more descriptive and
more readable, even though that would appear to go against convention.
It's just that the 'attribute' bit is space consuming and doesn't say
much...

Just my opinion anyway.

--
// Gianni Tedesco (gianni at scaramanga dot co dot uk)
lynx --source http://www.scaramanga.co.uk/gianni-at-ecsc.asc | gpg --import
8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2003-06-02 13:23:46

by Adrian Bunk

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

On Mon, Jun 02, 2003 at 03:51:39PM +0400, Nikita Danilov wrote:
>...
> --- 1.15/include/linux/compiler.h Wed Apr 9 22:15:46 2003
> +++ edited/include/linux/compiler.h Mon Jun 2 14:44:18 2003
>...
> +/* The attribute `const' is not implemented in GCC versions earlier than 2.5. */
> +/* Basically this is just slightly more strict class than the `pure'
> + attribute */
> +#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)
> +#define __attribute_const __attribute__ ((__const__))
> +#else
> +#define __attribute_const
> +#endif
>...

gcc 2.95 is the oldest compiler supported in kernel 2.5, there's no need
to be compatible with older compilers.

cu
Adrian

--

"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed

2003-06-02 14:33:35

by Nikita Danilov

[permalink] [raw]
Subject: Re: const from include/asm-i386/byteorder.h

Adrian Bunk writes:

[...]

>
> gcc 2.95 is the oldest compiler supported in kernel 2.5, there's no need
> to be compatible with older compilers.

Here is new version.

Nikita.
===== include/asm-arm/current.h 1.3 vs edited =====
--- 1.3/include/asm-arm/current.h Sat Dec 28 19:26:45 2002
+++ edited/include/asm-arm/current.h Mon Jun 2 18:32:12 2003
@@ -2,8 +2,9 @@
#define _ASMARM_CURRENT_H

#include <linux/thread_info.h>
+#include <linux/compiler.h>

-static inline struct task_struct *get_current(void) __attribute__ (( __const__ ));
+static inline struct task_struct *get_current(void) __const_fn;

static inline struct task_struct *get_current(void)
{
===== include/asm-arm/thread_info.h 1.6 vs edited =====
--- 1.6/include/asm-arm/thread_info.h Sat Dec 28 19:26:45 2002
+++ edited/include/asm-arm/thread_info.h Mon Jun 2 18:32:11 2003
@@ -22,6 +22,8 @@
#include <asm/ptrace.h>
#include <asm/types.h>

+#include <linux/compiler.h>
+
typedef unsigned long mm_segment_t;

struct cpu_context_save {
@@ -74,7 +76,7 @@
/*
* how to get the thread information struct from C
*/
-static inline struct thread_info *current_thread_info(void) __attribute__ (( __const__ ));
+static inline struct thread_info *current_thread_info(void) __const_fn;

static inline struct thread_info *current_thread_info(void)
{
===== include/asm-cris/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-cris/byteorder.h Tue Feb 5 20:56:43 2002
+++ edited/include/asm-cris/byteorder.h Mon Jun 2 18:32:12 2003
@@ -7,19 +7,21 @@

#ifdef __GNUC__

+#include <linux/compiler.h>
+
/* we just define these two (as we can do the swap in a single
* asm instruction in CRIS) and the arch-independent files will put
* them together into ntohl etc.
*/

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 x)
{
__asm__ ("swapwb %0" : "=r" (x) : "0" (x));

return(x);
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 x)
{
__asm__ ("swapb %0" : "=r" (x) : "0" (x));

===== include/asm-i386/byteorder.h 1.2 vs edited =====
--- 1.2/include/asm-i386/byteorder.h Fri Oct 11 21:15:35 2002
+++ edited/include/asm-i386/byteorder.h Mon Jun 2 18:31:33 2003
@@ -10,7 +10,9 @@
#include <linux/config.h>
#endif

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+#include <linux/compiler.h>
+
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 x)
{
#ifdef CONFIG_X86_BSWAP
__asm__("bswap %0" : "=r" (x) : "0" (x));
@@ -26,7 +28,7 @@

/* gcc should generate this for open coded C now too. May be worth switching to
it because inline assembly cannot be scheduled. -AK */
-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 x)
{
__asm__("xchgb %b0,%h0" /* swap bytes */
: "=q" (x)
@@ -35,7 +37,7 @@
}


-static inline __u64 ___arch__swab64(__u64 val)
+static inline __const_fn __u64 ___arch__swab64(__u64 val)
{
union {
struct { __u32 a,b; } s;
===== include/asm-ia64/byteorder.h 1.2 vs edited =====
--- 1.2/include/asm-ia64/byteorder.h Tue Feb 5 10:39:14 2002
+++ edited/include/asm-ia64/byteorder.h Mon Jun 2 18:32:12 2003
@@ -7,8 +7,9 @@
*/

#include <asm/types.h>
+#include <linux/compiler.h>

-static __inline__ __const__ __u64
+static __inline__ __const_fn __u64
__ia64_swab64 (__u64 x)
{
__u64 result;
@@ -17,13 +18,13 @@
return result;
}

-static __inline__ __const__ __u32
+static __inline__ __const_fn __u32
__ia64_swab32 (__u32 x)
{
return __ia64_swab64(x) >> 32;
}

-static __inline__ __const__ __u16
+static __inline__ __const_fn __u16
__ia64_swab16(__u16 x)
{
return __ia64_swab64(x) >> 48;
===== include/asm-m68k/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-m68k/byteorder.h Tue Feb 5 20:39:46 2002
+++ edited/include/asm-m68k/byteorder.h Mon Jun 2 18:32:12 2003
@@ -5,7 +5,9 @@

#ifdef __GNUC__

-static __inline__ __const__ __u32 ___arch__swab32(__u32 val)
+#include <linux/compiler.h>
+
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 val)
{
__asm__("rolw #8,%0; swap %0; rolw #8,%0" : "=d" (val) : "0" (val));
return val;
===== include/asm-parisc/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-parisc/byteorder.h Tue Feb 5 20:39:57 2002
+++ edited/include/asm-parisc/byteorder.h Mon Jun 2 18:32:12 2003
@@ -5,7 +5,9 @@

#ifdef __GNUC__

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+#include <linux/compiler.h>
+
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 x)
{
unsigned int temp;
__asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab */
@@ -28,7 +30,7 @@
** HSHR 67452301 -> *6*4*2*0 into %0
** OR %0 | %1 -> 76543210 into %0 (all done!)
*/
-static __inline__ __const__ __u64 ___arch__swab64(__u64 x) {
+static __inline__ __const_fn __u64 ___arch__swab64(__u64 x) {
__u64 temp;
__asm__("permh 3210, %0, %0\n\t"
"hshl %0, 8, %1\n\t"
@@ -40,7 +42,7 @@
}
#define __arch__swab64(x) ___arch__swab64(x)
#else
-static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
+static __inline__ __const_fn __u64 ___arch__swab64(__u64 x)
{
__u32 t1 = (__u32) x;
__u32 t2 = (__u32) ((x) >> 32);
@@ -51,7 +53,7 @@
#endif


-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 x)
{
__asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */
"shd %r0, %0, 8, %0" /* shift 000000ab -> 00ba */
===== include/asm-ppc/byteorder.h 1.5 vs edited =====
--- 1.5/include/asm-ppc/byteorder.h Mon Sep 16 08:52:03 2002
+++ edited/include/asm-ppc/byteorder.h Mon Jun 2 18:30:27 2003
@@ -4,8 +4,11 @@
#include <asm/types.h>

#ifdef __GNUC__
+
#ifdef __KERNEL__

+#include <linux/compiler.h>
+
extern __inline__ unsigned ld_le16(const volatile unsigned short *addr)
{
unsigned val;
@@ -32,7 +35,7 @@
__asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 value)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 value)
{
__u16 result;

@@ -40,7 +43,7 @@
return result;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 value)
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 value)
{
__u32 result;

===== include/asm-ppc64/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-ppc64/byteorder.h Thu Feb 14 15:14:36 2002
+++ edited/include/asm-ppc64/byteorder.h Mon Jun 2 18:32:12 2003
@@ -13,6 +13,8 @@
#ifdef __GNUC__
#ifdef __KERNEL__

+#include <linux/compiler.h>
+
static __inline__ __u16 ld_le16(const volatile __u16 *addr)
{
__u16 val;
@@ -40,7 +42,7 @@
}

#if 0
-static __inline__ __const__ __u16 ___arch__swab16(__u16 value)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 value)
{
__u16 result;

@@ -50,7 +52,7 @@
return result;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 value)
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 value)
{
__u32 result;

@@ -62,7 +64,7 @@
return result;
}

-static __inline__ __const__ __u64 ___arch__swab64(__u64 value)
+static __inline__ __const_fn __u64 ___arch__swab64(__u64 value)
{
__u64 result;
#error implement me
===== include/asm-s390/byteorder.h 1.4 vs edited =====
--- 1.4/include/asm-s390/byteorder.h Mon Apr 14 23:11:58 2003
+++ edited/include/asm-s390/byteorder.h Mon Jun 2 18:32:12 2003
@@ -13,8 +13,10 @@

#ifdef __GNUC__

+#include <linux/compiler.h>
+
#ifdef __s390x__
-static __inline__ __const__ __u64 ___arch__swab64p(__u64 *x)
+static __inline__ __const_fn __u64 ___arch__swab64p(__u64 *x)
{
__u64 result;

@@ -24,7 +26,7 @@
return result;
}

-static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
+static __inline__ __const_fn __u64 ___arch__swab64(__u64 x)
{
__u64 result;

@@ -40,7 +42,7 @@
}
#endif /* __s390x__ */

-static __inline__ __const__ __u32 ___arch__swab32p(__u32 *x)
+static __inline__ __const_fn __u32 ___arch__swab32p(__u32 *x)
{
__u32 result;

@@ -58,7 +60,7 @@
return result;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 x)
{
#ifndef __s390x__
return ___arch__swab32p(&x);
@@ -77,7 +79,7 @@
*x = ___arch__swab32p(x);
}

-static __inline__ __const__ __u16 ___arch__swab16p(__u16 *x)
+static __inline__ __const_fn __u16 ___arch__swab16p(__u16 *x)
{
__u16 result;

@@ -93,7 +95,7 @@
return result;
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 x)
{
return ___arch__swab16p(&x);
}
===== include/asm-sh/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-sh/byteorder.h Tue Feb 5 20:39:53 2002
+++ edited/include/asm-sh/byteorder.h Mon Jun 2 18:32:12 2003
@@ -6,8 +6,9 @@
*/

#include <asm/types.h>
+#include <linux/compiler.h>

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 x)
{
__asm__("swap.b %0, %0\n\t"
"swap.w %0, %0\n\t"
@@ -17,7 +18,7 @@
return x;
}

-static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
+static __inline__ __const_fn __u16 ___arch__swab16(__u16 x)
{
__asm__("swap.b %0, %0"
: "=r" (x)
===== include/asm-v850/byteorder.h 1.1 vs edited =====
--- 1.1/include/asm-v850/byteorder.h Fri Nov 1 19:38:12 2002
+++ edited/include/asm-v850/byteorder.h Mon Jun 2 18:32:12 2003
@@ -18,14 +18,16 @@

#ifdef __GNUC__

-static __inline__ __const__ __u32 ___arch__swab32 (__u32 word)
+#include <linux/compiler.h>
+
+static __inline__ __const_fn __u32 ___arch__swab32 (__u32 word)
{
__u32 res;
__asm__ ("bsw %1, %0" : "=r" (res) : "r" (word));
return res;
}

-static __inline__ __const__ __u16 ___arch__swab16 (__u16 half_word)
+static __inline__ __const_fn __u16 ___arch__swab16 (__u16 half_word)
{
__u16 res;
__asm__ ("bsh %1, %0" : "=r" (res) : "r" (half_word));
===== include/asm-x86_64/byteorder.h 1.2 vs edited =====
--- 1.2/include/asm-x86_64/byteorder.h Fri Apr 4 02:51:08 2003
+++ edited/include/asm-x86_64/byteorder.h Mon Jun 2 18:32:12 2003
@@ -5,13 +5,15 @@

#ifdef __GNUC__

-static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
+#include <linux/compiler.h>
+
+static __inline__ __const_fn __u64 ___arch__swab64(__u64 x)
{
__asm__("bswapq %0" : "=r" (x) : "0" (x));
return x;
}

-static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
+static __inline__ __const_fn __u32 ___arch__swab32(__u32 x)
{
__asm__("bswapl %0" : "=r" (x) : "0" (x));
return x;
===== include/linux/compiler.h 1.15 vs edited =====
--- 1.15/include/linux/compiler.h Wed Apr 9 22:15:46 2003
+++ edited/include/linux/compiler.h Mon Jun 2 18:11:06 2003
@@ -56,6 +56,19 @@
#define __attribute_used__ __attribute__((__unused__))
#endif

+/* The attribute `pure' is not implemented in GCC versions earlier than 2.96. */
+#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
+#define __pure_fn __attribute__ ((__pure__))
+#else
+#define __pure_fn
+#endif
+
+/* The attribute `const' is not implemented in GCC versions earlier than
+ 2.5. We are not interested in elder compilers. */
+/* Basically this is just slightly more strict class than the `pure'
+ attribute */
+#define __const_fn __attribute__ ((__const__))
+
/* This macro obfuscates arithmetic on a variable address so that gcc
shouldn't recognize the original var, and make assumptions about it */
#define RELOC_HIDE(ptr, off) \
===== include/linux/byteorder/swab.h 1.2 vs edited =====
--- 1.2/include/linux/byteorder/swab.h Tue Feb 5 10:43:00 2002
+++ edited/include/linux/byteorder/swab.h Mon Jun 2 18:32:12 2003
@@ -1,6 +1,8 @@
#ifndef _LINUX_BYTEORDER_SWAB_H
#define _LINUX_BYTEORDER_SWAB_H

+#include <linux/compiler.h>
+
/*
* linux/byteorder/swab.h
* Byte-swapping, independently from CPU endianness
@@ -128,7 +130,7 @@
#endif /* OPTIMIZE */


-static __inline__ __const__ __u16 __fswab16(__u16 x)
+static __inline__ __const_fn __u16 __fswab16(__u16 x)
{
return __arch__swab16(x);
}
@@ -141,7 +143,7 @@
__arch__swab16s(addr);
}

-static __inline__ __const__ __u32 __fswab32(__u32 x)
+static __inline__ __const_fn __u32 __fswab32(__u32 x)
{
return __arch__swab32(x);
}
@@ -155,7 +157,7 @@
}

#ifdef __BYTEORDER_HAS_U64__
-static __inline__ __const__ __u64 __fswab64(__u64 x)
+static __inline__ __const_fn __u64 __fswab64(__u64 x)
{
# ifdef __SWAB_64_THRU_32__
__u32 h = x >> 32;
===== include/linux/byteorder/swabb.h 1.2 vs edited =====
--- 1.2/include/linux/byteorder/swabb.h Tue Feb 5 10:43:00 2002
+++ edited/include/linux/byteorder/swabb.h Mon Jun 2 18:28:20 2003
@@ -1,6 +1,8 @@
#ifndef _LINUX_BYTEORDER_SWABB_H
#define _LINUX_BYTEORDER_SWABB_H

+#include <linux/compiler.h>
+
/*
* linux/byteorder/swabb.h
* SWAp Bytes Bizarrely
@@ -92,7 +94,7 @@
#endif /* OPTIMIZE */


-static __inline__ __const__ __u32 __fswahw32(__u32 x)
+static __inline__ __const_fn __u32 __fswahw32(__u32 x)
{
return __arch__swahw32(x);
}
@@ -106,7 +108,7 @@
}


-static __inline__ __const__ __u32 __fswahb32(__u32 x)
+static __inline__ __const_fn __u32 __fswahb32(__u32 x)
{
return __arch__swahb32(x);
}