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 13:16:21 +0100 Message-ID: <8739mb1jl6.fsf@gmx.at> 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> <87zkokrsp7.fsf@vir.lan> 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 1301056502 32693 80.91.229.12 (25 Mar 2011 12:35:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 25 Mar 2011 12:35:02 +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 13:34:58 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 1Q36ED-00018F-BQ for guile-devel@m.gmane.org; Fri, 25 Mar 2011 13:34:57 +0100 Original-Received: from localhost ([127.0.0.1]:58443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q36EC-00022Y-OY for guile-devel@m.gmane.org; Fri, 25 Mar 2011 08:34:56 -0400 Original-Received: from [140.186.70.92] (port=58163 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q36E9-00021H-Gf for guile-devel@gnu.org; Fri, 25 Mar 2011 08:34:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q36E7-0005Pe-Ac for guile-devel@gnu.org; Fri, 25 Mar 2011 08:34:53 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:50395) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Q36E6-0005P9-RR for guile-devel@gnu.org; Fri, 25 Mar 2011 08:34:51 -0400 Original-Received: (qmail invoked by alias); 25 Mar 2011 12:34:46 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp006) with SMTP; 25 Mar 2011 13:34:46 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX19t1bgVffltAf8bSM+O1SF/BJLVKLtiELpX1NaojL bbU2Klp+2R485V Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by nathot.lan (Postfix) with ESMTP id 70A8F3A68F; Fri, 25 Mar 2011 13:16:42 +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 ZdoHRUU8zNmi; Fri, 25 Mar 2011 13:16:21 +0100 (CET) Original-Received: from delenn.lan (delenn.lan [192.168.3.11]) by nathot.lan (Postfix) with ESMTP id E0EBD3A685; Fri, 25 Mar 2011 13:16:21 +0100 (CET) Original-Received: by delenn.lan (Postfix, from userid 1000) id 9C81D2C00C1; Fri, 25 Mar 2011 13:16:21 +0100 (CET) In-Reply-To: <87zkokrsp7.fsf@vir.lan> (Andreas Rottmann's message of "Fri, 25 Mar 2011 00:42:44 +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:11979 Archived-At: Andreas Rottmann writes: > 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. > Sorry to reply to myself, but new evidence has been produced :-). Using the following macro: (define-syntax define-fxop* (lambda (stx) (define prefix (string->symbol "% ")) (define (make-procedure-name name) (datum->syntax name (symbol-append prefix (syntax->datum name) '-procedure))) (syntax-case stx () ((_ name op) (with-syntax ((proc-name (make-procedure-name #'name))) #'(begin (define (proc-name . args) (assert-fixnums args) (apply op args)) (define-syntax name (lambda (stx) (syntax-case stx () ((_ x-expr y-expr) #'(let ((x x-expr) (y y-expr)) (assert-fixnum x y) (op x y))) ((_ . args) #'(proc-name . args)) (_ (identifier? stx) #'proc-name)))))))))) It turns out that this does not have a great effect on the efficiency; here are the numbers: * stable-2.0 + rotty/wip-fixnum-speed (simple define-fxop*, clever fixn= um?) #+begin_example % _build/meta/guile -e main -s benchmark-suite/guile-benchmark --benchm= ark-suite benchmarks r6rs-arithmetic.bm ;; running guile version 2.0.0.133-e47c9-dirty ;; calibrating the benchmarking framework... ;; framework time per iteration: 1.1444091796875e-7 ("r6rs-arithmetic.bm: fixnum: fixnum? [yes]" 10000000 user 3.42 benchma= rk 2.2755908203125 bench/interp 2.2755908203125 gc 0.0) ("r6rs-arithmetic.bm: fixnum: fixnum? [no]" 10000000 user 3.42 benchmar= k 2.2755908203125 bench/interp 2.2755908203125 gc 0.0) ("r6rs-arithmetic.bm: fixnum: fxxor [2]" 10000000 user 6.96 benchmark 5= .8155908203125 bench/interp 5.8155908203125 gc 0.0) scheme@(guile-user)> ,time (run-benchmark) clock utime stime cutime cstime gctime 23.81 23.76 0.00 0.00 0.00 0.00 #+end_example * stable-2.0 + rotty/wip-fixnum-speed (macro-based define-fxop*, clever= fixnum?) #+begin_example % _build/meta/guile -e main -s benchmark-suite/guile-benchmark --benchm= ark-suite benchmarks r6rs-arithmetic.bm ;; running guile version 2.0.0.133-e47c9-dirty ;; calibrating the benchmarking framework... ;; framework time per iteration: 1.52587890625e-7 ("r6rs-arithmetic.bm: fixnum: fixnum? [yes]" 10000000 user 3.4 benchmar= k 1.87412109375 bench/interp 1.87412109375 gc 0.0) ("r6rs-arithmetic.bm: fixnum: fixnum? [no]" 10000000 user 3.42 benchmar= k 1.89412109375 bench/interp 1.89412109375 gc 0.0) ("r6rs-arithmetic.bm: fixnum: fxxor [2]" 10000000 user 6.72 benchmark 5= .19412109375 bench/interp 5.19412109375 gc 0.0) scheme@(guile-user)> ,time (run-benchmark) clock utime stime cutime cstime gctime 22.76 22.73 0.00 0.00 0.00 0.00 #+end_example So, that's around 5% improvment (on the ZIP benchmark) for an IMHO significantly more hackish implementation. I'm not sure that's worth it. WDYT? Regards, Rotty --=20 Andreas Rottmann --