From: Florian Hars <hars@bik-gmbh.de>
To: Nicolas Cannasse <warplayer@free.fr>
Cc: Hal Daume III <hdaume@ISI.EDU>, Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] unboxing of unary datatypes
Date: Tue, 14 Jan 2003 12:17:20 +0100 [thread overview]
Message-ID: <3E23F1C0.2000604@bik-gmbh.de> (raw)
In-Reply-To: <001301c2bb7e$5e119840$41da0e50@warp>
Nicolas Cannasse wrote:
>>Can someone explain this to me? Why doesn't the compiler optimize out the
>>constructor?
> Because they don't have the same C raw representation.
> There is one more indirection when you use a constructor.
No, I think he sees something different here: The compiler does in fact
optimize out the constructor and then operates directly on the value (which, in
this case, is a boxed float). But it does not perform the special float
optimizations it does on values of the types float, float array and
records like { x: float; y: float; ... (* All fields are floats *)} (but not on
tupels and sum types containing floats).
(Maybe something like the last part of
http://caml.inria.fr/archives/200105/msg00174.html should be added to the
efficiency part of the expert FAQ).
You can see the difference if you compile
type foo = Foo of float
let addpair x y = match x, y with
(a,_), (b, _) -> a +. b
let addfoo x y = match x, y with
Foo x', Foo y' -> x' +. y'
let add x y = match x, y with
x', y' -> x' +. y'
with ocamlc -dinstr -c foo.ml: The code for addfoo is exactly the same as the
code for addpair and does not check any contructors, but accesses the values
with getfield without checking their types or any constructors again (the
compiler knows they are floats):
L2: grab 1
acc 1
getfield 0
push
acc 1
getfield 0
ccall add_float, 2
return 2
add, on the other hand, is treated specially by the float optimizer and gets
away without the unboxig getfield calls:
L1: grab 1
acc 1
push
acc 1
ccall add_float, 2
return 2
Yours, Florian Hars.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2003-01-14 11:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-14 0:08 Hal Daume III
2003-01-14 4:38 ` Nicolas Cannasse
2003-01-14 11:17 ` Florian Hars [this message]
2003-01-14 15:15 ` Nicolas Cannasse
2003-01-14 9:57 ` Fabrice Le Fessant
2003-01-14 11:19 ` Christophe Raffalli
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=3E23F1C0.2000604@bik-gmbh.de \
--to=hars@bik-gmbh.de \
--cc=caml-list@inria.fr \
--cc=hdaume@ISI.EDU \
--cc=warplayer@free.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