From: "Gerd Stolpmann" <info@gerd-stolpmann.de>
To: "Gerd Stolpmann" <info@gerd-stolpmann.de>
Cc: "Andries Hekstra" <andries.hekstra@philips.com>,
caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Comments welcomed to progr. style / speed of my first ocaml program "Error correcting LDPC decoder"
Date: Thu, 15 Dec 2005 13:40:22 +0100 (CET) [thread overview]
Message-ID: <3518.192.168.1.2.1134650422.squirrel@gps.dynxs.de> (raw)
In-Reply-To: <3943.192.168.1.2.1134648180.squirrel@gps.dynxs.de>
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 dynamic
> check for every access when the type of the array elements cannot be
> statically determined. For example, your function
>
> let swapElement i j a = let x = 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 = 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 no
> 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 many
> 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
------------------------------------------------------------
next prev parent reply other threads:[~2005-12-15 12:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-15 10:33 Andries Hekstra
[not found] ` <OFB50A01B3.ECDA5A94-ONC12570D8.00394FEA-C12570D8.003A2427@philips.com >
2005-12-15 12:03 ` [Caml-list] " Gerd Stolpmann
2005-12-15 12:40 ` Gerd Stolpmann [this message]
2005-12-15 15:09 ` Xavier Leroy
2005-12-16 19:35 ` Jon Harrop
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3518.192.168.1.2.1134650422.squirrel@gps.dynxs.de \
--to=info@gerd-stolpmann.de \
--cc=andries.hekstra@philips.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox