From: Chuck Ebbert <76306.1226@compuserve.com>
To: Grzegorz Kulewski <kangur@polcom.net>
Cc: "Valdis.Kletnieks" <Valdis.Kletnieks@vt.edu>,
Andrew Morton <akpm@osdl.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Andi Kleen <ak@suse.de>, Ingo Molnar <mingo@redhat.com>,
Linus Torvalds <torvalds@osdl.org>
Subject: Re: set_bit() is broken on i386?
Date: Sat, 21 Jan 2006 15:49:46 -0500 [thread overview]
Message-ID: <200601211553_MC3-1-B65F-A569@compuserve.com> (raw)
In-Reply-To: <Pine.LNX.4.63.0601210245280.8060@alpha.polcom.net>
(Resent because I forgot the cc: list; Grzegorz, please don't
reply to my original.)
On Sat, 21 Jan 2006, Grzegorz Kulewski wrote:
> > On Fri, 20 Jan 2006 19:53:14 EST, Chuck Ebbert said:
> >> /*
> >> * setbit.c -- test the Linux set_bit() function
> >> *
> >> * Compare the output of this program with and without the
> >> * -finline-functions option to GCC.
> >> *
> >> * If they are not the same, set_bit is broken.
I should have said "If they do not both output '00010001' then
set_bit() is broken."
You got:
> gcc-3.4.5 (GCC) 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)
> 00000001
> 00000001
>
> gcc-4.0.2 (GCC) 4.0.2 (Gentoo 4.0.2-r3, pie-8.7.8)
> 00000001
> 00000001
>
> gcc-4.1.0-beta20060113 (GCC) 4.1.0-beta20060113 (prerelease)
> 00000001
> 00000001
>
> gcc (GCC) 3.3.5-20050130 (Gentoo 3.3.5.20050130-r1, ssp-3.3.5.20050130-1,
pie-8.7.7.1)
> 00010001
> 00000001
So the macro is broken even without -finline-functions on all but the
last compiler.
I couldn't break this new program, which assumes 'nr' is a constant:
/*
* setbit2.c -- test an alternate Linux set_bit() function
*
* Compare the output of this program with and without the
* -finline-functions option to GCC.
*
* If they do not both contain two ones, set_bit is broken.
*
* Result on i386 with gcc 4.0.2 (Fedora Core 4):
*
* [me@d2 t]$ gcc -O2 -o setbit2.ex setbit2.c ; ./setbit2.ex
* 0x00010001
* [me@d2 t]$ gcc -O2 -o setbit2.ex -finline-functions setbit2.c ;
./setbit2.ex
* 0x00010001
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#define inline __attribute__((always_inline))
#define LONGBITS (8 * sizeof(unsigned long))
/*
* new set_bit() for testing; assumes nr is a compile-time constant
*/
#define ADDR (*(volatile long *) addr)
static inline void set_bit(int nr, volatile unsigned long * addr)
{
__asm__ __volatile__( "lock ; "
"btsl %2,%1"
:"=m" (*(addr + nr/LONGBITS))
:"m" (*addr),"Ir" (nr),"m" (*(addr + nr/LONGBITS))
);
}
unsigned long a = 1;
unsigned long b[3];
#define WORD 2
int main(int argc, char * const argv[])
{
b[WORD] = a;
set_bit(WORD * LONGBITS + LONGBITS / 2, b);
printf("0x%08x\n", b[WORD]);
return 0;
}
--
Chuck
next reply other threads:[~2006-01-21 20:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-21 20:49 Chuck Ebbert [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-01-21 7:43 Chuck Ebbert
2006-01-21 2:07 Kenny Simpson
2006-01-21 1:46 Kenny Simpson
2006-01-21 1:38 Kenny Simpson
2006-01-21 0:53 Chuck Ebbert
2006-01-21 1:15 ` Trond Myklebust
2006-01-21 1:49 ` Andreas Schwab
2006-01-21 2:38 ` Andrew Morton
2006-01-21 19:26 ` Trond Myklebust
2006-01-21 1:32 ` Valdis.Kletnieks
2006-01-21 2:01 ` Grzegorz Kulewski
2006-01-21 1:48 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200601211553_MC3-1-B65F-A569@compuserve.com \
--to=76306.1226@compuserve.com \
--cc=Valdis.Kletnieks@vt.edu \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=kangur@polcom.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome