linux-mips
[Top] [All Lists]

Re: set_bit() function.

To: Steven Liu <stevenliu@psdc.com>
Subject: Re: set_bit() function.
From: Ralf Baechle <ralf@oss.sgi.com>
Date: Tue, 7 Aug 2001 01:36:21 +0200
Cc: linux-mips@oss.sgi.com
In-reply-to: <84CE342693F11946B9F54B18C1AB837B0A21EB@ex2k.pcs.psdc.com>; from stevenliu@psdc.com on Mon, Aug 06, 2001 at 11:04:38AM -0700
References: <84CE342693F11946B9F54B18C1AB837B0A21EB@ex2k.pcs.psdc.com>
Sender: owner-linux-mips@oss.sgi.com
User-agent: Mutt/1.2.5i
On Mon, Aug 06, 2001 at 11:04:38AM -0700, Steven Liu wrote:

> extern __inline__ void set_bit(int nr, void * addr)
> {
>       int     mask;
>       int     *a = addr;
>       __bi_flags;
> 
>       a += nr >> 5;                        // <---- why shits right 5
> bits? 
>       mask = 1 << (nr & 0x1f);
>       __bi_save_flags(flags);
>       __bi_cli();
>       *a |= mask;
>       __bi_restore_flags(flags);
> }
> 
> In
> 
> extern __inline__ int test_bit(int nr, const void *addr)
> {
>       return ((1UL << (nr & 31)) & (((const unsigned int *) addr)[nr
> >> 5])) != 0;
> }
> 
> addr is always passed in as a pointer to an integer. Why does it use
> array [nr >>5]?

Linux bitfields can have an arbitrary size, more than a single machine
word.  Bitfields consist of a arrays of unsigned longs - note that this
makes a difference for 32-bit and 64-bit kernels!.

  Ralf

<Prev in Thread] Current Thread [Next in Thread>