Return-Path: Received: from mail-co1nam03on0096.outbound.protection.outlook.com ([104.47.40.96]:4313 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932166AbeARVH2 (ORCPT ); Thu, 18 Jan 2018 16:07:28 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Martin Kepplinger , Martin Kepplinger , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [added to the 4.1 stable tree] bitops.h: add sign_extend64() Date: Thu, 18 Jan 2018 21:02:04 +0000 Message-ID: <20180118205908.3220-298-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Martin Kepplinger This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 48e203e21b29cd4b2c58403fe8bca68e2e854895 ] 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 fell asleep but since there are possible users, let's add it. Signed-off-by: Martin Kepplinger Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Thomas Gleixner Cc: "H. Peter Anvin" Cc: George Spelvin Cc: Rasmus Villemoes Cc: Maxime Coquelin Cc: Denys Vlasenko Cc: Yury Norov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/bitops.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 297f5bda4fdf..858020682ac8 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -171,6 +171,17 @@ static inline __s32 sign_extend32(__u32 value, int ind= ex) return (__s32)(value << shift) >> shift; } =20 +/** + * 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<=3Dindex<64) to sign bit + */ +static inline __s64 sign_extend64(__u64 value, int index) +{ + __u8 shift =3D 63 - index; + return (__s64)(value << shift) >> shift; +} + static inline unsigned fls_long(unsigned long l) { if (sizeof(l) =3D=3D 4) --=20 2.11.0