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: [Emacs-diffs] /srv/bzr/emacs/trunk r107377: * src/lisp.h: Improve comment about USE_LSB_TAG. Date: Wed, 22 Feb 2012 17:20:21 -0800 Message-ID: <4F459455.8070206@verizon.net> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1329967881 2761 80.91.229.3 (23 Feb 2012 03:31:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 23 Feb 2012 03:31:21 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 23 04:31:20 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S0POm-0003xS-9y for ged-emacs-devel@m.gmane.org; Thu, 23 Feb 2012 04:31:16 +0100 Original-Received: from localhost ([::1]:39183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0POl-0006Hd-CH for ged-emacs-devel@m.gmane.org; Wed, 22 Feb 2012 22:31:15 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:53772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0OIf-00061u-61 for emacs-devel@gnu.org; Wed, 22 Feb 2012 21:20:54 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0OId-0005aH-SU for emacs-devel@gnu.org; Wed, 22 Feb 2012 21:20:53 -0500 Original-Received: from vms173015pub.verizon.net ([206.46.173.15]:60139) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0OId-0005Zv-P7 for emacs-devel@gnu.org; Wed, 22 Feb 2012 21:20:51 -0500 Original-Received: from [192.168.1.10] ([unknown] [71.189.109.235]) by vms173015.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0LZT000BUNPUXTE2@vms173015.mailsrvcs.net> for emacs-devel@gnu.org; Wed, 22 Feb 2012 19:20:19 -0600 (CST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-reply-to: X-detected-operating-system: by eggs.gnu.org: Solaris 10 (1203?) X-Received-From: 206.46.173.15 X-Mailman-Approved-At: Wed, 22 Feb 2012 22:31:13 -0500 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:148716 Archived-At: On 02/22/2012 12:25 PM, Stefan Monnier wrote: >> +/* On hosts where VALBITS is greater than the pointer width in bits, >> + USE_LSB_TAG is: >> + a. unnecessary, because the top bits of an EMACS_INT are unused, >> + b. slower, because it typically requires extra masking, and > > Is this just a gut-feeling, or is there some actual measurement behind > this assertion? Originally the former, but (now that you asked) the latter. On my host the expression (benchmark 1000000) ran about 8% faster without USE_LSB_TAG. This benchmark merely tests the speed of 'aset'; it is defined by the source code at the end of this message (not byte-compiled); this was a random benchmark I was using for something else. I benchmarked Emacs trunk bzr 107379 configured --with-wide-int, using gcc -m32 (GCC 4.6.2), and a Fedora 15 x86-64 kernel (2.6.41.1-1.fc15.x86_64 SMP). The executable size is measurably larger, too: src/temacs's text size is 0.94% larger when USE_LSB_TAG is defined. I'm pretty sure I'll get similar results with other benchmarks. I don't see how USE_LSB_TAG could outperform !USE_LSB_TAG on my platform. > What kind of extra masking are you referring to? The XFASTINT? > Note that the LSB masking can be cheaper than the MSB masking No, it's XPNTR that's faster, because its masking comes for free -- zero runtime overhead on my platform. > So "VALBITS is greater than the pointer width in bits" is not > the exactly right condition (e.g. if we have 48bit pointers and 61 > VALBITS then the problem should not appear). Most likely not, true. The current code is conservative. I don't know of any real platform where the conservatism matters, though. > Maybe a better fix is to add code to the stack marking loop, conditional > on WIDE_EMACS_INT and USE_LSB_TAGS, which passes pointer-sized > words to mark_maybe_object after expanding them to EMACS_INT size. That patch would be more intrusive. Plus, the following (further) patch is simpler and faster. This patch is purely a performance improvement so I didn't install it (was planning to do it after 24.1 comes out, but if you like I can do it now....). === modified file 'src/alloc.c' --- src/alloc.c 2012-01-19 07:21:25 +0000 +++ src/alloc.c 2012-02-23 01:10:15 +0000 @@ -4268,10 +4268,12 @@ end = tem; } +#if defined USE_LSB_TAG || UINTPTR_MAX >> VALBITS != 0 /* Mark Lisp_Objects. */ for (p = start; (void *) p < end; p++) for (i = 0; i < sizeof *p; i += GC_LISP_OBJECT_ALIGNMENT) mark_maybe_object (*(Lisp_Object *) ((char *) p + i)); +#endif /* Mark Lisp data pointed to. This is necessary because, in some situations, the C compiler optimizes Lisp objects away, so that Here's the benchmark code I mentioned earlier. (defun benchmark-with-aset (n) (let ((start (float-time (get-internal-run-time))) (v (make-vector 1 0)) (i 0)) (while (< i n) (aset v 0 1) (setq i (1+ i))) (- (float-time (get-internal-run-time)) start))) (defun benchmark-without-aset (n) (let ((start (float-time (get-internal-run-time))) (v (make-vector 1 0)) (i 0)) (while (< i n) (setq i (1+ i))) (- (float-time (get-internal-run-time)) start))) (defun benchmark (n) (- (benchmark-with-aset n) (benchmark-without-aset n)))