mips: Use builtins for ffs and ffsll

Message ID 20240204101132.653-2-zhujunxian@oss.cipunited.com
State Superseded
Headers
Series mips: Use builtins for ffs and ffsll |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed

Commit Message

Junxian Zhu Feb. 4, 2024, 10:11 a.m. UTC
  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
  

Comments

Adhemerval Zanella Netto Feb. 5, 2024, 2:19 p.m. UTC | #1
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)
  
Adhemerval Zanella Netto Feb. 5, 2024, 6:28 p.m. UTC | #2
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.
  

Patch

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)