Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262146AbVAYVPs (ORCPT ); Tue, 25 Jan 2005 16:15:48 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262139AbVAYVOK (ORCPT ); Tue, 25 Jan 2005 16:14:10 -0500 Received: from 168.imtp.Ilyichevsk.Odessa.UA ([195.66.192.168]:24336 "HELO port.imtp.ilyichevsk.odessa.ua") by vger.kernel.org with SMTP id S262148AbVAYVDL (ORCPT ); Tue, 25 Jan 2005 16:03:11 -0500 From: Denis Vlasenko To: Matt Mackall , Andrew Morton , "Theodore Ts'o" Subject: Re: [PATCH 1/12] random pt4: Create new rol32/ror32 bitops Date: Tue, 25 Jan 2005 23:02:55 +0200 User-Agent: KMail/1.5.4 Cc: linux-kernel@vger.kernel.org References: <2.314297600@selenic.com> In-Reply-To: <2.314297600@selenic.com> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200501252302.55038.vda@port.imtp.ilyichevsk.odessa.ua> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1233 Lines: 46 On Friday 21 January 2005 23:41, Matt Mackall wrote: > --- rnd2.orig/include/linux/bitops.h 2005-01-19 22:57:54.000000000 -0800 > +++ rnd2/include/linux/bitops.h 2005-01-20 09:20:24.641660815 -0800 > @@ -134,4 +134,26 @@ > return sizeof(w) == 4 ? generic_hweight32(w) : generic_hweight64(w); > } > > +/* > + * rol32 - rotate a 32-bit value left > + * > + * @word: value to rotate > + * @shift: bits to roll > + */ > +static inline __u32 rol32(__u32 word, int shift) > +{ > + return (word << shift) | (word >> (32 - shift)); > +} > + > +/* > + * ror32 - rotate a 32-bit value right > + * > + * @word: value to rotate > + * @shift: bits to roll > + */ > +static inline __u32 ror32(__u32 word, int shift) > +{ > + return (word >> shift) | (word << (32 - shift)); > +} > + > #endif gcc generates surprisingly good assembly for this, I coudn't beat it for 32bit rotations. Cool! So you are absolutely right here with not trying to asm optimize it. OTOH 64bit gcc rol is worse. -- vda - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/