Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fAr8d-0005yb-EF for mharc-grub-devel@gnu.org; Tue, 24 Apr 2018 02:09:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAr8b-0005yU-21 for grub-devel@gnu.org; Tue, 24 Apr 2018 02:09:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAr8X-0004VN-Mc for grub-devel@gnu.org; Tue, 24 Apr 2018 02:09:13 -0400 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:49573) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAr8X-0004UN-CR for grub-devel@gnu.org; Tue, 24 Apr 2018 02:09:09 -0400 Received: from mazu (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Tue, 24 Apr 2018 00:08:54 -0600 Date: Tue, 24 Apr 2018 14:08:51 +0800 From: Michael Chang To: Daniel Kiper Cc: grub-devel@gnu.org Subject: Re: [PATCH] bufio: round up block size to power of 2 Message-ID: <20180424060851.kgovzsc6yidboixd@mazu> Mail-Followup-To: Daniel Kiper , grub-devel@gnu.org References: <20180420072130.qm3lyhwwtc46znph@mazu> <20180423135722.GC4061@router-fw-old.local.net-space.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180423135722.GC4061@router-fw-old.local.net-space.pl> User-Agent: NeoMutt/20170421 (1.8.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 137.65.250.26 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Apr 2018 06:09:14 -0000 On Mon, Apr 23, 2018 at 03:57:22PM +0200, Daniel Kiper wrote: > On Fri, Apr 20, 2018 at 03:21:30PM +0800, Michael Chang wrote: > > Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf > > calcuation in grub_bufio_read. > > > > Signed-off-by: Michael Chang > > --- > > grub-core/io/bufio.c | 8 ++++++++ > > 1 file changed, 8 insertions(+) > > > > diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c > > index 22438277d..4d66b65a3 100644 > > --- a/grub-core/io/bufio.c > > +++ b/grub-core/io/bufio.c > > @@ -61,6 +61,14 @@ grub_bufio_open (grub_file_t io, int size) > > size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE : > > io->size); > > > > + /* round up size to power of 2 */ > > May I ask you to say why here? OK. > > > + if (size & (size - 1)) > > + { > > + int round_up; > > + for (round_up = 1; round_up < size; round_up <<= 1); > > + size = round_up; > > + } > > Please use this (stolen from linux/drivers/md/raid5.c): > while (size & (size - 1)) > size = (size | (size - 1)) + 1; Cool. They will be added in upcoming V2 patch. Thanks, Michael > > Daniel