lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <54BC59C3.8010208@roeck-us.net>
Date:	Sun, 18 Jan 2015 17:11:31 -0800
From:	Guenter Roeck <linux@...ck-us.net>
To:	Linus Torvalds <torvalds@...ux-foundation.org>,
	jsrhbz@...argh.force9.co.uk,
	christoph.muellner@...obroma-systems.com, linux@...musvillemoes.dk,
	paulmck@...ux.vnet.ibm.com, tglx@...utronix.de, mingo@...nel.org,
	akpm@...ux-foundation.org, hpa@...or.com, maxime.coquelin@...com,
	linux-kernel@...r.kernel.org, peterz@...radead.org,
	martink@...teo.de, tytso@....edu
CC:	linux-tip-commits@...r.kernel.org
Subject: Re: [tip:core/types] bitops: Add sign_extend8(), 16 and 64 functions

On 01/18/2015 11:54 AM, Linus Torvalds wrote:
> Why?
>

Probably because some of us are, unfortunately, sometimes clueless :-(.

Guenter

> The 8- and 16- bit versions are the same as the 32-bit one. This seems pointless. If you want something where the sign is in bit 3, they all return the same value, just the return type differs, but that's really a *caller* thing, no?
>
>       Linus
>
> On Jan 19, 2015 7:07 AM, "tip-bot for Martin Kepplinger" <tipbot@...or.com <mailto:tipbot@...or.com>> wrote:
>
>     Commit-ID:  7e9358073d3f0ed0a028c48aa54009b3296dffc9
>     Gitweb: http://git.kernel.org/tip/7e9358073d3f0ed0a028c48aa54009b3296dffc9
>     Author:     Martin Kepplinger <martink@...teo.de <mailto:martink@...teo.de>>
>     AuthorDate: Mon, 12 Jan 2015 18:22:50 +0100
>     Committer:  Ingo Molnar <mingo@...nel.org <mailto:mingo@...nel.org>>
>     CommitDate: Sun, 18 Jan 2015 20:03:51 +0100
>
>     bitops: Add sign_extend8(), 16 and 64 functions
>
>     This adds helper functions for sign-extending signed values of any
>     lower (hardware-)given size to s8, s16 or s64 respectively, just like
>     sign_extend32() for s32.
>
>     This completes the sign_extend*() API family to work on all bit sizes
>     like most other bitops APIs do.
>
>     Suggested-by: Christoph Muellner <christoph.muellner@...obroma-systems.com <mailto:christoph.muellner@...obroma-systems.com>>
>     Signed-off-by: Martin Kepplinger <martink@...teo.de <mailto:martink@...teo.de>>
>     Reviewed-by: Guenter Roeck <linux@...ck-us.net <mailto:linux@...ck-us.net>>
>     Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org <mailto:peterz@...radead.org>>
>     Cc: John Sullivan <jsrhbz@...argh.force9.co.uk <mailto:jsrhbz@...argh.force9.co.uk>>
>     Cc: Linus Torvalds <torvalds@...ux-foundation.org <mailto:torvalds@...ux-foundation.org>>
>     Cc: Maxime COQUELIN <maxime.coquelin@...com <mailto:maxime.coquelin@...com>>
>     Cc: Paul E. McKenney <paulmck@...ux.vnet.ibm.com <mailto:paulmck@...ux.vnet.ibm.com>>
>     Cc: Rasmus Villemoes <linux@...musvillemoes.dk <mailto:linux@...musvillemoes.dk>>
>     Cc: Theodore Ts'o <tytso@....edu <mailto:tytso@....edu>>
>     Cc: Andrew Morton <akpm@...ux-foundation.org <mailto:akpm@...ux-foundation.org>>
>     Link: http://lkml.kernel.org/r/1421083370-24924-1-git-send-email-martink@posteo.de
>     Signed-off-by <http://lkml.kernel.org/r/1421083370-24924-1-git-send-email-martink@posteo.de Signed-off-by>: Ingo Molnar <mingo@...nel.org <mailto:mingo@...nel.org>>
>     ---
>       include/linux/bitops.h | 33 +++++++++++++++++++++++++++++++++
>       1 file changed, 33 insertions(+)
>
>     diff --git a/include/linux/bitops.h b/include/linux/bitops.h
>     index 5d858e0..9c31680 100644
>     --- a/include/linux/bitops.h
>     +++ b/include/linux/bitops.h
>     @@ -161,6 +161,28 @@ static inline __u8 ror8(__u8 word, unsigned int shift)
>       }
>
>       /**
>     + * sign_extend8 - sign extend a 8-bit value using specified bit as sign-bit
>     + * @value: value to sign extend
>     + * @index: 0 based bit index (0<=index<8) to sign bit
>     + */
>     +static inline __s8 sign_extend8(__u8 value, int index)
>     +{
>     +       __u8 shift = 7 - index;
>     +       return (__s8)(value << shift) >> shift;
>     +}
>     +
>     +/**
>     + * sign_extend16 - sign extend a 16-bit value using specified bit as sign-bit
>     + * @value: value to sign extend
>     + * @index: 0 based bit index (0<=index<16) to sign bit
>     + */
>     +static inline __s16 sign_extend16(__u16 value, int index)
>     +{
>     +       __u8 shift = 15 - index;
>     +       return (__s16)(value << shift) >> shift;
>     +}
>     +
>     +/**
>        * sign_extend32 - sign extend a 32-bit value using specified bit as sign-bit
>        * @value: value to sign extend
>        * @index: 0 based bit index (0<=index<32) to sign bit
>     @@ -171,6 +193,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)
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ