all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: emacs-devel@gnu.org
Subject: Re: Optimize glyph row clearing and copying routines
Date: Tue, 24 Sep 2013 11:03:32 -0700	[thread overview]
Message-ID: <5241D3F4.7060407@cs.ucla.edu> (raw)
In-Reply-To: <83wqm6gnhv.fsf@gnu.org>

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.



  parent reply	other threads:[~2013-09-24 18:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24  6:35 Optimize glyph row clearing and copying routines Eli Zaretskii
2013-09-24 10:10 ` Dmitry Antipov
2013-09-24 11:50   ` Eli Zaretskii
2013-09-24 12:42     ` Dmitry Antipov
2013-09-24 13:40 ` John Yates
2013-09-24 17:04   ` Eli Zaretskii
2013-09-24 17:28     ` John Yates
2013-09-24 18:03     ` Paul Eggert [this message]
2013-09-24 18:32       ` Eli Zaretskii
2013-09-26 12:35         ` Juanma Barranquero

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=5241D3F4.7060407@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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.