This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [patch/rfc] align_up, align_down
- From: Kevin Buettner <kevinb at redhat dot com>
- To: Andrew Cagney <ac131313 at redhat dot com>, gdb-patches at sources dot redhat dot com
- Date: Fri, 12 Sep 2003 13:46:39 -0700
- Subject: Re: [patch/rfc] align_up, align_down
- References: <3F6227D6.3040300@redhat.com>
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