From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 174B7BB81 for ; Thu, 15 Dec 2005 13:40:24 +0100 (CET) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.173]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jBFCeNMa027470 for ; Thu, 15 Dec 2005 13:40:23 +0100 Received: from [212.227.126.160] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1EmsPH-0006eZ-00; Thu, 15 Dec 2005 13:40:23 +0100 Received: from [84.58.142.229] (helo=gate.lan.gerd-stolpmann.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1EmsPG-0001mc-00; Thu, 15 Dec 2005 13:40:23 +0100 Received: from gps.dynxs.de (localhost [127.0.0.1]) by gate.lan.gerd-stolpmann.de (Postfix) with ESMTP id B2A22C097; Thu, 15 Dec 2005 13:40:22 +0100 (CET) Received: from 192.168.1.2 (proxying for 194.127.8.19) (SquirrelMail authenticated user gerd) by gps.dynxs.de with HTTP; Thu, 15 Dec 2005 13:40:22 +0100 (CET) Message-ID: <3518.192.168.1.2.1134650422.squirrel@gps.dynxs.de> In-Reply-To: <3943.192.168.1.2.1134648180.squirrel@gps.dynxs.de> References: <3943.192.168.1.2.1134648180.squirrel@gps.dynxs.de> Date: Thu, 15 Dec 2005 13:40:22 +0100 (CET) Subject: Re: [Caml-list] Comments welcomed to progr. style / speed of my first ocaml program "Error correcting LDPC decoder" From: "Gerd Stolpmann" To: "Gerd Stolpmann" Cc: "Andries Hekstra" , caml-list@yquem.inria.fr User-Agent: SquirrelMail/1.4.4 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:a6865a839c0178d9aa0ce41878507ea2 X-Miltered: at concorde with ID 43A16437.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 gerd:01 stolpmann:01 gerd:01 stolpmann:01 arrays:01 compiler:01 statically:01 omitted:01 compiler:01 inlined:01 viktoriastr:01 64293:01 darmstadt:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 I forgot one thing: This comment is only correct for 32 bit code. 64 bit code has a uniform array layout for all element types. Gerd Gerd Stolpmann said: > > Andries Hekstra said: >> Attached please find the first program I wrote. It has about the same >> speed as its C++ counterpart (slightly faster). I welcome comments >> w.r.t. >> programming style, esp. when it affects the speed of the program. > > As you are doing a lot of array manipulation, this tip may increase > performance significantly: because "float array" is stored with a > different layout than all other arrays, the compiler generates a dynami= c > check for every access when the type of the array elements cannot be > statically determined. For example, your function > > let swapElement i j a =3D let x =3D a.(i) in a.(i) <- a.(j); a.(j) <- x > > is polymorphic in the element type. If you define instead > > let swapFloatElement i j (a : float array) let x =3D a.(i) in a.(i) <= - > a.(j); a.(j) <- x > > better code is generated because the mentioned check can be omitted by = the > compiler. This applies only if the function is not inlined; swapElement > could be small enough (but qsort, for instance, is definitely not). > > Unfortunately, one cannot define swapNonFloatElement because there is n= o > way to constrain a type that it is not float. So the type system cannot > represent this duality float/non-float, and one must fall back to as ma= ny > definitions as element types are actually used. > > Gerd > ------------------------------------------------------------ > Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany > gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de > ------------------------------------------------------------ > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > ------------------------------------------------------------ Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de ------------------------------------------------------------