From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Take some lowhanging fruit to speed up R6RS fixnum operations Date: Fri, 25 Mar 2011 00:42:44 +0100 Message-ID: <87zkokrsp7.fsf@vir.lan> References: <1300836034-17716-1-git-send-email-a.rottmann@gmx.at> <1300836034-17716-2-git-send-email-a.rottmann@gmx.at> <87hbas427n.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1301010183 11117 80.91.229.12 (24 Mar 2011 23:43:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 24 Mar 2011 23:43:03 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 25 00:42:59 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q2uB8-0001S1-Cq for guile-devel@m.gmane.org; Fri, 25 Mar 2011 00:42:58 +0100 Original-Received: from localhost ([127.0.0.1]:52469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2uB7-0004UU-Sx for guile-devel@m.gmane.org; Thu, 24 Mar 2011 19:42:57 -0400 Original-Received: from [140.186.70.92] (port=51955 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2uB4-0004TL-Q0 for guile-devel@gnu.org; Thu, 24 Mar 2011 19:42:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2uB3-00009o-Ep for guile-devel@gnu.org; Thu, 24 Mar 2011 19:42:54 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:49785) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Q2uB3-00009G-3X for guile-devel@gnu.org; Thu, 24 Mar 2011 19:42:53 -0400 Original-Received: (qmail invoked by alias); 24 Mar 2011 23:42:50 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp064) with SMTP; 25 Mar 2011 00:42:50 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX1/U9G52ob7UJD8m7y7kmqFSo9CzDeijN3SIcPG6UA sGLo7XL772/RST Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by nathot.lan (Postfix) with ESMTP id 829863A68F; Fri, 25 Mar 2011 00:42:49 +0100 (CET) Original-Received: from nathot.lan ([127.0.0.1]) by localhost (nathot.lan [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NrL8sjquVaWN; Fri, 25 Mar 2011 00:42:45 +0100 (CET) Original-Received: from vir (vir.lan [192.168.3.10]) by nathot.lan (Postfix) with ESMTP id 0791A3A685; Fri, 25 Mar 2011 00:42:44 +0100 (CET) Original-Received: by vir (Postfix, from userid 1000) id C7167BD13B; Fri, 25 Mar 2011 00:42:44 +0100 (CET) In-Reply-To: <87hbas427n.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Thu, 24 Mar 2011 22:51:08 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 213.165.64.22 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11974 Archived-At: ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Hi Andreas, > > I=E2=80=99m all for your suggestion. > > Andreas Rottmann writes: > >> + (define-syntax define-fxop* >> + (syntax-rules () >> + ((_ name op) >> + (define name >> + (case-lambda >> + ((x y) >> + (assert-fixnum x y) >> + (op x y)) >> + (args >> + (assert-fixnums args) >> + (apply op args))))))) >> + >> + (define-fxop* fx=3D? =3D) > > How about making something like this (untested): > > (define-syntax define-fxop* > (syntax-rules () > ((_ name op) > (define-syntax name > (lambda (s) > (syntax-case s () > ((_ x y) > #'(begin > (assert-fixnum x y) > (op x y))) > ((_ args ...) > #'(apply op args)) > (_ #'op))))))) > > This way, there=E2=80=99d be no procedure call involved and =E2=80=98=3D= =E2=80=99, =E2=80=98+=E2=80=99, etc. would > use the corresponding instruction in the base case. > That's an excellent idea, and would probably boost performance quite a bit. However, there's still the issue that the non-two-args cases don't throw the exceptions required by R6RS. Upon trying to interpret the R6RS in a way that would lift that requirement, I still see no way to do so in the general case, due to the following quite explicit language: Fixnum operations perform integer arithmetic on their fixnum arguments, but raise an exception with condition type &implementation-restriction if the result is not a fixnum. So even if checking the arguments seems to be not explicitly required (but might be implictly intended -- "fixnum arguments"), the result must definitly be a fixnum, or the mentioned exception be thrown. So for the sake of efficiency, while heeding what is explictly required, I propose the following: - Alias all fixnum operations that yield non-fixnums (e.g. fx?, ...) with the corresponding non-fixnum procedures. IMHO, that seems to be within bounds wrt. R6RS; Section 5.4 "Argument checking" says: The implementation must check that the restrictions in the specification are indeed met, to the extent that it is reasonable, possible, and necessary to allow the specified operation to complete successfully.=20=20 One might argue that it is not reasonable (for efficiency reasons related to the way Guile is currently implemented) and certainly not necessary to check the arguments for fixnum-ness in these procedures. - Otherwise, do the macro trick as above, but fall back on a procedure like in SRFI-9's `define-inlinable' for the non-binary case. Thoughts? Regards, Rotty --=20 Andreas Rottmann --