[patch/rfc] align_up, align_down
Kevin Buettner
kevinb@redhat.com
Fri Sep 12 20:46:00 GMT 2003
On Sep 12, 4:08pm, Andrew Cagney wrote:
> This patch introduces two utility functions:
>
> align_up (v, n);
> align_down (v, n);
>
> for [re]aligning addresses vis:
>
> + addr = align_up (addr, 8); -- VALUE needs 8 byte alignment
> + write_memory (addr, value, len);
> + addr += len;
>
> + sp = align_down (sp - len, 16); -- Keep SP 16 byte aligned
> + write_memory (sp, value, len);
>
> It then goes through and replaces all occurances of round_up /
> round_down and align_up / align_down with these globals.
>
> You'll notice that I chose align_XXX rather than round_XXX. I think
> this better reflects the intended usage. I've noticed a lot of code doing:
>
> write_memory (addr, data, len);
> addr += round_up (len, 16);
>
> instead of:
>
> addr = align_up (addr, 16);
> write_memory (addr, data, len);
> addr += len;
>
> as the former may not result in ADDR having the required alignment. The
> PPC SVr4 Altivec ABI, for instance, switches between 8 and 16 byte
> alignment making the former code very wrong.
>
> anyway, thoughts?
Looks good to me...
Kevin
More information about the Gdb-patches
mailing list