[Top][All Lists]

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

Re: Optimize glyph row clearing and copying routines

From: Paul Eggert
Subject: Re: Optimize glyph row clearing and copying routines
Date: Tue, 24 Sep 2013 11:03:32 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8

On 09/24/13 10:04, Eli Zaretskii wrote:
> The issue here is a _partial_ copy of a struct, starting with some
> offset.  That offset can be aligned less favorably than the struct
> itself, which will cause memcpy be less efficient.

Yes, I can verify that this is indeed an issue on my platform
(Fedora 19 x86-64, bundled GCC 4.8.1).  On my platform, this code:

  enum { off = offsetof (struct glyph_row, x) };
  memcpy (&to->x, &from->x, sizeof *to - off);

generates a complicated sequence of 176 instructions, whereas this:

  *to = *from;

generates just two:

   mov 0x20,%ecx
   rep movsq %ds:(%rsi),%es:(%rdi)

I don't know whether this is faster, but it sure is simpler.
One possible way to get the simplification at the assembly level,
might be to package the part of the structure that
one wants to copy inside another structure designed just for
that purpose, so that one could write (to->substruct = from->substruct).

The new code does have an advantage of clarity.
The old code squirreled away some stuff in a temporary copy
and then copied it back, which was hard to follow,
whereas the new code simply copies from source to
destination.  This may be worth any minor performance loss.

reply via email to

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