[Patch] MIPS: Align local variables like global variables

Richard Sandiford rsandifo@nildram.co.uk
Wed Sep 26 17:30:00 GMT 2007


Nigel Stephens <nigel@mips.com> writes:
> +/* If defined, a C expression to compute the alignment for a local
> +   variable.  TYPE is the data type, and ALIGN is the alignment that
> +   the object would ordinarily have.  The value of this macro is used
> +   instead of that alignment to align the object.
>  
> +   If this macro is not defined, then ALIGN is used.
> +
> +   One use of this macro is to increase alignment of medium-size data
> +   to make it all fit in fewer cache lines.  We need this for the same
> +   reason as DATA_ALIGNMENT, namely to cause character arrays to be
> +   word-aligned so that `strcpy' calls that copy constants to
> +   character arrays can be done inline, and 'strcmp' can be optimised
> +   to use word loads. */
> +
> +#define LOCAL_ALIGNMENT(TYPE, ALIGN)				\
> +  DATA_ALIGNMENT(TYPE, ALIGN)

Nits first: please drop the boiler-plate stuff, i.e. everything up to
"fewer cache lines."  (I know there are lots of pre-existing examples,
but I'm hoping to make a sweep over them before 4.3.)  Missing space
in "DATA_ALIGNMENT(".

More importantly, is this a win even for -Os?  Unlike DATA_ALIGNMENT[*],
this should be purely a tuning decision, so can depend on things like
optimize_size.

[*] ISTR MIPSpro expected global variables to have the alignment
    specified by DATA_ALIGNMENT, even if gcc doesn't.

Richard

PS. For the sake of ceremony, please remember to say how patches
were tested ;)



More information about the Gcc-patches mailing list