* [PATCH v2] Alchemy: cpu feature override constants.
@ 2008-11-25 23:12 Manuel Lauss
2008-11-25 23:23 ` David Daney
2008-11-26 12:48 ` Sergei Shtylyov
0 siblings, 2 replies; 7+ messages in thread
From: Manuel Lauss @ 2008-11-25 23:12 UTC (permalink / raw)
To: LMO, Ralf Baechle
Add cpu feature override constants for Alchemy.
This helps code generation: fls() for instance is compiled without
using the clz instruction; other macros which do runtime feature
detection fall back on safe legacy code as well. Adding this override
fixes that. As a sideeffect, the size of a kernel built with an
extended db1200 defconfig is reduced by over 200kB:
text data bss dec hex filename
3901089 124160 436528 4461777 4414d1 vmlinux
3676433 124096 436528 4237057 40a701 vmlinux-patched
Signed-off-by: Manuel Lauss <mano@roarinelk.homelinux.net>
---
This v2 version fixes a few typos.
.../asm/mach-au1x00/cpu-feature-overrides.h | 51 ++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
create mode 100644 arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h
diff --git a/arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h b/arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h
new file mode 100644
index 0000000..c22492e
--- /dev/null
+++ b/arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h
@@ -0,0 +1,51 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#ifndef __ASM_MACH_AU1X00_CPU_FEATURE_OVERRIDES_H
+#define __ASM_MACH_AU1X00_CPU_FEATURE_OVERRIDES_H
+
+#define cpu_has_tlb 1
+#define cpu_has_4kex 1
+#define cpu_has_3k_cache 0
+#define cpu_has_4k_cache 1
+#define cpu_has_tx39_cache 0
+#define cpu_has_fpu 0
+#define cpu_has_32fpr 0
+#define cpu_has_counter 1
+#define cpu_has_watch 1
+#define cpu_has_divec 1
+#define cpu_has_vce 0
+#define cpu_has_cache_cdex_p 0
+#define cpu_has_cache_cdex_s 0
+#define cpu_has_mcheck 1
+#define cpu_has_ejtag 1
+#define cpu_has_llsc 1
+#define cpu_has_mips16 0
+#define cpu_has_mdmx 0
+#define cpu_has_mips3d 0
+#define cpu_has_smartmips 0
+#define cpu_has_vtag_icache 0
+#define cpu_has_dc_aliases 0
+#define cpu_has_ic_fills_f_dc 1
+#define cpu_has_pindexed_cache 0
+#define cpu_has_mips32r1 1
+#define cpu_has_mips32r2 0
+#define cpu_has_mips64r1 0
+#define cpu_has_mips64r2 0
+#define cpu_has_dsp 0
+#define cpu_has_mipsmt 0
+#define cpu_has_userlocal 0
+#define cpu_has_nofpuex 0
+#define cpu_has_64bits 0
+#define cpu_has_64bit_zero_reg 0
+#define cpu_has_vint 0
+#define cpu_has_veic 0
+#define cpu_has_inclusive_pcaches 0
+
+#define cpu_dcache_line_size() 32
+#define cpu_icache_line_size() 32
+
+#endif /* __ASM_MACH_AU1X00_CPU_FEATURE_OVERRIDES_H */
--
1.6.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Alchemy: cpu feature override constants.
2008-11-25 23:12 [PATCH v2] Alchemy: cpu feature override constants Manuel Lauss
@ 2008-11-25 23:23 ` David Daney
2008-11-26 5:50 ` Manuel Lauss
2008-11-26 12:48 ` Sergei Shtylyov
1 sibling, 1 reply; 7+ messages in thread
From: David Daney @ 2008-11-25 23:23 UTC (permalink / raw)
To: Manuel Lauss; +Cc: LMO, Ralf Baechle
Manuel Lauss wrote:
[...]
> +#define cpu_has_tlb 1
> +#define cpu_has_4kex 1
> +#define cpu_has_3k_cache 0
> +#define cpu_has_4k_cache 1
> +#define cpu_has_tx39_cache 0
> +#define cpu_has_fpu 0
> +#define cpu_has_32fpr 0
> +#define cpu_has_counter 1
> +#define cpu_has_watch 1
> +#define cpu_has_divec 1
> +#define cpu_has_vce 0
> +#define cpu_has_cache_cdex_p 0
> +#define cpu_has_cache_cdex_s 0
> +#define cpu_has_mcheck 1
> +#define cpu_has_ejtag 1
> +#define cpu_has_llsc 1
> +#define cpu_has_mips16 0
> +#define cpu_has_mdmx 0
> +#define cpu_has_mips3d 0
> +#define cpu_has_smartmips 0
> +#define cpu_has_vtag_icache 0
> +#define cpu_has_dc_aliases 0
> +#define cpu_has_ic_fills_f_dc 1
> +#define cpu_has_pindexed_cache 0
> +#define cpu_has_mips32r1 1
> +#define cpu_has_mips32r2 0
> +#define cpu_has_mips64r1 0
> +#define cpu_has_mips64r2 0
> +#define cpu_has_dsp 0
> +#define cpu_has_mipsmt 0
> +#define cpu_has_userlocal 0
> +#define cpu_has_nofpuex 0
> +#define cpu_has_64bits 0
> +#define cpu_has_64bit_zero_reg 0
> +#define cpu_has_vint 0
> +#define cpu_has_veic 0
> +#define cpu_has_inclusive_pcaches 0
> +
> +#define cpu_dcache_line_size() 32
> +#define cpu_icache_line_size() 32
The probe routines in cpu-probe.c should get at least some of that
correct. How about just overriding the things that cpu-probe.c doesn't
get right?
David Daney
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Alchemy: cpu feature override constants.
2008-11-25 23:23 ` David Daney
@ 2008-11-26 5:50 ` Manuel Lauss
2008-11-26 7:51 ` Ralf Baechle
0 siblings, 1 reply; 7+ messages in thread
From: Manuel Lauss @ 2008-11-26 5:50 UTC (permalink / raw)
To: David Daney; +Cc: LMO, Ralf Baechle
Hi David,
On Tue, Nov 25, 2008 at 03:23:48PM -0800, David Daney wrote:
> Manuel Lauss wrote:
> [...]
>> +#define cpu_has_tlb 1
>> +#define cpu_has_4kex 1
>> +#define cpu_has_3k_cache 0
>> +#define cpu_has_4k_cache 1
>> +#define cpu_has_tx39_cache 0
>> +#define cpu_has_fpu 0
>> +#define cpu_has_32fpr 0
>> +#define cpu_has_counter 1
>> +#define cpu_has_watch 1
>> +#define cpu_has_divec 1
>> +#define cpu_has_vce 0
>> +#define cpu_has_cache_cdex_p 0
>> +#define cpu_has_cache_cdex_s 0
>> +#define cpu_has_mcheck 1
>> +#define cpu_has_ejtag 1
>> +#define cpu_has_llsc 1
>> +#define cpu_has_mips16 0
>> +#define cpu_has_mdmx 0
>> +#define cpu_has_mips3d 0
>> +#define cpu_has_smartmips 0
>> +#define cpu_has_vtag_icache 0
>> +#define cpu_has_dc_aliases 0
>> +#define cpu_has_ic_fills_f_dc 1
>> +#define cpu_has_pindexed_cache 0
>> +#define cpu_has_mips32r1 1
>> +#define cpu_has_mips32r2 0
>> +#define cpu_has_mips64r1 0
>> +#define cpu_has_mips64r2 0
>> +#define cpu_has_dsp 0
>> +#define cpu_has_mipsmt 0
>> +#define cpu_has_userlocal 0
>> +#define cpu_has_nofpuex 0
>> +#define cpu_has_64bits 0
>> +#define cpu_has_64bit_zero_reg 0
>> +#define cpu_has_vint 0
>> +#define cpu_has_veic 0
>> +#define cpu_has_inclusive_pcaches 0
>> +
>> +#define cpu_dcache_line_size() 32
>> +#define cpu_icache_line_size() 32
>
> The probe routines in cpu-probe.c should get at least some of that correct.
> How about just overriding the things that cpu-probe.c doesn't get right?
CPU detection gets them all right, it's just that somehow GCC does not use
the information correctly; i.e. in the __fls() case it blindly falls back
on the C version instead of using the asm macro with clz in it. I scanned
a few callsites of __fls() and there's not 'clz' to be found anywhere. With
this addition the clz is used and the binary is a _lot_ smaller.
I believe this is a gcc thing, but this seemed to be the obvious quick
remedy.
Thanks!
Manuel Lauss
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Alchemy: cpu feature override constants.
2008-11-26 5:50 ` Manuel Lauss
@ 2008-11-26 7:51 ` Ralf Baechle
2008-11-26 8:08 ` Manuel Lauss
0 siblings, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2008-11-26 7:51 UTC (permalink / raw)
To: Manuel Lauss; +Cc: David Daney, LMO
On Wed, Nov 26, 2008 at 06:50:53AM +0100, Manuel Lauss wrote:
> > The probe routines in cpu-probe.c should get at least some of that correct.
> > How about just overriding the things that cpu-probe.c doesn't get right?
>
> CPU detection gets them all right, it's just that somehow GCC does not use
> the information correctly; i.e. in the __fls() case it blindly falls back
> on the C version instead of using the asm macro with clz in it. I scanned
> a few callsites of __fls() and there's not 'clz' to be found anywhere. With
> this addition the clz is used and the binary is a _lot_ smaller.
>
You should define all values as constants, as far as known. GCC will
then be able to use constant propagation and dead code elemination to
optimize the code for a particular target system.
The way fls() is written it will only use of CLZ if the expression
cpu_has_mips_r is a constant, that is if the kernel is being built
exclusivly for MIPS32 / MIPS64 revision 1 or higher. The reason that
__fls is written this way is that both it's legacy and R1 variants using
CLZ/DCLZ the function body will be compiled into something relativly small.
There is not such much point in adding even more code for a runtime
decission between two variants.
> I believe this is a gcc thing, but this seemed to be the obvious quick
> remedy.
GCC does correct.
Ralf
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Alchemy: cpu feature override constants.
2008-11-26 7:51 ` Ralf Baechle
@ 2008-11-26 8:08 ` Manuel Lauss
2008-11-26 8:34 ` Ralf Baechle
0 siblings, 1 reply; 7+ messages in thread
From: Manuel Lauss @ 2008-11-26 8:08 UTC (permalink / raw)
To: Ralf Baechle; +Cc: David Daney, LMO
On Wed, Nov 26, 2008 at 07:51:04AM +0000, Ralf Baechle wrote:
> On Wed, Nov 26, 2008 at 06:50:53AM +0100, Manuel Lauss wrote:
>
> > > The probe routines in cpu-probe.c should get at least some of that correct.
> > > How about just overriding the things that cpu-probe.c doesn't get right?
> >
> > CPU detection gets them all right, it's just that somehow GCC does not use
> > the information correctly; i.e. in the __fls() case it blindly falls back
> > on the C version instead of using the asm macro with clz in it. I scanned
> > a few callsites of __fls() and there's not 'clz' to be found anywhere. With
> > this addition the clz is used and the binary is a _lot_ smaller.
> >
>
> You should define all values as constants, as far as known. GCC will
> then be able to use constant propagation and dead code elemination to
> optimize the code for a particular target system.
>
> The way fls() is written it will only use of CLZ if the expression
> cpu_has_mips_r is a constant, that is if the kernel is being built
> exclusivly for MIPS32 / MIPS64 revision 1 or higher. The reason that
Ah, so the __builtin_constat_p() is a compiletime check as to whether a
given symbol is a constant or needs to be evaluated at runtime? That
explains a lot.
Thanks,
Manuel Lauss
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Alchemy: cpu feature override constants.
2008-11-26 8:08 ` Manuel Lauss
@ 2008-11-26 8:34 ` Ralf Baechle
0 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2008-11-26 8:34 UTC (permalink / raw)
To: Manuel Lauss; +Cc: David Daney, LMO
On Wed, Nov 26, 2008 at 09:08:08AM +0100, Manuel Lauss wrote:
> > then be able to use constant propagation and dead code elemination to
> > optimize the code for a particular target system.
> >
> > The way fls() is written it will only use of CLZ if the expression
> > cpu_has_mips_r is a constant, that is if the kernel is being built
> > exclusivly for MIPS32 / MIPS64 revision 1 or higher. The reason that
>
> Ah, so the __builtin_constat_p() is a compiletime check as to whether a
> given symbol is a constant or needs to be evaluated at runtime? That
> explains a lot.
Yes. See GCC documentation. It's used all over place in the kernel for
optimizations. In some occasions gcc is not able to determine the
constness of an expression, so the code should better prepared to handle
a 0 return value. Another interesting property of __buitin_const_p() is
that side effects don't matter, that is for example
__buitin_const_p(expr) && (expr)
will only execute any sideeffects the expression expr may have once which
is extremly handy in macro.
Ralf
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] Alchemy: cpu feature override constants.
2008-11-25 23:12 [PATCH v2] Alchemy: cpu feature override constants Manuel Lauss
2008-11-25 23:23 ` David Daney
@ 2008-11-26 12:48 ` Sergei Shtylyov
1 sibling, 0 replies; 7+ messages in thread
From: Sergei Shtylyov @ 2008-11-26 12:48 UTC (permalink / raw)
To: Manuel Lauss; +Cc: LMO, Ralf Baechle
Hello.
Manuel Lauss wrote:
> Add cpu feature override constants for Alchemy.
>
> This helps code generation: fls() for instance is compiled without
> using the clz instruction; other macros which do runtime feature
> detection fall back on safe legacy code as well. Adding this override
> fixes that. As a sideeffect, the size of a kernel built with an
> extended db1200 defconfig is reduced by over 200kB:
>
> text data bss dec hex filename
> 3901089 124160 436528 4461777 4414d1 vmlinux
> 3676433 124096 436528 4237057 40a701 vmlinux-patched
>
Great!
> Signed-off-by: Manuel Lauss <mano@roarinelk.homelinux.net>
>
The whitespace police on the road. :-)
> diff --git a/arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h b/arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h
> new file mode 100644
> index 0000000..c22492e
> --- /dev/null
> +++ b/arch/mips/include/asm/mach-au1x00/cpu-feature-overrides.h
> @@ -0,0 +1,51 @@
>
[...]
> +
> +#define cpu_dcache_line_size() 32
> +#define cpu_icache_line_size() 32
>
Inconsistent alignment.
WBR, Sergei
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-11-26 12:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-25 23:12 [PATCH v2] Alchemy: cpu feature override constants Manuel Lauss
2008-11-25 23:23 ` David Daney
2008-11-26 5:50 ` Manuel Lauss
2008-11-26 7:51 ` Ralf Baechle
2008-11-26 8:08 ` Manuel Lauss
2008-11-26 8:34 ` Ralf Baechle
2008-11-26 12:48 ` Sergei Shtylyov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox