* [PATCH] mips: Use builtins for ffs and ffsll
@ 2024-02-04 10:11 Junxian Zhu
2024-02-05 14:19 ` Adhemerval Zanella Netto
0 siblings, 1 reply; 4+ messages in thread
From: Junxian Zhu @ 2024-02-04 10:11 UTC (permalink / raw)
To: libc-alpha; +Cc: Junxian Zhu
From: Junxian Zhu <zhujunxian@oss.cipunited.com>
__builtin_ffs{,ll} basically on __builtin_ctz{,ll} in MIPS GCC compiler.
The hardware ctz instructions were available after MIPS{32,64} Release1. By using builtin ctz. It can also reduce code size of ffs/ffsll.
Checked on mips o32. mips64.
Signed-off-by: Junxian Zhu <zhujunxian@oss.cipunited.com>
---
sysdeps/mips/math-use-builtins-ffs.h | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 sysdeps/mips/math-use-builtins-ffs.h
diff --git a/sysdeps/mips/math-use-builtins-ffs.h b/sysdeps/mips/math-use-builtins-ffs.h
new file mode 100644
index 0000000000..78b3f14fae
--- /dev/null
+++ b/sysdeps/mips/math-use-builtins-ffs.h
@@ -0,0 +1,2 @@
+#define USE_FFS_BUILTIN (__mips_isa_rev >= 1)
+#define USE_FFSLL_BUILTIN (__mips_isa_rev >= 1)
--
2.43.0.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mips: Use builtins for ffs and ffsll
2024-02-04 10:11 [PATCH] mips: Use builtins for ffs and ffsll Junxian Zhu
@ 2024-02-05 14:19 ` Adhemerval Zanella Netto
2024-02-05 18:28 ` Adhemerval Zanella Netto
0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella Netto @ 2024-02-05 14:19 UTC (permalink / raw)
To: Junxian Zhu, libc-alpha
On 04/02/24 07:11, Junxian Zhu wrote:
> From: Junxian Zhu <zhujunxian@oss.cipunited.com>
>
> __builtin_ffs{,ll} basically on __builtin_ctz{,ll} in MIPS GCC compiler.
> The hardware ctz instructions were available after MIPS{32,64} Release1. By using builtin ctz. It can also reduce code size of ffs/ffsll.
>
> Checked on mips o32. mips64.
>
> Signed-off-by: Junxian Zhu <zhujunxian@oss.cipunited.com>
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> sysdeps/mips/math-use-builtins-ffs.h | 2 ++
> 1 file changed, 2 insertions(+)
> create mode 100644 sysdeps/mips/math-use-builtins-ffs.h
>
> diff --git a/sysdeps/mips/math-use-builtins-ffs.h b/sysdeps/mips/math-use-builtins-ffs.h
> new file mode 100644
> index 0000000000..78b3f14fae
> --- /dev/null
> +++ b/sysdeps/mips/math-use-builtins-ffs.h
> @@ -0,0 +1,2 @@
> +#define USE_FFS_BUILTIN (__mips_isa_rev >= 1)
> +#define USE_FFSLL_BUILTIN (__mips_isa_rev >= 1)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mips: Use builtins for ffs and ffsll
2024-02-05 14:19 ` Adhemerval Zanella Netto
@ 2024-02-05 18:28 ` Adhemerval Zanella Netto
2024-05-12 17:06 ` Maciej W. Rozycki
0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella Netto @ 2024-02-05 18:28 UTC (permalink / raw)
To: Junxian Zhu, libc-alpha
On 05/02/24 11:19, Adhemerval Zanella Netto wrote:
>
>
> On 04/02/24 07:11, Junxian Zhu wrote:
>> From: Junxian Zhu <zhujunxian@oss.cipunited.com>
>>
>> __builtin_ffs{,ll} basically on __builtin_ctz{,ll} in MIPS GCC compiler.
>> The hardware ctz instructions were available after MIPS{32,64} Release1. By using builtin ctz. It can also reduce code size of ffs/ffsll.
>>
>> Checked on mips o32. mips64.
>>
>> Signed-off-by: Junxian Zhu <zhujunxian@oss.cipunited.com>
>
> LGTM, thanks.
>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
>> ---
>> sysdeps/mips/math-use-builtins-ffs.h | 2 ++
>> 1 file changed, 2 insertions(+)
>> create mode 100644 sysdeps/mips/math-use-builtins-ffs.h
>>
>> diff --git a/sysdeps/mips/math-use-builtins-ffs.h b/sysdeps/mips/math-use-builtins-ffs.h
>> new file mode 100644
>> index 0000000000..78b3f14fae
>> --- /dev/null
>> +++ b/sysdeps/mips/math-use-builtins-ffs.h
>> @@ -0,0 +1,2 @@
>> +#define USE_FFS_BUILTIN (__mips_isa_rev >= 1)
>> +#define USE_FFSLL_BUILTIN (__mips_isa_rev >= 1)
In fact you need to include <sysdep.h> since gcc only defines __mips_isa_rev
for -mips32 or higher.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mips: Use builtins for ffs and ffsll
2024-02-05 18:28 ` Adhemerval Zanella Netto
@ 2024-05-12 17:06 ` Maciej W. Rozycki
0 siblings, 0 replies; 4+ messages in thread
From: Maciej W. Rozycki @ 2024-05-12 17:06 UTC (permalink / raw)
To: Adhemerval Zanella Netto; +Cc: Junxian Zhu, libc-alpha
On Mon, 5 Feb 2024, Adhemerval Zanella Netto wrote:
> >> __builtin_ffs{,ll} basically on __builtin_ctz{,ll} in MIPS GCC compiler.
> >> The hardware ctz instructions were available after MIPS{32,64} Release1. By
> using builtin ctz. It can also reduce code size of ffs/ffsll.
> >>
> >> Checked on mips o32. mips64.
> >>
> >> Signed-off-by: Junxian Zhu <zhujunxian@oss.cipunited.com>
> >
> > LGTM, thanks.
> >
> > Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> >
> >> ---
> >> sysdeps/mips/math-use-builtins-ffs.h | 2 ++
> >> 1 file changed, 2 insertions(+)
> >> create mode 100644 sysdeps/mips/math-use-builtins-ffs.h
> >>
> >> diff --git a/sysdeps/mips/math-use-builtins-ffs.h
> b/sysdeps/mips/math-use-builtins-ffs.h
> >> new file mode 100644
> >> index 0000000000..78b3f14fae
> >> --- /dev/null
> >> +++ b/sysdeps/mips/math-use-builtins-ffs.h
> >> @@ -0,0 +1,2 @@
> >> +#define USE_FFS_BUILTIN (__mips_isa_rev >= 1)
> >> +#define USE_FFSLL_BUILTIN (__mips_isa_rev >= 1)
>
> In fact you need to include <sysdep.h> since gcc only defines __mips_isa_rev
> for -mips32 or higher.
Also this causes code pessimisation for MIPS32 and `ffsll', as there is
no hw instruction for this operation in the 32-bit ABI and consequently
`__builtin_ffsll' resorts to a libcall. So IMO USE_FFSLL_BUILTIN ought to
only be set for 64-bit ABIs, making `ffsll' defer to `ffs' (and then use
32-bit CLZ as appropriate).
NB contrary to the change description there is no CTZ instruction in the
MIPS ISA at any level. There are: CLO, CLZ, and for 64-bit: DCLO, DCLZ,
and `__builtin_ctz', etc. can be synthesized with the usual calculation.
Maciej
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-12 17:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-04 10:11 [PATCH] mips: Use builtins for ffs and ffsll Junxian Zhu
2024-02-05 14:19 ` Adhemerval Zanella Netto
2024-02-05 18:28 ` Adhemerval Zanella Netto
2024-05-12 17:06 ` Maciej W. Rozycki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).