From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753835AbbJOQWe (ORCPT ); Thu, 15 Oct 2015 12:22:34 -0400 Received: from mout01.posteo.de ([185.67.36.65]:36926 "EHLO mout01.posteo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753599AbbJOQWK (ORCPT ); Thu, 15 Oct 2015 12:22:10 -0400 From: Martin Kepplinger 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 , Martin Kepplinger Subject: [PATCH 2/2] bitops.h: add sign_extend64() Date: Thu, 15 Oct 2015 18:18:29 +0200 Message-Id: <1444925909-6013-3-git-send-email-martink@posteo.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1444925909-6013-1-git-send-email-martink@posteo.de> References: <1444925909-6013-1-git-send-email-martink@posteo.de> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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