From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/5138 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: thoughts on reallocarray, explicit_bzero? Date: Mon, 19 May 2014 20:12:58 +0200 Message-ID: <20140519181257.GA12324@port70.net> References: <20140519153130.GA519@muslin> <20140519162556.GY12324@port70.net> <20140519165523.GP507@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1400523205 8240 80.91.229.3 (19 May 2014 18:13:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 19 May 2014 18:13:25 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-5143-gllmg-musl=m.gmane.org@lists.openwall.com Mon May 19 20:13:19 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WmS3j-0004AL-18 for gllmg-musl@plane.gmane.org; Mon, 19 May 2014 20:13:11 +0200 Original-Received: (qmail 13358 invoked by uid 550); 19 May 2014 18:13: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 13350 invoked from network); 19 May 2014 18:13:09 -0000 Content-Disposition: inline In-Reply-To: <20140519165523.GP507@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:5138 Archived-At: * Rich Felker [2014-05-19 12:55:23 -0400]: > On Mon, May 19, 2014 at 06:25:57PM +0200, Szabolcs Nagy wrote: > > static size_t sizemul(size_t a, size_t b) > > { > > return b>1 && a>1 && a>-1/b ? -1 : a*b; > > } > > On 32-bit this can easily be optimized to just one conditional instead > of three: > > uint64_t tmp = (uint64_t)a * b; > return tmp>SIZE_MAX ? SIZE_MAX : tmp; > > Of course that requires an ifdef, which is perhaps ugly. or without ifdef static size_t sizemul(size_t a, size_t b) { if (2*sizeof a <= sizeof 1ULL) { unsigned long long m = 1ULL*a*b; return m>>8*sizeof a ? -1 : m; } return (a|b)>>4*sizeof a && b && a>-1/b ? -1 : a*b; }