All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][2.6] constant_test_bit doesn't like my gcc
@ 2003-10-16  3:13 Zwane Mwaikambo
  2003-10-16  4:10 ` Andrew Morton
  0 siblings, 1 reply; 8+ messages in thread
From: Zwane Mwaikambo @ 2003-10-16  3:13 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Andrew Morton

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2229 bytes --]

cpu_has_foo and friends don't work at all with my gcc 3.2.2-5 and i'm 
branching off into all sorts of tests (which is another story...). i also 
took the liberty of removing the const volatile...

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --enable-shared --enable-threads=posix 
--disable-checking --with-system-zlib --enable-__cxa_atexit 
--host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

0x08048328 <main+0>:    push   %ebp
0x08048329 <main+1>:    mov    %esp,%ebp
0x0804832b <main+3>:    sub    $0x8,%esp
0x0804832e <main+6>:    mov    0xfffffffc(%ebp),%eax
0x08048331 <main+9>:    and    $0xfffffff0,%esp
0x08048334 <main+12>:   shr    $0x3,%eax
0x08048337 <main+15>:   sub    $0x8,%esp
0x0804833a <main+18>:   and    $0x1,%eax
0x0804833d <main+21>:   push   %eax
0x0804833e <main+22>:   push   $0x8048400
0x08048343 <main+27>:   movl   $0xff,0xfffffffc(%ebp)
0x0804834a <main+34>:   call   0x8048268 <printf>
0x0804834f <main+39>:   xor    %eax,%eax
0x08048351 <main+41>:   leave

Index: linux-2.6.0-test7-mm1/include/asm-i386/bitops.h
===================================================================
RCS file: /build/cvsroot/linux-2.6.0-test7-mm1/include/asm-i386/bitops.h,v
retrieving revision 1.1.1.1
diff -u -p -B -r1.1.1.1 bitops.h
--- linux-2.6.0-test7-mm1/include/asm-i386/bitops.h	15 Oct 2003 09:02:10 -0000	1.1.1.1
+++ linux-2.6.0-test7-mm1/include/asm-i386/bitops.h	16 Oct 2003 03:04:34 -0000
@@ -239,12 +239,12 @@ static __inline__ int test_and_change_bi
 static int test_bit(int nr, const volatile void * addr);
 #endif
 
-static __inline__ int constant_test_bit(int nr, const volatile unsigned long * addr)
+static __inline__ int constant_test_bit(int nr, const unsigned long * addr)
 {
-	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
+	return ((1UL << (nr & 31)) & (((const unsigned long *) addr)[nr >> 5])) != 0;
 }
 
-static __inline__ int variable_test_bit(int nr, const volatile unsigned long * addr)
+static __inline__ int variable_test_bit(int nr, const unsigned long * addr)
 {
 	int oldbit;
 

[-- Attachment #2: Type: TEXT/PLAIN, Size: 368 bytes --]

#include <stdio.h>

static int __inline__ constant_test_bit(int nr, const volatile unsigned long * addr)
{
	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
}

int main()
{
	unsigned long foo[2];
	*foo = 0xff;
	foo[1] = 0xff;

	printf("%d %d\n", constant_test_bit(3, foo), constant_test_bit(33, foo));
	return 0;
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16  3:13 [PATCH][2.6] constant_test_bit doesn't like my gcc Zwane Mwaikambo
@ 2003-10-16  4:10 ` Andrew Morton
  2003-10-16  4:12   ` Zwane Mwaikambo
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2003-10-16  4:10 UTC (permalink / raw)
  To: Zwane Mwaikambo; +Cc: linux-kernel

Zwane Mwaikambo <zwane@arm.linux.org.uk> wrote:
>
>  cpu_has_foo and friends don't work at all with my gcc 3.2.2-5 and i'm 
>  branching off into all sorts of tests (which is another story...). i also 
>  took the liberty of removing the const volatile...

The volatile is rather important.


static inline int constant_test_bit(int nr, const unsigned long *addr)
{
        return ((1UL << (nr & 31)) & (((const unsigned long *) addr)[nr >> 5])) != 0;
}

foo(unsigned long *p)
{
        while (constant_test_bit(0, p))
                ;
}


        .file   "a.c"
        .text
        .align 2
        .p2align 2,,3
.globl foo
        .type   foo,@function
foo:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        testb   $1, (%eax)
        .p2align 2,,3
.L2:
        jne     .L2
        leave
        ret
.Lfe1:
        .size   foo,.Lfe1-foo
        .ident  "GCC: (GNU) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)"


See, the little busywait loop doesn't reevaluate the test each time around:
it locks up instead.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16  4:10 ` Andrew Morton
@ 2003-10-16  4:12   ` Zwane Mwaikambo
  2003-10-16  4:21     ` Andrew Morton
  0 siblings, 1 reply; 8+ messages in thread
From: Zwane Mwaikambo @ 2003-10-16  4:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

On Wed, 15 Oct 2003, Andrew Morton wrote:

> Zwane Mwaikambo <zwane@arm.linux.org.uk> wrote:
> >
> >  cpu_has_foo and friends don't work at all with my gcc 3.2.2-5 and i'm 
> >  branching off into all sorts of tests (which is another story...). i also 
> >  took the liberty of removing the const volatile...
> 
> The volatile is rather important.

Good point, how about;

Index: linux-2.6.0-test7-mm1/include/asm-i386/bitops.h
===================================================================
RCS file: /build/cvsroot/linux-2.6.0-test7-mm1/include/asm-i386/bitops.h,v
retrieving revision 1.1.1.1
diff -u -p -B -r1.1.1.1 bitops.h
--- linux-2.6.0-test7-mm1/include/asm-i386/bitops.h	15 Oct 2003 09:02:10 -0000	1.1.1.1
+++ linux-2.6.0-test7-mm1/include/asm-i386/bitops.h	16 Oct 2003 04:10:37 -0000
@@ -241,7 +241,7 @@ static int test_bit(int nr, const volati
 
 static __inline__ int constant_test_bit(int nr, const volatile unsigned long * addr)
 {
-	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
+	return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
 }
 
 static __inline__ int variable_test_bit(int nr, const volatile unsigned long * addr)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16  4:12   ` Zwane Mwaikambo
@ 2003-10-16  4:21     ` Andrew Morton
  2003-10-16  4:22       ` Zwane Mwaikambo
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2003-10-16  4:21 UTC (permalink / raw)
  To: Zwane Mwaikambo; +Cc: linux-kernel

Zwane Mwaikambo <zwane@arm.linux.org.uk> wrote:
>
>  > The volatile is rather important.
> 
>  Good point, how about;
> 
>  Index: linux-2.6.0-test7-mm1/include/asm-i386/bitops.h
>  ===================================================================
>  RCS file: /build/cvsroot/linux-2.6.0-test7-mm1/include/asm-i386/bitops.h,v
>  retrieving revision 1.1.1.1
>  diff -u -p -B -r1.1.1.1 bitops.h
>  --- linux-2.6.0-test7-mm1/include/asm-i386/bitops.h	15 Oct 2003 09:02:10 -0000	1.1.1.1
>  +++ linux-2.6.0-test7-mm1/include/asm-i386/bitops.h	16 Oct 2003 04:10:37 -0000
>  @@ -241,7 +241,7 @@ static int test_bit(int nr, const volati
>   
>   static __inline__ int constant_test_bit(int nr, const volatile unsigned long * addr)
>   {
>  -	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
>  +	return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
>   }
>  

Looks fine.  Does your compiler get this right? 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16  4:21     ` Andrew Morton
@ 2003-10-16  4:22       ` Zwane Mwaikambo
  2003-10-16 10:55         ` Ingo Oeser
  0 siblings, 1 reply; 8+ messages in thread
From: Zwane Mwaikambo @ 2003-10-16  4:22 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

On Wed, 15 Oct 2003, Andrew Morton wrote:

> >   static __inline__ int constant_test_bit(int nr, const volatile unsigned long * addr)
> >   {
> >  -	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
> >  +	return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
> >   }
> >  
> 
> Looks fine.  Does your compiler get this right? 

Yep, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16  4:22       ` Zwane Mwaikambo
@ 2003-10-16 10:55         ` Ingo Oeser
  2003-10-16 14:55           ` Andrew Morton
  2003-10-16 21:58           ` bill davidsen
  0 siblings, 2 replies; 8+ messages in thread
From: Ingo Oeser @ 2003-10-16 10:55 UTC (permalink / raw)
  To: Zwane Mwaikambo, Andrew Morton; +Cc: linux-kernel

On Thursday 16 October 2003 06:22, Zwane Mwaikambo wrote:
> On Wed, 15 Oct 2003, Andrew Morton wrote:
> > >   static __inline__ int constant_test_bit(int nr, const volatile
> > > unsigned long * addr) {
> > >  -	return ((1UL << (nr & 31)) & (((const volatile unsigned int *)
> > > addr)[nr >> 5])) != 0; +	return ((1UL << (nr & 31)) & (addr[nr >> 5]))
> > > != 0;
> > >   }
> >
> > Looks fine.  Does your compiler get this right?
>
> Yep, thanks.

Sorry, but I still don't get, what a "const volatile" is supposed to mean.

I would be thankful for an explanation (s. Reply-To).

Regards

Ingo Oeser



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16 10:55         ` Ingo Oeser
@ 2003-10-16 14:55           ` Andrew Morton
  2003-10-16 21:58           ` bill davidsen
  1 sibling, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2003-10-16 14:55 UTC (permalink / raw)
  To: Ingo Oeser; +Cc: zwane, linux-kernel

Ingo Oeser <ioe-lkml@rameria.de> wrote:
>
> On Thursday 16 October 2003 06:22, Zwane Mwaikambo wrote:
> > On Wed, 15 Oct 2003, Andrew Morton wrote:
> > > >   static __inline__ int constant_test_bit(int nr, const volatile
> > > > unsigned long * addr) {
> > > >  -	return ((1UL << (nr & 31)) & (((const volatile unsigned int *)
> > > > addr)[nr >> 5])) != 0; +	return ((1UL << (nr & 31)) & (addr[nr >> 5]))
> > > > != 0;
> > > >   }
> > >
> > > Looks fine.  Does your compiler get this right?
> >
> > Yep, thanks.
> 
> Sorry, but I still don't get, what a "const volatile" is supposed to mean.

const: this function doesn't alter it

volatile: someone else does modify it, so the compiler needs to avoid
caching it in a register.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH][2.6] constant_test_bit doesn't like my gcc
  2003-10-16 10:55         ` Ingo Oeser
  2003-10-16 14:55           ` Andrew Morton
@ 2003-10-16 21:58           ` bill davidsen
  1 sibling, 0 replies; 8+ messages in thread
From: bill davidsen @ 2003-10-16 21:58 UTC (permalink / raw)
  To: linux-kernel

In article <200310161255.36380.ioe-lkml@rameria.de>,
Ingo Oeser  <ioe-lkml@rameria.de> asked:

| Sorry, but I still don't get, what a "const volatile" is supposed to mean.

It's a volatile which we're not allowed to change.

The ones which I always have to look at multiple times are the "const
pointer to volatile" and "volatile pointer to const." As in unchanging
pointer to a volatile datum, or a volatile pointer to unchanging data.
-- 
bill davidsen <davidsen@tmr.com>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-10-16 22:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-16  3:13 [PATCH][2.6] constant_test_bit doesn't like my gcc Zwane Mwaikambo
2003-10-16  4:10 ` Andrew Morton
2003-10-16  4:12   ` Zwane Mwaikambo
2003-10-16  4:21     ` Andrew Morton
2003-10-16  4:22       ` Zwane Mwaikambo
2003-10-16 10:55         ` Ingo Oeser
2003-10-16 14:55           ` Andrew Morton
2003-10-16 21:58           ` bill davidsen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.