From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11354 Path: news.gmane.org!.POSTED!not-for-mail From: Brad Conroy Newsgroups: gmane.linux.lib.musl.general Subject: Re: towlower performance Date: Sat, 27 May 2017 19:09:59 +0000 (UTC) Message-ID: <1871525485.1112020.1495912199619@mail.yahoo.com> References: <1871525485.1112020.1495912199619.ref@mail.yahoo.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1495912457 5696 195.159.176.226 (27 May 2017 19:14:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 27 May 2017 19:14:17 +0000 (UTC) To: Original-X-From: musl-return-11369-gllmg-musl=m.gmane.org@lists.openwall.com Sat May 27 21:14:12 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dEhAB-0001M4-Ni for gllmg-musl@m.gmane.org; Sat, 27 May 2017 21:14:11 +0200 Original-Received: (qmail 19465 invoked by uid 550); 27 May 2017 19:14:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 18417 invoked from network); 27 May 2017 19:14:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1495912440; bh=8eg47WqXbbAtNj6txI/zCQh7l3IzzIPacJrcYq/z174=; h=Date:From:Reply-To:To:Subject:References:From:Subject; b=Okir3f0wcXbR0UZhfnpvehtGOxBoPtrXYdJLU7KIpfqxcD9NYZ8BKXLael0nkQJaPR13ELyB5DJqR5Auq3x0SAx8G1kJZy1VqU0ozjRPGDzwHKQcNY6OL4Q5KOldDudQxPY6V2sAw/j8Y5Y/WO65jrNjuXuL8A4nrk57LQJD8+ELrRWzmZfJ2wAKWBTvppaVu1hf264EOk/UGgNsNyNd688E/8tDAqcaBEnsUqADUAgiHyT9r2bet6zT+xXc+kmvj1nnFHKcAkeqrDNtxHjg8+fs7480jfRI9S5eRkbVgMzxrsgWmnpaiRTHC5dirS1EiBlemjN8jAuuPlSJHx3slQ== X-YMail-OSG: sM8ASn0VM1nflHfBu53nPTAP0crY0t2CbN3t3Qr4OO3W2CnauozLr7vOzEv1B25 DpR.BslITL6osYzAD13HCENOLt1T6Gh04mY1LQFcDmOOcQaqYWYmoE.xCF8e8DTIno3ZIfBKxkJN Q3iO8eeymSQSaH7Om9KzCiqXwKjVyEiqpEfM.VQj7f6mG42BRmtpUh9q7IEXizxmPYBcav9qD.gE xUag2326WirtjiuZPCTRaoO_V0KLHMLBeIfYIp3Xq3AKIqLVN0wAuBj92Opvc0FCvbzxPPeZ0ZbY RAymZt70jFxy.3lRJJHoKmI.yEBzplpVyH_l.1eQbQiUGq0NhIJ.WWtACPhCl4j1iW03OIZg7vW5 v95gvDKiv_BFkiHfmvLh2agfOZbyibbIarWWmSqk9u9zfO2CwgA1_8tbrpl1_c5O90VeXi5S0__a Ag_WKiji6uIWMG3XsYxHvMg7.X9_8boFUKNNkRPitOOwpJJXIfs_824DqbA0w.91gcK93.tdWvkF gRODcUK570iBkI1vnKk4UworyIyV2V9CC X-Mailer: WebService/1.1.9726 YahooMailBasic Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48 Xref: news.gmane.org gmane.linux.lib.musl.general:11354 Archived-At: > Thankfully, though, I think the issue maksis reported is more a matter > of the towlower/towupper implementation being oriented towards > size The current macros in ctype.h evaluate twice and could all really be inlined. For a test case try building strcasecmp with and without tolower inlined. It is actually smaller inlined because it doesn't need to setup for a call. I try to avoid branching in inlined functions to avoid mis-predictions and to keep constant time as well as better vectorization (although the unsigned comparison trick may prevent automatic conversion to SIMD on x86 since there is no unsigned compare), so here are some branchless static inlined versions if you want to use them: static __inline int isalnum(int c){ return ((unsigned)c-'0' < 10)|(((unsigned)c|32)-'a' < 26); } static __inline int isalpha(int c){ return (((unsigned)c|32)-'a' < 26); } static __inline int isascii(int c){ return (unsigned)c<128; } static __inline int isblank(int c){ return (c==' ')|(c=='\t'); } static __inline int iscntrl(int c){ return ((unsigned)c < 0x20) | (c == 0x7f); } static __inline int isdigit(int c){ return (unsigned)c-'0' < 10; } static __inline int isgraph(int c){ return (unsigned)c-0x21 < 0x5e; } static __inline int islower(int c){ return (unsigned)c-'a' < 26; } static __inline int isprint(int c){ return (unsigned)c-0x20 < 0x5f; } static __inline int ispunct(int c){ unsigned y=(unsigned)c; return ( ( y-'!' < 95 ) & ( ((y|32)-'a' > 25) | (y-'0' > 9) ) ); } static __inline int isspace(int c){ return ((unsigned)c-'\t' < 5)|(c == ' '); } static __inline int isupper(int c){ return (unsigned)c-'A' < 26; } static __inline int isxdigit(int c){ return ((unsigned)c-'0' < 10) | (((unsigned)c|32)-'a' < 6); } static __inline int toascii(int c){ return c & 0x7f; } static __inline int tolower(int c){ return c | ( ((unsigned)c-'A' < 26)<<5 ); } static __inline int toupper(int c){ return c & ~(((unsigned)c-'a' < 26)<<5); }