From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: VIRT_ADDR_VARIES Date: Thu, 10 Nov 2011 08:19:44 -0800 Organization: UCLA Computer Science Department Message-ID: <4EBBF9A0.6010604@cs.ucla.edu> References: <4EB73983.1060000@cs.ucla.edu> <4EB86864.5080709@cs.ucla.edu> <4EB96841.7020701@cs.ucla.edu> <4EB99C7D.8000407@cs.ucla.edu> <4EBABBF5.5030602@cs.ucla.edu> <4EBB8882.6080504@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1320942008 27427 80.91.229.12 (10 Nov 2011 16:20:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 10 Nov 2011 16:20:08 +0000 (UTC) Cc: emacs-devel@gnu.org To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 10 17:20:02 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ROXM9-0001j5-2L for ged-emacs-devel@m.gmane.org; Thu, 10 Nov 2011 17:20:01 +0100 Original-Received: from localhost ([::1]:38273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROXM8-0005rF-HW for ged-emacs-devel@m.gmane.org; Thu, 10 Nov 2011 11:20:00 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:55784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROXM2-0005qO-PH for emacs-devel@gnu.org; Thu, 10 Nov 2011 11:19:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROXLx-0006Iz-Vl for emacs-devel@gnu.org; Thu, 10 Nov 2011 11:19:54 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:38685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROXLx-0006Il-Ic for emacs-devel@gnu.org; Thu, 10 Nov 2011 11:19:49 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 813DFA60005; Thu, 10 Nov 2011 08:19:48 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GknFQkxA2ktt; Thu, 10 Nov 2011 08:19:48 -0800 (PST) Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 15F2EA60001; Thu, 10 Nov 2011 08:19:48 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:145970 Archived-At: On 11/10/11 01:29, Andreas Schwab wrote: >> + ((uintptr_t) XPNTR (obj) - (uintptr_t) pure <= PURESIZE) > > There is no need for obfuscation, the compiler should find that out by > itself. Perhaps it should, but it typically doesn't. For example, given this: #include #include #define TYPEMASK 7 #define XPNTR(a) ((a) & ~TYPEMASK) #define PURESIZE 1000000 extern long pure[]; #define PURE_P1(obj) \ ((char *) pure <= (char *) XPNTR (obj) \ && (char *) XPNTR (obj) < (char *) pure + PURESIZE) #define PURE_P2(obj) \ ((uintptr_t) XPNTR (obj) - (uintptr_t) pure <= PURESIZE) int pure1 (intptr_t obj) { return PURE_P1 (obj); } int pure2 (intptr_t obj) { return PURE_P2 (obj); } gcc -O2 (x86-64, GCC 4.6.2) generates this for the comparisons of PURE_P1: xorl %eax, %eax cmpq $pure, %rdi jb .L2 xorl %eax, %eax cmpq $pure+1000000, %rdi setb %al .L2: rep and this for PURE_P2: xorl %eax, %eax subq $pure, %rdi cmpq $1000000, %rdi setbe %al The PURE_P1 version has more instructions, and has a conditional jump. The PURE_P2 version is nearly as fast as the old code without VIRT_ADDR_VARIES. I observed similar savings with the other compilers I tried (Sun C 5.11 sparcv9 cc -xO4, clang 2.8 x86-64 -O2). So we should go with PURE_P2.