From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03792C76191 for ; Mon, 22 Jul 2019 01:32:13 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC7D3218C9 for ; Mon, 22 Jul 2019 01:32:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xv5tiztV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC7D3218C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.92) (envelope-from ) id 1hpNB0-0006cC-NR; Sun, 21 Jul 2019 21:31:42 -0400 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1hpNAy-0006c3-JS for kernelnewbies@kernelnewbies.org; Sun, 21 Jul 2019 21:31:40 -0400 Received: by mail-io1-xd44.google.com with SMTP id o9so70461291iom.3 for ; Sun, 21 Jul 2019 18:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=eCcA0TlDRQFawdBtuI/3sPEZCsDs3BvN865hp/kgWTk=; b=Xv5tiztVL0Xu8b2xiyH3e3VMdk90WOpo7tooVlzWwNveS2Rg94eigZvA2dnauTxDDA obOvXO9BA6pGxCnTKJU33sTxRUtSQLs+U0BeOVQPFeUG3qTuei0cza5KdY9RNki1jXay 7x1FfYgmylPXnSLKogyNdTR7bNO+SoM6vn7KdIRnwisH8XyF2VZMPZdJOvk4itTU4WAr BUAUZV6iSPAWPw4kmvGub8m1lSi/+ZBn9Y1f6S5Vda/SQnMYR0yUetHELAR+x90Zp8pE zq9VUpiyZhGjh7mI2u9VnAimN8oA50qIzunYGN9wz9cqCIRvxDF/aMNuQQq5NFiQIxi5 DVxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=eCcA0TlDRQFawdBtuI/3sPEZCsDs3BvN865hp/kgWTk=; b=PGrOVrZshwCjO+d6967nlNc53OqJXuF8lOWhWBof0wRM6WRjyjKmtbBNtGTYnQSdGK dLnOmFoDODegDKY5r4dRgxzpUYcZdHhMt5AXZCSYCEoKTKkuh4FxhPBmut9jPqHWZMok 8dEYQWZ5CG3lvWDf4Vr1d+D6Epm8X7nY3CAeEwbK0gjUEMC5iWcTUAeGD3zjkjE7jDHE rJH0znYoeTNpa789FAqDSYRgxCA3MSZdSYAki/YzwV5b9bsSlolgpnaxJNrYy/q7yM5g aWEaD3RXONDwttT280yOla3jiCpvcE/fQhKlIUfQLNBA47WwkUwa6HOpkx6Ox2HJGs1a wCSg== X-Gm-Message-State: APjAAAVdiOIWoLxxJjuECHs8zBT+yy6jRd5vIF0TXFZgV3swsexGzUsb JV7gclXR3bGdj3QEptFawUtoz0d9XolSNLlaajJptbtS/BA= X-Google-Smtp-Source: APXvYqzKzYW53craO8AQRLvxLDDONEyOPl2cnW+0cKeXFPJ1g1c8nZ0Rf6wSivN9BWaDMkR+4oOCCvrSXvl/TQe6XC0= X-Received: by 2002:a6b:6310:: with SMTP id p16mr63024485iog.118.1563759036537; Sun, 21 Jul 2019 18:30:36 -0700 (PDT) MIME-Version: 1.0 From: Wes Edens Date: Sun, 21 Jul 2019 21:30:25 -0400 Message-ID: Subject: bitops api for set_bit function To: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org 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