From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7013 Path: news.gmane.org!not-for-mail From: Denys Vlasenko Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 1/2] x86_64/memset: avoid multiply insn if possible Date: Thu, 12 Feb 2015 20:26:27 +0100 Message-ID: References: <1423761423-30050-1-git-send-email-vda.linux@googlemail.com> <20150212172735.GX23507@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1423769232 31448 80.91.229.3 (12 Feb 2015 19:27:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 12 Feb 2015 19:27:12 +0000 (UTC) To: musl Original-X-From: musl-return-7026-gllmg-musl=m.gmane.org@lists.openwall.com Thu Feb 12 20:27:12 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YLzPs-0001Qe-5s for gllmg-musl@m.gmane.org; Thu, 12 Feb 2015 20:27:12 +0100 Original-Received: (qmail 15833 invoked by uid 550); 12 Feb 2015 19:27:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 15739 invoked from network); 12 Feb 2015 19:27:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=OPntuVwhtqqzZ814ZN60Ca8GkyJrbieap3zR+R6/CD4=; b=0sl7ZiGaGCimt6yLnp8ZB/t1687kOeh7epaosYGZfBWvX299NymTCPzOjvjYyU3AG8 pXud07beTHw9By24lndIUWMCsI1NaXX9jpcjQcVq0LN9/ezGtlQaA9VTLb9AAIqssLzc w9LeFOAjGlr7UCTfoB7vtVSOL9VI57/7zXai4f0tqx3yJr3gAdms5kk6oR/2xPmo0Pwv tv/FaARQZplaKRrU5+KbavRstQrGkMA/cqVxn3HVsNBbDjDDP532zLxo3iB9j0ga25kJ VCtTZopbN0xbcdneXCkL/o/oQJft1EbU7s5s/dZ0IKT8XSG9pTdQmZPIw9kL8sHkUjfa STDQ== X-Received: by 10.140.23.199 with SMTP id 65mr13355777qgp.84.1423769208089; Thu, 12 Feb 2015 11:26:48 -0800 (PST) In-Reply-To: <20150212172735.GX23507@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:7013 Archived-At: On Thu, Feb 12, 2015 at 6:27 PM, Rich Felker wrote: > On Thu, Feb 12, 2015 at 06:17:02PM +0100, Denys Vlasenko wrote: >> memset is very, very often called with fill=0, >> and 64-bit imul is expensive on many CPUs. >> Avoid it if fill=0. >> >> Also avoid multiply on "short memset" codepath if possible, >> and when we do need it, use 32-bit one, which is cheaper on many CPUs. > > I'd actually like to extend the "short" range up to at least 32 bytes > using two 8-byte writes for the middle, unless the savings from using > 32-bit imul instead of 64-bit are sufficient to justify 4 4-byte > writes for the middle. On the cpu I tested on, the difference is 11 > cycles vs 32 cycles for non-rep path versus rep path at size 32. The short path causes mixed feelings in me. On one hand, it's elegant in a contrived way. On the other hand, multiple overlaying stores must be causing hell in store unit. I'm thinking, maybe there's a faster way to do that. Can you post your memset testsuite?