all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand
       [not found] ` <E1aRUQf-0003kP-6V@vcs.savannah.gnu.org>
@ 2016-02-05 13:25   ` Stefan Monnier
  2016-02-05 22:40     ` Paul Eggert
  2016-02-07 17:53     ` John Wiegley
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Monnier @ 2016-02-05 13:25 UTC (permalink / raw)
  To: emacs-devel; +Cc: Paul Eggert

> +  if (XLI (init) == 0)
> +    memset (p->contents, 0, XFASTINT (length) * sizeof p->contents[0]);
> +  else
> +    for (ptrdiff_t i = 0; i < XFASTINT (length); i++)
> +      p->contents[i] = init;

FWIW, I much prefer keeping just the loop, over using this "if+memset"
which seems like an obvious case or too-early-optimization.


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand
  2016-02-05 13:25   ` [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand Stefan Monnier
@ 2016-02-05 22:40     ` Paul Eggert
  2016-02-07 17:53     ` John Wiegley
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Eggert @ 2016-02-05 22:40 UTC (permalink / raw)
  To: Stefan Monnier, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 525 bytes --]

On 02/05/2016 05:25 AM, Stefan Monnier wrote:
> FWIW, I much prefer keeping just the loop, over using this "if+memset"
> which seems like an obvious case or too-early-optimization.
Fair enough, I didn't measure it and you're probably right that it's not 
worth the complexity. I changed it to use just the loop, with the 
attached patch.

This patch's commit message documents what I had *originally* put in 
there in my private copy, something that I fondly hope would have made 
the hair on the back of your neck stand up.

[-- Attachment #2: 0001-Omit-XLI-init-0-optimization-in-make-vector.patch --]
[-- Type: application/x-patch, Size: 1293 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand
  2016-02-05 13:25   ` [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand Stefan Monnier
  2016-02-05 22:40     ` Paul Eggert
@ 2016-02-07 17:53     ` John Wiegley
  2016-02-07 21:24       ` Paul Eggert
  1 sibling, 1 reply; 4+ messages in thread
From: John Wiegley @ 2016-02-07 17:53 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Paul Eggert, emacs-devel

>>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> +  if (XLI (init) == 0)
>> +    memset (p->contents, 0, XFASTINT (length) * sizeof p->contents[0]);
>> +  else
>> +    for (ptrdiff_t i = 0; i < XFASTINT (length); i++)
>> +      p->contents[i] = init;

> FWIW, I much prefer keeping just the loop, over using this "if+memset" which
> seems like an obvious case or too-early-optimization.

Is this so performance critical that we can't just always use the memset?
Don't modern compilers inline the memset into the loop these days?

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand
  2016-02-07 17:53     ` John Wiegley
@ 2016-02-07 21:24       ` Paul Eggert
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Eggert @ 2016-02-07 21:24 UTC (permalink / raw)
  To: emacs-devel

John Wiegley wrote:
> Is this so performance critical that we can't just always use the memset?

We can't always use the memset. The memset works only if the bit pattern we're 
trying to store can be implemented by storing the same unsigned char value 
repeatedly. The important special case here is storing Qnil, which is 
represented by the all-zeros bit pattern.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-07 21:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20160205003917.14369.86929@vcs.savannah.gnu.org>
     [not found] ` <E1aRUQf-0003kP-6V@vcs.savannah.gnu.org>
2016-02-05 13:25   ` [Emacs-diffs] master 605f901: Prefer memcpy and memset to doing it by hand Stefan Monnier
2016-02-05 22:40     ` Paul Eggert
2016-02-07 17:53     ` John Wiegley
2016-02-07 21:24       ` Paul Eggert

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.