Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gw5PV-0006vt-4X for mharc-grub-devel@gnu.org; Tue, 19 Feb 2019 08:26:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:32956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gw5PS-0006uF-LJ for grub-devel@gnu.org; Tue, 19 Feb 2019 08:26:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gw5PR-0002lH-QL for grub-devel@gnu.org; Tue, 19 Feb 2019 08:26:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:37664 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gw5PR-0002l6-Ds for grub-devel@gnu.org; Tue, 19 Feb 2019 08:26:05 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6DAA1AC8A; Tue, 19 Feb 2019 13:26:04 +0000 (UTC) Subject: Re: [PATCH v6 09/11] RISC-V: Add libgcc helpers for clz To: Daniel Kiper Cc: grub-devel@gnu.org, "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng References: <20190212103108.56963-1-agraf@suse.de> <20190212103108.56963-10-agraf@suse.de> <20190218195528.kfifazvs5fzjxyrt@tomti.i.net-space.pl> From: Alexander Graf Message-ID: Date: Tue, 19 Feb 2019 14:26:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20190218195528.kfifazvs5fzjxyrt@tomti.i.net-space.pl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 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, 19 Feb 2019 13:26:07 -0000 On 02/18/2019 08:55 PM, Daniel Kiper wrote: > On Tue, Feb 12, 2019 at 11:31:06AM +0100, Alexander Graf wrote: >> Gcc may decide it wants to call helper functions to execute clz. Provide > Do we know when it happens? Could we add that to the commit message? Uh, on bitfield operations? I don't know - gcc just does it. > >> them in our own copy of libgcc. >> >> Signed-off-by: Alexander Graf >> --- >> grub-core/kern/compiler-rt.c | 42 ++++++++++++++++++++++++++++++++++++++++++ >> include/grub/compiler-rt.h | 7 +++++++ >> 2 files changed, 49 insertions(+) >> >> diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c >> index 5cfcb3907..404902119 100644 >> --- a/grub-core/kern/compiler-rt.c >> +++ b/grub-core/kern/compiler-rt.c >> @@ -417,3 +417,45 @@ __aeabi_llsl (grub_uint64_t u, int b) >> __attribute__ ((alias ("__ashldi3"))); >> >> #endif >> + >> +#ifdef __riscv >> + >> +/* Based on libgcc from gcc suite. */ >> +int >> +__clzsi2 (grub_uint32_t val) >> +{ >> + int i = 32; >> + int j = 16; >> + int temp; >> + >> + for (; j; j >>= 1) >> + { >> + if ((temp = val) >> j) >> + { >> + if (j == 1) >> + { >> + return (i - 2); >> + } >> + else >> + { >> + i -= j; >> + val = temp; >> + } >> + } >> + } >> + return (i - val); >> +} >> + >> +int >> +__clzdi2 (grub_uint64_t val) >> +{ >> + if (val >> 32) >> + { >> + return __clzsi2 (val >> 32); >> + } >> + else >> + { >> + return __clzsi2 (val) + 32; >> + } >> +} > I assume that __clzsi2() and __clzdi2() are exact copies from libgcc. > If no then I have an itching to drop redundant curly braces. Yes, copied from libgcc. Alex