RISC-V: Add libgcc helpers for clz
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> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
8ce194d068
commit
1edef90cf9
2 changed files with 49 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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__)
|
||||
|
||||
|
|
Loading…
Reference in a new issue