All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Weil <sw@weilnetz.de>
To: "Emilio G. Cota" <cota@braap.org>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] tcg: pack TCGTemp to reduce size by 8 bytes
Date: Mon, 23 Mar 2015 22:42:39 +0100	[thread overview]
Message-ID: <551088CF.1050001@weilnetz.de> (raw)
In-Reply-To: <1426919232-20813-1-git-send-email-cota@braap.org>

Am 21.03.2015 um 07:27 schrieb Emilio G. Cota:
> This brings down the size of the struct from 56 to 48 bytes.
>
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>   tcg/tcg.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tcg/tcg.h b/tcg/tcg.h
> index add7f75..3276924 100644
> --- a/tcg/tcg.h
> +++ b/tcg/tcg.h
> @@ -429,8 +429,8 @@ typedef struct TCGTemp {
>       int val_type;
>       int reg;
>       tcg_target_long val;
> -    int mem_reg;
>       intptr_t mem_offset;
> +    int mem_reg;
>       unsigned int fixed_reg:1;
>       unsigned int mem_coherent:1;
>       unsigned int mem_allocated:1;

Reviewed-by: Stefan Weil <sw@weilnetz.de>

TCGContext includes an array of TCGTemp, so it is even reduced by 4 KiB 
(good for caching),
and tcg.o now uses 55364 instead of 56116 bytes (maybe faster, too).

Further optimizations are possible. TCGTemp can be reduced to 32 bytes 
as the output
of pahole shows:

struct TCGTemp {
         TCGTempVal                 val_type:8; /*     0:24  4 */
         unsigned int               reg:8; /*     0:16  4 */
         unsigned int               mem_reg:8; /*     0: 8  4 */

         /* Bitfield combined with next fields */

         _Bool                      fixed_reg:1; /*     3: 7  1 */
         _Bool                      mem_coherent:1; /*     3: 6  1 */
         _Bool                      mem_allocated:1; /*     3: 5  1 */
         _Bool                      temp_local:1; /*     3: 4  1 */
         _Bool                      temp_allocated:1; /*     3: 3  1 */

         /* XXX 3 bits hole, try to pack */

         TCGType                    base_type:16; /*     4:16  4 */
         TCGType                    type:16; /*     4: 0  4 */
         tcg_target_long            val; /*     8     8 */
         intptr_t                   mem_offset; /*    16     8 */
         const char  *              name; /*    24     8 */

         /* size: 32, cachelines: 1, members: 13 */
         /* bit holes: 1, sum bit holes: 3 bits */
         /* last cacheline: 32 bytes */
};

Here I used a new enum type for val_type and reduced some values to 8 or 
16 bit.
I also put the two most often used values at the beginning, so they can be
addressed without or with a small offset ("often" in the code, no runtime
data available).

Are such optimizations useful?

Stefan



WARNING: multiple messages have this Message-ID (diff)
From: Stefan Weil <sw@weilnetz.de>
To: "Emilio G. Cota" <cota@braap.org>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH] tcg: pack TCGTemp to reduce size by 8 bytes
Date: Mon, 23 Mar 2015 22:42:39 +0100	[thread overview]
Message-ID: <551088CF.1050001@weilnetz.de> (raw)
In-Reply-To: <1426919232-20813-1-git-send-email-cota@braap.org>

Am 21.03.2015 um 07:27 schrieb Emilio G. Cota:
> This brings down the size of the struct from 56 to 48 bytes.
>
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
>   tcg/tcg.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tcg/tcg.h b/tcg/tcg.h
> index add7f75..3276924 100644
> --- a/tcg/tcg.h
> +++ b/tcg/tcg.h
> @@ -429,8 +429,8 @@ typedef struct TCGTemp {
>       int val_type;
>       int reg;
>       tcg_target_long val;
> -    int mem_reg;
>       intptr_t mem_offset;
> +    int mem_reg;
>       unsigned int fixed_reg:1;
>       unsigned int mem_coherent:1;
>       unsigned int mem_allocated:1;

Reviewed-by: Stefan Weil <sw@weilnetz.de>

TCGContext includes an array of TCGTemp, so it is even reduced by 4 KiB 
(good for caching),
and tcg.o now uses 55364 instead of 56116 bytes (maybe faster, too).

Further optimizations are possible. TCGTemp can be reduced to 32 bytes 
as the output
of pahole shows:

struct TCGTemp {
         TCGTempVal                 val_type:8; /*     0:24  4 */
         unsigned int               reg:8; /*     0:16  4 */
         unsigned int               mem_reg:8; /*     0: 8  4 */

         /* Bitfield combined with next fields */

         _Bool                      fixed_reg:1; /*     3: 7  1 */
         _Bool                      mem_coherent:1; /*     3: 6  1 */
         _Bool                      mem_allocated:1; /*     3: 5  1 */
         _Bool                      temp_local:1; /*     3: 4  1 */
         _Bool                      temp_allocated:1; /*     3: 3  1 */

         /* XXX 3 bits hole, try to pack */

         TCGType                    base_type:16; /*     4:16  4 */
         TCGType                    type:16; /*     4: 0  4 */
         tcg_target_long            val; /*     8     8 */
         intptr_t                   mem_offset; /*    16     8 */
         const char  *              name; /*    24     8 */

         /* size: 32, cachelines: 1, members: 13 */
         /* bit holes: 1, sum bit holes: 3 bits */
         /* last cacheline: 32 bytes */
};

Here I used a new enum type for val_type and reduced some values to 8 or 
16 bit.
I also put the two most often used values at the beginning, so they can be
addressed without or with a small offset ("often" in the code, no runtime
data available).

Are such optimizations useful?

Stefan

  reply	other threads:[~2015-03-23 21:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-21  6:27 [Qemu-trivial] [PATCH] tcg: pack TCGTemp to reduce size by 8 bytes Emilio G. Cota
2015-03-21  6:27 ` [Qemu-devel] " Emilio G. Cota
2015-03-23 21:42 ` Stefan Weil [this message]
2015-03-23 21:42   ` Stefan Weil
2015-03-24  1:07   ` [Qemu-trivial] " Richard Henderson
2015-03-24  1:07     ` Richard Henderson
2015-03-25 19:50     ` [Qemu-trivial] [PATCH] tcg: optimise memory layout of TCGTemp Emilio G. Cota
2015-03-25 19:50       ` [Qemu-devel] " Emilio G. Cota
2015-03-27  9:55       ` [Qemu-trivial] " Alex Bennée
2015-03-27  9:55         ` Alex Bennée
2015-03-27 21:09         ` [Qemu-trivial] " Emilio G. Cota
2015-03-27 21:09           ` Emilio G. Cota
2015-03-30  9:55           ` [Qemu-trivial] " Laurent Desnogues
2015-03-30  9:55             ` Laurent Desnogues
2015-03-27 14:58       ` [Qemu-trivial] " Richard Henderson
2015-03-27 14:58         ` [Qemu-devel] " Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=551088CF.1050001@weilnetz.de \
    --to=sw@weilnetz.de \
    --cc=cota@braap.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.