grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Optimization calculation expression of Macro


From: Daniel Kiper
Subject: Re: [PATCH] Optimization calculation expression of Macro
Date: Thu, 4 Apr 2019 18:52:34 +0200
User-agent: NeoMutt/20170113 (1.7.2)

On Wed, Apr 03, 2019 at 05:27:18PM +0800, WILLIAM NEW wrote:
> Just to remove the common factor: "sizeof (grub_addr_t)"  from the
> numerator and denominator of the fractional expression of next var.
> Let me explant it:
> Shortly:
> H: struct grub_module_header ;
> B: grub_uint32_t ;
> A: grub_addr_t;
>
> Thus, original expression can be expressed as:
> var = (H *)((B*)var) + ( offset_exp ))
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>              (((H*)var)->size + sizeof(A) - 1)    sizeof(A)  |
> offset_exp = --------------------------------- * ----------- |
>                       sizeof(A)                   sizeof(B)  |
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Remove the common factor "sizeof(A)" of fractional offset_exp, we got
> the result.
> offset_exp_new = ((H*)->size + sizeof(A) - 1) / sizeof(B)
>                    = ((struct grub_module_header *) var)->size +
> sizeof (grub_addr_t) -1) / sizeof (grub_uint32_t)
>
> so:
> var =(H *)(((B*)var) + ( (((H*)var)->size + sizeof(A) - 1) / sizeof(B) ))
>
>
> Still, the new offset express is meaningfull:
> numerator: ((struct grub_module_header *) var)->size + sizeof (grub_addr_t) 
> -1)
>           it present the offset value united by byte.
> denominator: sizeof (grub_uint32_t)
> it's means "struct grub_module_header" alligned by sizeof(grub_uint32_t)
>
> Please feel free to contact me if you need any further information.

Gosh! I missed that somehow. Sorry about that. So,
  Reviewed-by: Daniel Kiper <address@hidden>

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]