From: Martin Kepplinger <martink@posteo.de>
To: mingo@kernel.org, akpm@linux-foundation.org, linux@horizon.com,
linux@rasmusvillemoes.dk, maxime.coquelin@st.com,
dvlasenk@redhat.com, yury.norov@gmail.com,
torvalds@linux-foundation.org
Cc: linux-kernel@vger.kernel.org,
Martin Kepplinger <martink@posteo.de>,
Martin Kepplinger <martin.kepplinger@theobroma-systems.com>
Subject: [PATCH 2/2] bitops.h: add sign_extend64()
Date: Thu, 15 Oct 2015 18:18:29 +0200 [thread overview]
Message-ID: <1444925909-6013-3-git-send-email-martink@posteo.de> (raw)
In-Reply-To: <1444925909-6013-1-git-send-email-martink@posteo.de>
Months back, this was discussed, see https://lkml.org/lkml/2015/1/18/289
The result was the 64-bit version being "likely fine", "valuable" and
"correct". The discussion only fell asleep but since there are possible
users, let's add it.
Signed-off-by: Martin Kepplinger <martin.kepplinger@theobroma-systems.com>
---
include/linux/bitops.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 2177c01..1672b74 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -173,6 +173,17 @@ static inline __s32 sign_extend32(__u32 value, int index)
return (__s32)(value << shift) >> shift;
}
+/**
+ * sign_extend64 - sign extend a 64-bit value using specified bit as sign-bit
+ * @value: value to sign extend
+ * @index: 0 based bit index (0<=index<64) to sign bit
+ */
+static inline __s64 sign_extend64(__u64 value, int index)
+{
+ __u8 shift = 63 - index;
+ return (__s64)(value << shift) >> shift;
+}
+
static inline unsigned fls_long(unsigned long l)
{
if (sizeof(l) == 4)
--
2.1.4
prev parent reply other threads:[~2015-10-15 16:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 16:18 bitops.h: improve sign extending API Martin Kepplinger
2015-10-15 16:18 ` [PATCH 1/2] bitops.h: Improve sign_extend32()'s documentation Martin Kepplinger
2015-10-15 18:06 ` George Spelvin
2015-10-15 16:18 ` Martin Kepplinger [this message]
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=1444925909-6013-3-git-send-email-martink@posteo.de \
--to=martink@posteo.de \
--cc=akpm@linux-foundation.org \
--cc=dvlasenk@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=linux@rasmusvillemoes.dk \
--cc=martin.kepplinger@theobroma-systems.com \
--cc=maxime.coquelin@st.com \
--cc=mingo@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=yury.norov@gmail.com \
/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
all inboxes | Powered by JetHome®