Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
* bitops api for set_bit function
@ 2019-07-22  1:30 Wes Edens
  0 siblings, 0 replies; only message in thread
From: Wes Edens @ 2019-07-22  1:30 UTC (permalink / raw)
  To: kernelnewbies

Hi all,

I have been looking at the bitops api for various architectures. I am
curious why some architectures define the 'nr' argument as a signed
int and some architectures define it as an unsigned int. there are
even some architectures (mips, sparc) that mix the prototypes between
atomic and non-atomic functions (set_bit and __set_bit). The x86
architecture uses a long as its 'nr' argument.

the atomic operations documentation gives a prototype of the bit
operations using unsigned int for 'nr'.
(https://elixir.bootlin.com/linux/latest/source/Documentation/core-api/atomic_ops.rst#L451)

i've looked at the commit where the sparc architecture changes from
using signed to unsigned, but the commit message didn't have an
explanation on that part of it.
(https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8a8b836b91aa170a383f2f360b73d3d23160d9d7)

i've dug through the uses of this function and most drivers/kernel
subsystems use this to set bits in a status bitfield where the 'nr'
argument is a #define. it doesn't seem to matter which type the
argument is, but i'm curious why there are different implementations.

asm-generic implementation:
static inline void __set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);

*p  |= mask;
}

sparc implementation:
static inline void set_bit(unsigned long nr, volatile unsigned long *addr)
{
unsigned long *ADDR, mask;

ADDR = ((unsigned long *) addr) + (nr >> 5);
mask = 1 << (nr & 31);

(void) ___set_bit(ADDR, mask);
}

thank you,
wes edens

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22  1:30 bitops api for set_bit function Wes Edens

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox