kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Wes Edens <wes.k.edens@gmail.com>
To: kernelnewbies@kernelnewbies.org
Subject: bitops api for set_bit function
Date: Sun, 21 Jul 2019 21:30:25 -0400	[thread overview]
Message-ID: <CAK4+kRPKnzrW_4b7jgWduse5Sq88SJgwz6vmWiDVcNZjcnEBMA@mail.gmail.com> (raw)

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

                 reply	other threads:[~2019-07-22  1:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=CAK4+kRPKnzrW_4b7jgWduse5Sq88SJgwz6vmWiDVcNZjcnEBMA@mail.gmail.com \
    --to=wes.k.edens@gmail.com \
    --cc=kernelnewbies@kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).