Message ID | 20190212103108.56963-10-agraf@suse.de |
---|---|
State | Accepted |
Commit | e795b9011fdb7208cccb1804d9bbc81a6cd251c6 |
Headers | show |
Series | Add RISC-V support | expand |
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? > them in our own copy of libgcc. > > Signed-off-by: Alexander Graf <agraf@suse.de> > --- > 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. Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
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 <agraf@suse.de> >> --- >> 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 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
On Tue, Feb 19, 2019 at 02:26:04PM +0100, Alexander Graf wrote: > 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. OK, let's ignore it. > > > them in our own copy of libgcc. > > > > > > Signed-off-by: Alexander Graf <agraf@suse.de> > > > --- > > > 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. Then Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
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; + } +} +#endif diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h index dc73649a5..2cc69e239 100644 --- a/include/grub/compiler-rt.h +++ b/include/grub/compiler-rt.h @@ -108,6 +108,13 @@ EXPORT_FUNC (__aeabi_llsr) (grub_uint64_t u, int b); #endif +#ifdef __riscv +int +EXPORT_FUNC (__clzsi2) (grub_uint32_t val); + +int +EXPORT_FUNC (__clzdi2) (grub_uint64_t val); +#endif #if defined (__powerpc__)
Gcc may decide it wants to call helper functions to execute clz. Provide them in our own copy of libgcc. Signed-off-by: Alexander Graf <agraf@suse.de> --- grub-core/kern/compiler-rt.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/grub/compiler-rt.h | 7 +++++++ 2 files changed, 49 insertions(+) -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel