From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA12400; Mon, 3 Sep 2001 11:36:21 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA12771 for caml-list@pauillac.inria.fr; Mon, 3 Sep 2001 11:36:20 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA09379 for ; Mon, 3 Sep 2001 10:16:26 +0200 (MET DST) Received: from ajax2.sovam.com (ajax2.sovam.com [194.67.1.173]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f838GPr11007 for ; Mon, 3 Sep 2001 10:16:25 +0200 (MET DST) Received: from ts5-a146.Spb.dial.sovam.com ([195.190.96.146]:32833 "HELO kouzdra.glokaya" ident: "NO-IDENT-SERVICE[2]" whoson: "-unregistered-" smtp-auth: TLS-CIPHER: TLS-PEER: ) by ajax2.sovam.com with SMTP id ; Mon, 3 Sep 2001 12:16:38 +0400 Content-Type: Multipart/Mixed; charset="koi8-r"; boundary="------------Boundary-00=_LZU20E1PGOWEBXU44DSI" From: Anton Moscal To: caml Subject: [Caml-list] caml perfomance Date: Mon, 3 Sep 2001 12:16:33 +0400 X-Mailer: KMail [version 1.2] Cc: Nickolay Kolchin MIME-Version: 1.0 Message-Id: <01090312163300.01587@kouzdra.glokaya> Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --------------Boundary-00=_LZU20E1PGOWEBXU44DSI Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 8bit Hi! I & my friend has made some investgations about O'Caml flotaing-point code quality. We discovered some strange code examples(all assembler code is for IA32 architecture): -------------------------------------------------------------------------- 1. "let _ = f a in" and "ignore (f a);" generates different code. for example: let _ = ignore (sin 1.0); () produces the following: 1 Float2_entry: 2 subl $8, %esp 3 .L100: 4 fld1 5 subl $8, %esp 6 fstpl 0(%esp) 7 call sin 8 addl $8, %esp 9 fstpl 0(%esp) ;-----------------------! floating value boxed before discarding 10 call caml_alloc2 12 .L101: 13 leal 4(%eax), %eax 14 movl $2301, -4(%eax) 15 fldl 0(%esp) 16 fstpl (%eax) ;----------------------------------------------------------------- 17 movl $1, %eax 18 addl $8, %esp 19 ret let _ = let _ = sin 1.0 in () produces the following (much more better) code: 1 Float1_entry: 2 subl $8, %esp 3 .L100: 4 fld1 5 subl $8, %esp 6 fstpl 0(%esp) 7 call sin 8 addl $8, %esp 9 fstpl 0(%esp) ;--- instead discarding value from FP stack O'Caml allocates ; space for result on the main stack, store this value to ; stack and after all discards it. 10 movl $1, %eax 11 addl $8, %esp 12 ret -- 2. passing FP parameter to stack is less efficient than possible: Ocaml currently generates this code for pushing float arguments. fldl
subl $8, %esp fstpl 0(%esp) While gcc generates two pushes pushl pushl or movl %address,%reg1 movl %address+4,%reg2 pushl %reg2 pushl %reg1 3. (less important) Ocaml never generate assembler trigonometric functions: fsin, fcos... Yes they violates ANSI rules, but their usage can improve perfomance of an application. Write simple C program with sin or cos usage and compile it with and without "-ffast-math" switch. The difference is about 25%. example.c: #include int main() { int i; volatile double d=1.0; for(i=0;i<10000000;i+=1) d=cos(sin(d)); return 0; } Regards, Anton Moscal Nickolay Kolchin --------------Boundary-00=_LZU20E1PGOWEBXU44DSI Content-Type: application/x-gzip; charset="koi8-r"; name="programs.tgz" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="programs.tgz" H4sIAMqHkjsAA+2Xz2+bMBTHc+aveMouSSfANga0pNl5tx16rKqJOE6xanAEznqY9r/PgJuFirTV JtK180cKRPaXZ8Pj/YDl2Q6Hk1FBiKI0jc0ZoTShvbNlgtKIUprGKDI6jOIknUA87rY69rXOKoBJ Xar1U7rn5t8orPX/VqpM46CQo6xh/IkSSk/7P00e/E9JEhk9iZDxPxplN4/4z/3vSa7hG6w8MNj/ UIsScIBAlL1hpurj4dnce+3dO/6Wo/gnrxf/9BD/UVMLMCEmJbj4PwO9+Be3pao4zGz8z5e9URv+ dtRF/7ugif/oX+n/TPeXENv/Ja7/Owed/zWvdcDGWuO5/E8QOfgfkdTocZISl//PwQdRMrnfcLgs Mp0H+WfPE6WGIhOlyfA/ugJgBkSX9b8rmWkhOWzUft2cVqYidFNbVc3ECi3FJbZ+XYqPKzw3GlM5 mpoy28xt8ai43lclmCt/uiryqnTx/0XdaxUwpe7GWOOZ+McxPuR/Qglt+r+YuO+/s+Axhs2nnf/1 E/hbVQjtb6us4P5OmajnFfiyWBoNeVKz3Wa19psE8qCPHvTFjpda7AuYmvmK5SsjkqqcPrka/cOr H+/Dy6RcQFPccHsk7TFqj9RMtzOdIGA22d0yBtfmodzYYfAVXJtX5Jbrm+VB4V+dFAVXTVbrjBNY DBknLzE+KLLG29sY3nj0EtuDoiPbdNg2fYntQZG1veYlyxdg3GINc5ar7kl2ZrQoOPg7CNqWBC97 IjIoIn1RNCiK+iI6KKLtHpnkWbmw+6sK81ZBFqi9BtZ8BV0EyvyuYNpccI1JRG+mb7mKHed/KWo9 xhpt/k9O9384Sh/1/yROsMv/5yC8gDBXBQ+b+wvvVXUXKpYVUop1WO8434S62JGjFwQuQq9pFBan Y+N3aLzZsHA4HA6Hw+FwOBwOh+Nd8Qvq7HuhACgAAA== --------------Boundary-00=_LZU20E1PGOWEBXU44DSI-- ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr